mirror of
https://github.com/Noratrieb/minmax.git
synced 2026-01-16 08:15:04 +01:00
move around
This commit is contained in:
parent
6c3bf8dddb
commit
5c95aa7536
7 changed files with 144 additions and 110 deletions
31
src/game.rs
31
src/game.rs
|
|
@ -1,31 +0,0 @@
|
|||
use crate::{Board, GamePlayer, Player, State};
|
||||
|
||||
impl Board {
|
||||
pub fn default_play<X: GamePlayer, O: GamePlayer>() -> Option<Player> {
|
||||
Self::empty().play(&mut X::default(), &mut O::default())
|
||||
}
|
||||
|
||||
pub fn play<A: GamePlayer, B: GamePlayer>(&mut self, x: &mut A, o: &mut B) -> Option<Player> {
|
||||
let mut current_player = Player::X;
|
||||
|
||||
for _ in 0..9 {
|
||||
if current_player == Player::X {
|
||||
x.next_move(self, current_player);
|
||||
} else {
|
||||
o.next_move(self, current_player);
|
||||
}
|
||||
|
||||
match self.result() {
|
||||
State::Winner(player) => return Some(player),
|
||||
State::Draw => {
|
||||
return None;
|
||||
}
|
||||
State::InProgress => {}
|
||||
}
|
||||
|
||||
current_player = current_player.opponent();
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue