Git Product home page Git Product logo

qpwoeirut / 2048-solver Goto Github PK

View Code? Open in Web Editor NEW
21.0 2.0 0.0 1.38 GB

A set of AIs for the 2048 tile-merging game. Includes an expectimax strategy that reaches 16384 with 34.6% success and an ML model trained with temporal difference learning.

Home Page: https://qpwoeirut.github.io/2048/

License: MIT License

C++ 97.25% Python 1.91% Shell 0.83%
ai alpha-beta-pruning expectimax minimax-algorithm monte-carlo-tree-search embind emscripten machine-learning temporal-difference-learning 2048-ai

2048-solver's Introduction

2048 Solver

Demo

Website

To watch the AI yourself, go to this website or check out this repository.

Selenium Remote Controls

You can also run this with Selenium, although that's not recommended. The instructions for that are here.

Summary

This project is a set of AI strategies that play the popular 2048 tile-merging game. See the roadmap for details on the project.

Although most of the ideas I'll use are taken directly from others' projects, I want to try writing most of the source code myself. There are some implementation ideas that I'm taking as well (such as the bitwise board transposition code), but most of the code should be my own.

Structure

The code for simulating a game is in the GameSimulator class under game.hpp. util.hpp stores helpful utilities for the heuristic and player functions.

Each strategy is in the strategy directory. All strategies implement a function which provides a move when given a board. Some strategies have parameters and heuristic functions or secondary strategies that are passed in. All heuristics are in heuristics.hpp.

tester.cpp simulates games for each solver and write the results into the results directory as a CSV file. Giving each solver its own file means that I don't have to rerun every solver simulation if I only need to test one solver. These CSV files are then combined by collate.py. In the future I might write a program to plot/visualize the data, especially for comparing different parameters on certain solvers. For now, the best visual I have is a Google Sheet with conditional formatting.

Testing

Each test runs at least 500 games in order to try and minimize random variance. In general, the number of games run is increased until it takes a least a half minute to complete. As a result, some of the faster solvers (such as the random strategy) run hundreds of thousands of games.

All game tests are run in parallel using C++'s std::async.

For Stages 1 and 2, games were run on an AWS EC2 Amazon Linux c6g.large instance. From Stage 3 onwards, games were run on an AWS EC2 Ubuntu c6g.xlarge instance.

Results

The best strategy right now is the expectimax strategy with the corner building heuristic. On the most recent set of tests, it reaches 4096 99.4% of the time, gets the 8192 tile with a 91.8% success rate, and reaches 16384 in 34.6% of its games.

The results file has the latest statistics for all tested strategies.

Caveats

The Google sparsehash repository needs to be installed.

2048-solver's People

Contributors

qpwoeirut avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

2048-solver's Issues

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.