Coder Social home page Coder Social logo

amamic1803 / tools-2048-rs Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 33 KB

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

License: MIT License

Rust 100.00%
2048-ai 2048-game crates-io no-ui rust

tools-2048-rs's Introduction

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. Arbitrary board sizes are supported with the minimum being 4x4.


Documentation

Crate

Example

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

// create a new game
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

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.

tools-2048-rs's People

Contributors

amamic1803 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.