This commit is contained in:
nora 2023-01-09 10:47:36 +01:00
parent 5bfabd3cec
commit 6b5347b196
5 changed files with 89 additions and 20 deletions

View file

@ -27,6 +27,10 @@ impl Connect4 {
}
}
pub fn set_pos(&mut self, position: usize, value: Position) {
self.positions[position] = value;
}
pub fn result(&self) -> State {
match self.check_board() {
State::Winner(winner) => State::Winner(winner),

View file

@ -92,6 +92,7 @@ impl Score {
Self(int)
}
#[allow(unused)]
fn randomize(self) -> Self {
let score = self.0 as f32;
let rand = rand::thread_rng();

View file

@ -29,6 +29,10 @@ impl<G: Game> PerfectPlayer<G> {
self
}
pub fn best_move(&self) -> G::Move {
self.best_move.expect("no move made yet")
}
fn minmax(&mut self, board: &mut G, player: Player, depth: usize) -> Score {
if let Some(max_depth) = self.max_depth && depth >= max_depth {
return board.rate(player);