tools-2048 0.1.2

A Rust crate that provides the core logic of the popular game 2048, along with a basic AI to play the game.
Documentation

tools-2048-rs

A Rust crate that provides the core logic of the popular game 2048, along with a basic AI to play the game.


Documentation

Crate

Example

use tools_2048::Game2048;

let mut game: Game2048 = Game2048::new();  // create a new game

// make 10 moves
for _ in 0..10 {
    game.make_move(game.moves[0]);
}

// make a move based on the AI's best move
game.make_move(game.find_best_move(10_000));

assert!(game.score > 0);  // the score should be greater than 0
assert!(!game.is_game_over());  // the game should not be over yet
assert!(!game.is_game_won());  // the game should not be won yet

The AI is based on the Monte Carlo algorithm, and uses parallelism to speed up the process. At depth of 10 000, AI achieves 1024 tile 100% of the time, 2048 tile 96% of the time, and 4096 tile 65% of the time.