use crate::{ agent::Agent, board::{Board, BOARD_SIZE}, piece::Piece, }; 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::>() }) .flat_map(|(i, j)| board.what_if(i, j, piece).map(|x| (i, j, x))) .collect() } impl Agent for ComplexAgent { fn next_move(&mut self, board: &Board) -> Option<(usize, usize)> { problem_space(board, self.color) .iter() .map(|&(i, j, (board, c))| { ( i, j, c as i64 // reduce # of adversarial moves - problem_space(&board, self.color.flip()) .into_iter() .map(|(_, _, (_, c))| c as i64) .count() as i64, ) }) .max_by_key(|&(_, _, c)| c) .map(|(i, j, _)| (i, j)) } fn name(&self) -> &'static str { "Complex Agent" } fn color(&self) -> Piece { self.color } } impl ComplexAgent { pub fn new(color: Piece) -> Self { Self { color } } }