weight sides more

This commit is contained in:
Simon Gardling 2025-02-19 22:14:26 -05:00
parent 5f1236d351
commit 18dbc2ffe2
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D
2 changed files with 24 additions and 5 deletions

View File

@ -199,6 +199,14 @@ impl Board {
Self::all_positions().filter(move |&(i, j)| self.would_prop(i, j, color))
}
pub fn sides() -> impl Iterator<Item = (usize, usize)> {
(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 {

View File

@ -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
}