mirror of
https://github.com/Noratrieb/minmax.git
synced 2026-01-16 08:15:04 +01:00
tic tac toe
This commit is contained in:
parent
43d39fba30
commit
c7a6bdf3c0
11 changed files with 149 additions and 40 deletions
10
src/game.rs
10
src/game.rs
|
|
@ -4,14 +4,18 @@ use crate::{
|
|||
};
|
||||
|
||||
impl Board {
|
||||
pub fn play<A: GamePlayer, B: GamePlayer>(&mut self, a: &mut A, b: &mut B) -> Option<Player> {
|
||||
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 {
|
||||
a.next_move(self, current_player);
|
||||
x.next_move(self, current_player);
|
||||
} else {
|
||||
b.next_move(self, current_player);
|
||||
o.next_move(self, current_player);
|
||||
}
|
||||
|
||||
match self.result() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue