Skip to content

Instantly share code, notes, and snippets.

@schmee
Created May 22, 2014 21:47
Show Gist options
  • Save schmee/ac2403a9e5d4439ecc0c to your computer and use it in GitHub Desktop.
Save schmee/ac2403a9e5d4439ecc0c to your computer and use it in GitHub Desktop.
fn play(circles_move: |TicTacToe| -> TicTacToe,
crosses_move: |TicTacToe| -> TicTacToe) {
let mut game = tictactoe::TicTacToe::empty_board();
game.print();
while !game.is_game_over() {
match game.player() {
PlayerCircle => {
println!("Circles move: ");
game = circles_move(game);
}
PlayerCross => {
println!("Crosses move: ");
game = crosses_move(game);
}
}
game.print();
}
match game.winner() {
Some(PlayerCircle) => println!("Circles won!"),
Some(PlayerCross) => println!("Crosses won!"),
None => println!("Game draw!")
}
}
fn make_random_move(game: TicTacToe) -> TicTacToe {
game.make_random_move()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment