diff --git a/src/future_moves.rs b/src/future_moves.rs index eda815b..31c6576 100644 --- a/src/future_moves.rs +++ b/src/future_moves.rs @@ -3,70 +3,9 @@ use indicatif::{ProgressIterator, ProgressStyle}; use crate::{ board::{Board, Winner}, piece::Piece, + r#move::Move, }; -#[derive(Clone, Debug)] -pub struct Move { - /// `i` position of move - i: usize, - - /// `j` position of move - j: usize, - - /// [`Board`] state after move is made - board: Board, - - /// Current winner of the match - winner: Winner, - - /// Index of this move's parent - parent: Option, - - /// Indices of this Move's Children - children: Vec, - - /// Value of this move - value: i64, - - color: Piece, - - lazy_children: bool, -} - -impl Move { - pub const fn coords(&self) -> (usize, usize) { - (self.i, self.j) - } - - fn compute_self_value(&self, agent_color: Piece) -> i64 { - if self.winner == Winner::Player(!agent_color) { - // if this board results in the opponent winning, MAJORLY negatively weigh this move - // NOTE! this branch isn't completely deleted because if so, the bot wouldn't make a move. - // We shouldn't prune branches because we still need to always react to the opponent's moves - return i64::MIN; - } else if self.winner == Winner::Player(agent_color) { - // results in a win for the agent - return i64::MAX; - } else if self.winner == Winner::Tie { - // idk what a Tie should be valued? - return 0; - } - - let mut self_value = self.board.net_score(agent_color) as i64; - let corner_v_agent = Board::sides() - .filter(|&(i, j)| self.board.get_piece(i, j, agent_color)) - .count() as i64; - let corner_v_not_agent = Board::sides() - .filter(|&(i, j)| self.board.get_piece(i, j, !agent_color)) - .count() as i64; - - // make net-corner capture important - self_value += (corner_v_agent - corner_v_not_agent) * 4; - - self_value - } -} - pub struct FutureMoves { /// Arena containing all [`Move`] arena: Vec, diff --git a/src/lib.rs b/src/lib.rs index ef5ad5a..4a154eb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,4 +5,5 @@ mod complexagent; pub mod future_moves; mod game; mod misc; +mod r#move; pub mod piece; diff --git a/src/main.rs b/src/main.rs index 8bbeee9..679f9b9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,7 @@ mod complexagent; pub mod future_moves; mod game; mod misc; +mod r#move; mod piece; fn main() { diff --git a/src/move.rs b/src/move.rs new file mode 100644 index 0000000..0582e36 --- /dev/null +++ b/src/move.rs @@ -0,0 +1,66 @@ +use crate::{ + board::{Board, Winner}, + piece::Piece, +}; + +#[derive(Clone, Debug)] +pub struct Move { + /// `i` position of move + pub i: usize, + + /// `j` position of move + pub j: usize, + + /// [`Board`] state after move is made + pub board: Board, + + /// Current winner of the match + pub winner: Winner, + + /// Index of this move's parent + pub parent: Option, + + /// Indices of this Move's Children + pub children: Vec, + + /// Value of this move + pub value: i64, + + pub color: Piece, + + pub lazy_children: bool, +} + +impl Move { + pub const fn coords(&self) -> (usize, usize) { + (self.i, self.j) + } + + pub fn compute_self_value(&self, agent_color: Piece) -> i64 { + if self.winner == Winner::Player(!agent_color) { + // if this board results in the opponent winning, MAJORLY negatively weigh this move + // NOTE! this branch isn't completely deleted because if so, the bot wouldn't make a move. + // We shouldn't prune branches because we still need to always react to the opponent's moves + return i64::MIN; + } else if self.winner == Winner::Player(agent_color) { + // results in a win for the agent + return i64::MAX; + } else if self.winner == Winner::Tie { + // idk what a Tie should be valued? + return 0; + } + + let mut self_value = self.board.net_score(agent_color) as i64; + let corner_v_agent = Board::sides() + .filter(|&(i, j)| self.board.get_piece(i, j, agent_color)) + .count() as i64; + let corner_v_not_agent = Board::sides() + .filter(|&(i, j)| self.board.get_piece(i, j, !agent_color)) + .count() as i64; + + // make net-corner capture important + self_value += (corner_v_agent - corner_v_not_agent) * 4; + + self_value + } +}