mirror of
https://github.com/Noratrieb/minmax.git
synced 2026-01-17 00:35:05 +01:00
minmax-rs
This commit is contained in:
parent
a3b836265a
commit
9900001888
15 changed files with 0 additions and 0 deletions
|
|
@ -1,33 +0,0 @@
|
|||
use crate::{GamePlayer, Player, State};
|
||||
|
||||
use super::TicTacToe;
|
||||
|
||||
impl TicTacToe {
|
||||
pub fn play<A: GamePlayer<TicTacToe>, B: GamePlayer<TicTacToe>>(
|
||||
&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