display game
This commit is contained in:
parent
c48a4595c3
commit
d8e50fe218
31
src/agent.rs
31
src/agent.rs
@ -4,24 +4,45 @@ use crate::repr::{Board, Piece};
|
||||
|
||||
pub trait Agent {
|
||||
fn next_move(&mut self, board: &Board) -> Option<(usize, usize)>;
|
||||
fn name(&self) -> &'static str;
|
||||
fn color(&self) -> Piece;
|
||||
}
|
||||
|
||||
pub struct ManualAgent {}
|
||||
pub struct ManualAgent {
|
||||
color: Piece,
|
||||
}
|
||||
|
||||
impl Agent for ManualAgent {
|
||||
fn next_move(&mut self, board: &Board) -> Option<(usize, usize)> {
|
||||
todo!("user input not implemented")
|
||||
}
|
||||
|
||||
fn name(&self) -> &'static str {
|
||||
"Manual Agent"
|
||||
}
|
||||
|
||||
fn color(&self) -> Piece {
|
||||
self.color
|
||||
}
|
||||
}
|
||||
|
||||
pub struct QueueAgent {
|
||||
moves: VecDeque<(usize, usize)>,
|
||||
color: Piece,
|
||||
}
|
||||
|
||||
impl Agent for QueueAgent {
|
||||
fn next_move(&mut self, board: &Board) -> Option<(usize, usize)> {
|
||||
self.moves.pop_front()
|
||||
}
|
||||
|
||||
fn name(&self) -> &'static str {
|
||||
"Queue Agent"
|
||||
}
|
||||
|
||||
fn color(&self) -> Piece {
|
||||
self.color
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AutoAgent {
|
||||
@ -32,6 +53,14 @@ impl Agent for AutoAgent {
|
||||
fn next_move(&mut self, board: &Board) -> Option<(usize, usize)> {
|
||||
todo!("next_move not implemented")
|
||||
}
|
||||
|
||||
fn name(&self) -> &'static str {
|
||||
"Auto Agent"
|
||||
}
|
||||
|
||||
fn color(&self) -> Piece {
|
||||
self.color
|
||||
}
|
||||
}
|
||||
|
||||
impl AutoAgent {
|
||||
|
||||
15
src/game.rs
15
src/game.rs
@ -4,3 +4,18 @@ pub struct Game {
|
||||
players: [Box<dyn Agent>; 2],
|
||||
board: Board,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Game {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
writeln!(
|
||||
f,
|
||||
"Players: {} ({}) and {} ({})",
|
||||
self.players[0].name(),
|
||||
self.players[0].color().text(),
|
||||
self.players[1].name(),
|
||||
self.players[1].color().text()
|
||||
)?;
|
||||
write!(f, "{}", self.board)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@ -192,7 +192,7 @@ mod test {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn long_capture() {
|
||||
fn long_capture_horiz() {
|
||||
let mut board = Board::new();
|
||||
|
||||
assert_eq!(board.place(0, 0, Piece::Black), Ok(()));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user