woah
This commit is contained in:
43
src/complexagent.rs
Normal file
43
src/complexagent.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use crate::{
|
||||
agent::Agent,
|
||||
board::{Board, BOARD_SIZE},
|
||||
misc::{offsets, split_from},
|
||||
piece::Piece,
|
||||
};
|
||||
use rand::{seq::IteratorRandom, Rng};
|
||||
|
||||
pub struct ComplexAgent {
|
||||
color: Piece,
|
||||
}
|
||||
|
||||
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()))
|
||||
.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())
|
||||
.or_else(|| {
|
||||
(0..BOARD_SIZE)
|
||||
.zip(0..BOARD_SIZE)
|
||||
.filter(|&(i, j)| board.get(i, j).is_none())
|
||||
.choose(&mut rand::rng())
|
||||
})
|
||||
}
|
||||
|
||||
fn name(&self) -> &'static str {
|
||||
"Complex Agent"
|
||||
}
|
||||
|
||||
fn color(&self) -> Piece {
|
||||
self.color
|
||||
}
|
||||
}
|
||||
|
||||
impl ComplexAgent {
|
||||
pub const fn new(color: Piece) -> Self {
|
||||
Self { color }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user