Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit ea3e714

Browse files
committed
Changes per PR feedback
1 parent fbbea5d commit ea3e714

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

react-tic-tac-toe/src/board.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,15 @@ export class Board extends React.Component<void, BoardState> {
118118
});
119119
}
120120
}
121-
122-
// AI make a random move
123-
private aiMove(): void {
124-
let emptyCells = this.findAllEmptyCells(this.state.cells);
125-
let pos = emptyCells[Math.floor(Math.random() * emptyCells.length)];
126-
this.move(pos, aiCell);
127-
}
128-
121+
129122
// handle a new move from player
130123
private handleNewPlayerMove(pos: number): void {
131-
this.move(pos, playerCell, this.aiMove);
124+
this.move(pos, playerCell, () => {
125+
// AI make a random move following player's move
126+
let emptyCells = this.findAllEmptyCells(this.state.cells);
127+
let pos = emptyCells[Math.floor(Math.random() * emptyCells.length)];
128+
this.move(pos, aiCell);
129+
});
132130
}
133131

134132
render() {

0 commit comments

Comments
 (0)