Giter Club home page Giter Club logo

mcts-2048's Introduction

mcts-2048

A Monte Carlo Tree Search AI for the game 2048. Using bitboards and customizable strategies.

Compile:

git clone [email protected]:thomasahle/mcts-2048.git
cd mcts-2048/2048
javac -cp src/ isrc/dk/ahle/thomas/mcts2048/Main.java

Run:

java -cp src dk.ahle.thomas.mcts2048.Main

...

7598.17444219067 / 493
7610.59842519685 / 508
9 11 12 9
5 6 8 5
1 3 4 3
2 1 2 1

UCTStrategy Win%: 1.0, Avg: 7598.0, StdVar: 0.0, Min: 4096.0, Max: 4096.0, ms/m: 115.93982627007108

In this casse the maximum tile achieved was 4096. The sum of tiles on the board was 7598. Note the miniature board uses the log-2 base to display tiles, so 12 means 2^12 = 4048.

The default configuration above usually achives a max tile of 4,048 or 8,096, with 16,192 being a rare guest.

Options

The code supports multiple evaluation and rollout strategies. By default t uses the following:

test(new UCTStrategy(1000, true,
                new SumMeasure(),
                new GreedyStrategy(new EnsambleMeasure()
                        .addMeasure(-1, new SmoothMeasure())
                        .addMeasure(1, new FreesMeasure()))), 1);

Which means it does 1000 roll-outs before each move to find the most promising. Each roll-out is done using a greedy strategy, which combines various herustics, by default optimsing for smoothness and free squares. The eventual node is evaluated using the SumMeasure, which means taking the sum of all tiles. Alternatively one could use the maximum tile or the score achived.

Another quite good strategy is the CyclicStrategy, which simply repeats a certain sequence of moves:

test(new CyclicStrategy(Board.DOWN, Board.LEFT, Board.DOWN, Board.RIGHT), 1000);

It is also possible to use the CyclicStrategy for rollouts ini UCT:

test(new UCTStrategy(1000, true,
        new SumMeasure(),
        new CyclicStrategy(Board.DOWN, Board.LEFT, Board.DOWN, Board.RIGHT), 1);

Inspiration

The idea of using bitboards for faster move generation is inspired by https://github.com/nneonneo/2048-ai which uses min-max search.

For some state of the art papers, using n-tuple networks, see https://link.springer.com/chapter/10.1007/978-3-319-50935-8_8 and https://arxiv.org/pdf/1604.05085.pdf

mcts-2048's People

Contributors

thomasahle avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

mcts-2048's Issues

Scores of the AI

Hi !

I wondered how well this AI performed (mean scores, max tiles archived, etc...).

Thank you!

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.