connect4_lib/
lib.rs

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