split off logic

This commit is contained in:
2025-02-20 16:00:01 -05:00
parent 47faa2af75
commit 73faf4c1fb
6 changed files with 7 additions and 7 deletions

66
src/logic/move.rs Normal file
View File

@@ -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<usize>,
/// Indices of this Move's Children
pub children: Vec<usize>,
/// 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
}
}