add debug stuff to game_inner

This commit is contained in:
Simon Gardling 2025-03-06 15:38:06 -05:00
parent 52ad7ba53d
commit 4de62a2d0f
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D

View File

@ -1,6 +1,6 @@
use crate::{
agent::Agent,
repr::{Board, Piece, Winner},
repr::{Board, CoordPair, Piece, Winner},
};
impl std::fmt::Display for GameInner {
@ -18,10 +18,20 @@ impl std::fmt::Display for GameInner {
}
}
impl std::fmt::Debug for GameInner {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "FirstBoard:\n{}", self.first_board)?;
writeln!(f, "\nmove_log: {:?}", self.move_log)?;
Ok(())
}
}
pub struct GameInner {
players: [Box<dyn Agent>; 2],
board: Board,
do_print: bool,
move_log: Vec<(Option<CoordPair>, Piece)>,
first_board: Board,
}
impl GameInner {
@ -47,6 +57,8 @@ impl GameInner {
players: [player1, player2],
board,
do_print,
move_log: Vec::new(),
first_board: board,
}
}
@ -58,6 +70,7 @@ impl GameInner {
// when it comes to human input
loop {
let player_move = self.players[player_i].next_move(&self.board);
self.move_log.push((player_move, player_color));
if let Some(coord) = player_move {
match self.board.place(coord, player_color) {
@ -71,8 +84,8 @@ impl GameInner {
Err(err) => {
panic!(
"Invalid move by Player {}: {}. Move: {}",
player_i, err, coord
"Invalid move by Player {}: {}. Move: {} State: {:?}",
player_i, err, coord, self
);
}
}