This commit is contained in:
Simon Gardling 2025-01-28 16:44:28 -05:00
parent 0dac4a9a38
commit 37c3f8572f
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D
2 changed files with 16 additions and 14 deletions

View File

@ -63,10 +63,6 @@ impl Board {
*self.get_mut(i, j) = Some(piece);
}
pub fn move_would_propegate(&self, i: usize, j: usize, piece: Piece) -> i16 {
self.what_if(i, j, piece).map(|x| x.1 as i16).unwrap_or(-1)
}
pub fn what_if(&self, i: usize, j: usize, piece: Piece) -> Option<(Self, usize)> {
let mut self_copy = *self;
if self_copy.get(i, j).is_some() {

View File

@ -8,18 +8,24 @@ pub struct ComplexAgent {
color: Piece,
}
fn problem_space(board: &Board, piece: Piece) -> Vec<(usize, usize, (Board, usize))> {
(0..BOARD_SIZE)
.flat_map(|i| {
(0..BOARD_SIZE)
.map(|j| (i, j))
.collect::<Vec<(usize, usize)>>()
})
.flat_map(|(i, j)| board.what_if(i, j, piece).map(|x| (i, j, x)))
.map(|(i, j, (board, c))| (i, j, (board, c as usize)))
.collect()
}
impl Agent for ComplexAgent {
fn next_move(&mut self, board: &Board) -> Option<(usize, usize)> {
(0..BOARD_SIZE)
.flat_map(|i| {
(0..BOARD_SIZE)
.map(|j| (i, j))
.collect::<Vec<(usize, usize)>>()
})
.map(|(i, j)| (i, j, board.move_would_propegate(i, j, self.color)))
.filter(|&(_, _, c)| c >= 0) // a `c` value of less than 0 implies the move is invalid: TODO! make this an enum or smth
.max_by_key(|&(_, _, c)| c)
.map(|(i, j, _)| (i, j)) // remove `c` and return the best move
problem_space(board, self.color)
.iter()
.max_by_key(|(_, _, (_, c))| c)
.map(|&(i, j, (_, _))| (i, j))
}
fn name(&self) -> &'static str {