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§

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

Structs§

Game
A struct that represents the 2048 game.

Enums§

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