allow the game to end in cases of a non-full board

This commit is contained in:
2025-02-08 22:47:44 -05:00
parent 5c27572f9f
commit ec0eb7f849
4 changed files with 31 additions and 60 deletions

View File

@@ -51,6 +51,7 @@ impl Game {
}
} else {
println!("Player {} did not make a move!", player_i);
// TODO! break, player should not be able to skip a move
return; // No valid move available
}
}
@@ -67,36 +68,9 @@ impl Game {
println!("{}", self);
// TODO! what if the board isn't full, but one player cannot win as
// they don't have any moves to play?
// Example::
// Player 1 placed at (1, 0)
// Players: Complex Agent (□) and Manual Agent (■)
// 0 1 2 3 4 5 6 7
// -----------------
// 0|□|□|□|□|□|□|□|□|
// -----------------
// 1|■|■|■|□|□|□| |□|
// -----------------
// 2|■|■|□|■|□|□|□|□|
// -----------------
// 3|■|■|□|□|■|□|□|□|
// -----------------
// 4|■|■|□|□|■|□|□|□|
// -----------------
// 5|□|□|■|□|■|□|□|□|
// -----------------
// 6| |□|□|□|□|□|□|□|
// -----------------
// 7| | | |■|■| |■| |
// -----------------
// White Score: 17
// Black Score: 40
// (depth: 5) possible board states: 0
// thread 'main' panicked at src/complexagent.rs:139:9:
// ComplexAgent didn't make a move
if self.board.game_over() {
if let Some(game_winner) = self.board.game_winner(self.players[current_player].color())
{
println!("{} Wins!", game_winner.text());
// end the game
break;
}