From 18dbc2ffe27d7c30275e15f84cf3304e48867f77 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Wed, 19 Feb 2025 22:14:26 -0500 Subject: [PATCH] weight sides more --- src/board.rs | 8 ++++++++ src/future_moves.rs | 21 ++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/board.rs b/src/board.rs index 723cf1c..5cdf47c 100644 --- a/src/board.rs +++ b/src/board.rs @@ -199,6 +199,14 @@ impl Board { Self::all_positions().filter(move |&(i, j)| self.would_prop(i, j, color)) } + pub fn sides() -> impl Iterator { + (0..BOARD_SIZE) + .map(|i| (i, BOARD_SIZE - 1)) + .chain((0..BOARD_SIZE).map(|i| (i, 0))) + .chain((0..BOARD_SIZE).map(|j| (BOARD_SIZE - 1, j))) + .chain((0..BOARD_SIZE).map(|j| (0, j))) + } + /// Get a reference to a backing [`BitBoard`] const fn board(&self, color: Piece) -> &BitBoard { match color { diff --git a/src/future_moves.rs b/src/future_moves.rs index 58e650e..0e67fe4 100644 --- a/src/future_moves.rs +++ b/src/future_moves.rs @@ -39,18 +39,29 @@ impl Move { } fn compute_self_value(&self, agent_color: Piece) -> i64 { - let mut self_value = self.board.net_score(agent_color) as 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 - self_value = i64::MIN; + return i64::MIN; } else if self.winner == Winner::Player(agent_color) { // results in a win for the agent - self_value = i64::MAX; + return i64::MAX; + } else if self.winner == Winner::Tie { + // idk what a Tie should be valued? + return 0; } - // TODO! handle ties... what should they be valued as? maybe `i64::MAX / 2` or 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 }