general code improvements

This commit is contained in:
2025-02-10 14:21:06 -05:00
parent cb5f9d075d
commit bd5cc2ea52
3 changed files with 43 additions and 60 deletions

View File

@@ -104,28 +104,27 @@ impl FutureMoves {
board: &Board,
color: Piece,
) -> Vec<usize> {
let children: Vec<_> = board
.possible_moves(color)
.flat_map(|(i, j)| board.what_if(i, j, color).map(|x| (i, j, x)))
.map(|(i, j, (new_board, captured))| {
let winner = new_board.game_winner(color);
Move {
i,
j,
captured,
color,
board: new_board,
winner,
parent,
children: Vec::new(),
value: 0,
}
})
.collect();
let parent_idx = parent;
let start_idx = self.arena.len();
self.arena.extend(children);
self.arena.extend(
board
.possible_moves(color)
.flat_map(|(i, j)| board.what_if(i, j, color).map(|x| (i, j, x)))
.map(|(i, j, (new_board, captured))| {
let winner = new_board.game_winner(color);
Move {
i,
j,
captured,
color,
board: new_board,
winner,
parent,
children: Vec::new(),
value: 0,
}
}),
);
let new_indices: Vec<usize> = (start_idx..self.arena.len()).collect();
if let Some(parent_idx) = parent_idx {
@@ -249,7 +248,7 @@ pub struct ComplexAgent {
impl ComplexAgent {
pub fn new(color: Piece) -> Self {
const MAX_DEPTH: usize = 7;
const MAX_DEPTH: usize = 6;
Self {
color,
future_moves: FutureMoves::new(color, MAX_DEPTH),