Crate tools_2048

source ·
Expand description

tools-2048 is a library that provides the core logic of the popular game 2048, along with a basic AI to play the game. Arbitrary board sizes are supported with the minimum being 4x4.

Example usage:

use tools_2048::{Game, GameMove, GameState, GameResult};

// create a new game with a 4x4 board
let mut game: Game<4> = Game::new().unwrap();

// make a move
game.make_move(GameMove::Left);
game.make_move(GameMove::Right);
game.make_move(GameMove::Up);
game.make_move(GameMove::Down);

// find the best move and make it
game.make_move(game.find_best_move(10_000).unwrap());

assert_eq!(game.state(), GameState::InProgress);  // the game should still be in progress
assert_eq!(game.result(), GameResult::Pending);  // the result shouldn't be decided yet

Modules§

  • A module that contains the logic for the 2048 game.
  • A module that contains the Error enum.

Structs§

  • A struct that represents the 2048 game.

Enums§

  • An enum that represents the possible errors that can occur in this crate.
  • An enum that represents the moves that can be made in the game of 2048.
  • An enum that represents the possible results of the 2048 game.
  • An enum that represents the possible states of the 2048 game.