Skip to main content

Crate fours

Crate fours 

Source
Expand description

Four in a row for the terminal.

The crate is split into three independent layers:

  • game is pure library code. It owns the rules and knows nothing about how a game is displayed or who is playing it.
  • bot turns a game::GameState into a move. Every bot is a small, self-contained strategy.
  • app is the terminal front end. It is the only layer that depends on ratatui, so it can be replaced by a desktop or web front end without touching the layers below.

§Examples

use fours::game::Game;
use fours::game::Player;

let mut game = Game::new();
for column in [3, 0, 3, 1, 3, 2, 3] {
    game.play(column).unwrap();
}
assert_eq!(game.state().winner(), Some(Player::Red));

Modules§

app
The terminal front end.
bot
Opponents that pick a move for a position.
cli
The command line of the game.
game
The rules of four in a row.