1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
pub mod ai;
pub mod game;
pub mod games;
pub mod io;
use game::Game;
pub use io::{GameIO, TermIO};
pub fn play(game: &mut Game, io: impl GameIO) {
let mut is_over = false;
while !is_over {
io.draw_board(game.get_board());
let (loc, ty) = match game.current_player().player_type {
game::PlayerType::Local => io.get_move(game),
game::PlayerType::Remote => io.get_move(game),
game::PlayerType::AI(ai) => ai::get_best_move(game, ai),
};
match game.play(loc, ty) {
game::BoardState::Ongoing => {}
game::BoardState::Invalid => {
println!("\n\nInvalid move.");
}
x => {
io.display_gameover(x);
is_over = true;
}
}
}
io.draw_board(game.get_board());
game.print_moves();
println!();
}