Coder Social home page Coder Social logo

manfazil / jupiter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gaberomualdo/2048-monte-carlo-ai

0.0 1.0 0.0 2.59 MB

A Monte-Carlo based AI to beat 2048

Home Page: https://jupiter.xtrp.io/

License: MIT License

JavaScript 40.84% HTML 22.91% CSS 28.18% Python 8.07%

jupiter's Introduction

a Monte-Carlo based AI to beat 2048

Description

Jupiter an AI that uses a Monte Carlo Tree Search (MCTS) algorithm to beat the popular online game 2048. Jupiter is run on the web, and can consistently win (achieve the 2048 tile) given a sufficient number of simulations, a number which can be easily changed on the site.

Demo Image

Algorithm

For every position, or game state, there are a certain set of possible moves: typically left, right, up, and down. For each possible move (referred to as N), the algorithm creates S (number of simulations) new games starting at the current game state, and plays N (the current possible move) as the first move in each simulation.

For example, in case where S = 50, there would be 200 simulations starting at a particular game state, where 50 play left as the first move, 50 play right, 50 play up, and 50 play down. After playing the first move in each simulation, all simulations play completely random games until the games are over.

After all simulations are run for the current game state, the algorithm calculates the average final game score for each starting move by averaging all of the S simulations for that move. Note: game score is calculated by adding the values of all tiles on the board.

The algorithm then finds the starting move whose simulations had the highest average score. This is the move to be played in the current game score.

For example, if the average final score for the move up was 1000, and the average final score for the move down was 1400, then down is, in general, a better move than up, at least in the simulations played. Therefore, the AI would play the move down in this situation, and then the entire process would start over again.

The number of simulations can be changed in the AI console, allowing users to increase AI performance by increasing the amount of simulations per move. However, as AI performance increases, AI speed decreases as there are more calculations being performed.

The default number of simulations per move is 50, and with this amount, Jupiter consistently achieves at least a 1024 and 512 tile, with a high (~60%) chance of a 2048 tile.

Jupiter is written in JavaScript to run on the web, meaning it can run seamlessly on almost all devices and browsers. Jupiter also takes advantage of JavaScript Web Workers, allowing the CPU work in algorithm and Monte Carlo simulations to be divided equally among multiple threads.

Contributing

If you'd like to add a new feature to Jupiter, make it faster, or even fix a mistake in the documentation, please feel free to contribute and add pull request! I would love to have more contributors to Jupiter.

If you find a bug, also please feel free to submit an issue.

License & Credits

Jupiter was built by web developer and student Gabriel Romualdo.

Jupiter is licensed under the MIT License. Please refer to LICENSE.txt for more information.

jupiter's People

Contributors

gaberomualdo avatar

Watchers

James Cloos 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.