diff --git a/src/complexagent.rs b/src/complexagent.rs index 0bbcbc2..c32f295 100644 --- a/src/complexagent.rs +++ b/src/complexagent.rs @@ -4,26 +4,27 @@ use crate::{ misc::offsets, piece::Piece, }; -use rand::seq::IteratorRandom; +use rand::{rngs::ThreadRng, seq::IteratorRandom}; pub struct ComplexAgent { color: Piece, + rng: ThreadRng, } impl Agent for ComplexAgent { fn next_move(&mut self, board: &Board) -> Option<(usize, usize)> { (0..BOARD_SIZE) .zip(0..BOARD_SIZE) - .filter(|&(i, j)| board.get(i, j) == &Some(!self.color())) + .filter(|&(i, j)| board.get(i, j) == &Some(!self.color)) .flat_map(|(i, j)| offsets(i, j, 1)) .filter(|&(i, j)| i < BOARD_SIZE && j < BOARD_SIZE) .filter(|&(i, j)| board.get(i, j).is_none()) - .choose(&mut rand::rng()) + .choose(&mut self.rng) .or_else(|| { (0..BOARD_SIZE) .zip(0..BOARD_SIZE) .filter(|&(i, j)| board.get(i, j).is_none()) - .choose(&mut rand::rng()) + .choose(&mut self.rng) }) } @@ -37,7 +38,10 @@ impl Agent for ComplexAgent { } impl ComplexAgent { - pub const fn new(color: Piece) -> Self { - Self { color } + pub fn new(color: Piece) -> Self { + Self { + color, + rng: rand::rng(), + } } }