fix some stuff

This commit is contained in:
2025-02-06 22:56:01 -05:00
parent 669af2a56e
commit 6143473c1d
4 changed files with 29 additions and 23 deletions

View File

@@ -50,6 +50,26 @@ impl Move {
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`]
pub fn from_board_color(color: Piece, board: &Board) -> Self {
Move {
i: 0,
j: 0,
captured: 0,
color,
board: *board,
next_move: vec![Move {
i: 0,
j: 0,
captured: 0,
color: !color,
board: *board,
next_move: problem_space(board, color).collect(),
}],
}
}
}
fn problem_space(board: &Board, color: Piece) -> Box<dyn Iterator<Item = Move> + '_> {
@@ -72,28 +92,17 @@ impl Agent for ComplexAgent {
fn next_move(&mut self, board: &Board) -> Option<(usize, usize)> {
const LOOPS: usize = 5;
let curr_move: Move = self.curr_move.take().unwrap_or_else(|| Move {
i: 0,
j: 0,
captured: 0,
color: self.color,
board: *board,
next_move: vec![Move {
i: 0,
j: 0,
captured: 0,
color: !self.color,
board: *board,
next_move: problem_space(board, self.color).collect(),
}],
});
let curr_move: Move = self
.curr_move
.take()
.unwrap_or_else(|| Move::from_board_color(self.color, board));
let mut other_player_move = curr_move
.next_move
.into_iter()
.filter(|x| &x.board == board)
.last()
.unwrap();
.expect("other player made an invalid move?");
other_player_move.populate_next_moves(LOOPS);