The game object already has two distinct notions of players and
teams. And this property will only be compared to team values, not
player values, so this name is more accurate and less confusing.
this.state = {
moves: [],
board: Array(9).fill(""),
this.state = {
moves: [],
board: Array(9).fill(""),
};
this.teams = ["X", "O"];
}
};
this.teams = ["X", "O"];
}
}
/* Cannot move if it's not this player's team's turn. */
}
/* Cannot move if it's not this player's team's turn. */
- if (player.team !== this.state.next_player)
+ if (player.team !== this.state.team_to_play)
{
return { legal: false,
message: "It's not your turn to move" };
{
return { legal: false,
message: "It's not your turn to move" };
message: "Square is already occupied" };
}
message: "Square is already occupied" };
}
- this.state.board[square] = this.state.next_player;
+ this.state.board[square] = this.state.team_to_play;
this.state.moves.push(square);
this.state.moves.push(square);
- if (this.state.next_player === "X")
- this.state.next_player = "O";
+ if (this.state.team_to_play === "X")
+ this.state.team_to_play = "O";
- this.state.next_player = "X";
+ this.state.team_to_play = "X";
return { legal: true };
}
return { legal: true };
}