diff --git a/src/agent.rs b/src/agent.rs index 2a00d76..9291316 100644 --- a/src/agent.rs +++ b/src/agent.rs @@ -1,7 +1,6 @@ +use crate::{board::Board, piece::Piece}; use std::collections::VecDeque; -use crate::repr::{Board, Piece}; - pub trait Agent { fn next_move(&mut self, board: &Board) -> Option<(usize, usize)>; fn name(&self) -> &'static str; diff --git a/src/repr.rs b/src/board.rs similarity index 92% rename from src/repr.rs rename to src/board.rs index 81e3923..d98443e 100644 --- a/src/repr.rs +++ b/src/board.rs @@ -1,36 +1,6 @@ -use crate::misc::split_from; +use crate::{misc::split_from, piece::Piece}; use std::fmt; -#[derive(Copy, Clone, PartialEq, Eq, Debug)] -pub enum Piece { - Black, - White, -} - -impl Piece { - pub const fn flip(&self) -> Self { - match self { - Piece::Black => Piece::White, - Piece::White => Piece::Black, - } - } - - pub const fn text(&self) -> &'static str { - match self { - Piece::White => "■", - Piece::Black => "□", - } - } -} - -impl std::ops::Not for Piece { - type Output = Piece; - - fn not(self) -> Self::Output { - self.flip() - } -} - const BOARD_SIZE: usize = 8; #[derive(Copy, Clone)] diff --git a/src/game.rs b/src/game.rs index a3ab673..f9fee2f 100644 --- a/src/game.rs +++ b/src/game.rs @@ -1,4 +1,4 @@ -use crate::{agent::Agent, repr::Board}; +use crate::{agent::Agent, board::Board}; use std::time::Duration; pub struct Game { @@ -43,17 +43,17 @@ impl Game { // TODO! make this loop good pub fn game_loop(&mut self) { + let mut i = 0; loop { + self.step(i); + + // alternate which player plays + i += 1; + i %= self.players.len(); + 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); } } } diff --git a/src/main.rs b/src/main.rs index 86ed7e3..b6295b7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,12 @@ use agent::QueueAgent; use game::Game; -use repr::Piece; +use piece::Piece; mod agent; +mod board; mod game; mod misc; -mod repr; +mod piece; fn main() { let player1 = QueueAgent::new( diff --git a/src/piece.rs b/src/piece.rs new file mode 100644 index 0000000..5b50987 --- /dev/null +++ b/src/piece.rs @@ -0,0 +1,29 @@ +#[derive(Copy, Clone, PartialEq, Eq, Debug)] +pub enum Piece { + Black, + White, +} + +impl Piece { + pub const fn flip(&self) -> Self { + match self { + Piece::Black => Piece::White, + Piece::White => Piece::Black, + } + } + + pub const fn text(&self) -> &'static str { + match self { + Piece::White => "■", + Piece::Black => "□", + } + } +} + +impl std::ops::Not for Piece { + type Output = Piece; + + fn not(self) -> Self::Output { + self.flip() + } +}