allow the game to end in cases of a non-full board
This commit is contained in:
@@ -30,39 +30,43 @@ impl Move {
|
||||
}
|
||||
|
||||
fn value(&self, agent_color: Piece, depth: usize) -> i64 {
|
||||
let mut captured_value = self.captured as i64;
|
||||
let mut self_value = self.captured as i64;
|
||||
|
||||
if self.board.game_over() && self.board.get_winner() != Some(!agent_color) {
|
||||
if self.board.game_winner(agent_color) != Some(!agent_color) {
|
||||
// if this board results in the opponent winning, MAJORLY negatively weigh this move
|
||||
captured_value = i64::MIN;
|
||||
// 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;
|
||||
} else if agent_color != self.color {
|
||||
captured_value = -captured_value;
|
||||
self_value = -self_value;
|
||||
}
|
||||
|
||||
// Reduce value of capture based on depth of prediction
|
||||
captured_value /= depth as i64;
|
||||
self_value /= depth as i64;
|
||||
|
||||
let avg_next_move_value = (self
|
||||
let avg_next_move_value = self
|
||||
.next_move
|
||||
.iter()
|
||||
.map(|x| x.value(agent_color, depth + 1))
|
||||
.sum::<i64>()
|
||||
.checked_div(self.next_move.len() as i64))
|
||||
.unwrap_or(0);
|
||||
.checked_div(self.next_move.len() as i64)
|
||||
.unwrap_or(0);
|
||||
|
||||
captured_value + avg_next_move_value
|
||||
self_value + avg_next_move_value
|
||||
}
|
||||
|
||||
/// Returns the # of moves in the entire tree
|
||||
pub fn len(&self) -> u32 {
|
||||
self.next_move.len() as u32 + self.next_move.iter().map(Move::len).sum::<u32>()
|
||||
}
|
||||
|
||||
/// Returns a tuple containing the `i` and `j` fields
|
||||
pub const fn coords(&self) -> (usize, usize) {
|
||||
(self.i, self.j)
|
||||
}
|
||||
|
||||
/// Cursed function to create a dummy move type from a color and board
|
||||
/// Used to bootstrap [`ComplexAgent`]
|
||||
/// Used to bootstrap [`ComplexAgent`]'s future moves
|
||||
pub fn bootstrap(color: Piece, board: &Board) -> Self {
|
||||
Move {
|
||||
i: 0,
|
||||
@@ -109,6 +113,7 @@ impl Agent for ComplexAgent {
|
||||
.take()
|
||||
.unwrap_or_else(|| Move::bootstrap(self.color, board));
|
||||
|
||||
// determine the move the other player made via the board state
|
||||
let mut other_player_move = curr_move
|
||||
.next_move
|
||||
.into_iter()
|
||||
|
||||
Reference in New Issue
Block a user