added winner() method

This commit is contained in:
2025-06-27 22:04:11 +08:00
parent 2483de7608
commit 8e852759ba
2 changed files with 12 additions and 1 deletions

View File

@@ -15,7 +15,7 @@ fn main() {
pieces.push(Piece::CrownedRedPawn).unwrap();
board
.pieces(&pieces)
.pieces(pieces)
.for_each(|pos| println!("({}, {}): {:?}", pos.row(), pos.col(), board[pos]));
// println!("{:?}", board[Position::new(0, 0)]);

View File

@@ -492,6 +492,17 @@ impl DraughtsGame {
};
(best_move, analyzed_moves)
}
pub fn winner(&self) -> Option<Player> {
if self.available_moves().next().is_none() {
Some(match self.next_move {
Player::White => Player::Red,
Player::Red => Player::White,
})
} else {
None
}
}
}
#[derive(Debug, PartialEq, Eq)]
struct MoveHeapEntry {