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

Commit

Permalink
Changes per PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
liminzhu committed Apr 6, 2016
1 parent fbbea5d commit ea3e714
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions react-tic-tac-toe/src/board.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,15 @@ export class Board extends React.Component<void, BoardState> {
});
}
}

// AI make a random move
private aiMove(): void {
let emptyCells = this.findAllEmptyCells(this.state.cells);
let pos = emptyCells[Math.floor(Math.random() * emptyCells.length)];
this.move(pos, aiCell);
}


// handle a new move from player
private handleNewPlayerMove(pos: number): void {
this.move(pos, playerCell, this.aiMove);
this.move(pos, playerCell, () => {
// AI make a random move following player's move
let emptyCells = this.findAllEmptyCells(this.state.cells);
let pos = emptyCells[Math.floor(Math.random() * emptyCells.length)];
this.move(pos, aiCell);
});
}

render() {
Expand Down

0 comments on commit ea3e714

Please sign in to comment.