sample game segment

This commit is contained in:
2025-01-28 13:07:03 -05:00
parent ef9a07242d
commit afef9f1b19
4 changed files with 55 additions and 5 deletions

View File

@@ -1,4 +1,5 @@
use crate::{agent::Agent, repr::Board};
use std::time::Duration;
pub struct Game {
players: [Box<dyn Agent>; 2],
@@ -19,3 +20,40 @@ impl std::fmt::Display for Game {
Ok(())
}
}
impl Game {
pub const fn new(player1: Box<dyn Agent>, player2: Box<dyn Agent>) -> Self {
Self {
players: [player1, player2],
board: Board::new(),
}
}
pub fn step(&mut self, player_i: usize) {
let player_move = self.players[player_i].next_move(&self.board);
if let Some((i, j)) = player_move {
if let Ok(()) = self.board.place(i, j, self.players[player_i].color()) {
} else {
todo!("handle invalid player move");
}
} else {
todo!("handle player not having a move to make");
}
}
// TODO! make this loop good
pub fn game_loop(&mut self) {
loop {
println!("{}", self);
std::thread::sleep(Duration::from_millis(500));
self.step(0);
println!("{}", self);
std::thread::sleep(Duration::from_millis(500));
self.step(1);
println!("{}", self);
}
}
}