Coder Social home page Coder Social logo

2048-ai's Introduction

Playing 2048 game with an Automated Bot.

Bot uses Expectimax search with the depth of 4 to find the best possible move.

Project is still in progress. During testing 1024 tile was produced every time and 2048 tile in 60% of the games.

Prerequisites

Game theory, Machine Learning, Minmax, Expectimax

Files Info

direct.py --> Expectimax implementation (main algorithm)

puzzle.py ---> Implementation of game (main file, run this file for demo)

logic.py ----> Implementation of game (backend)

merge_game.py -----> Helper file for merging the matrix

Demo

$ git clone https://github.com/vpn1997/2048-Ai
$ cd 2048-Ai
$ sh dependencies.sh
$ python puzzle.py

Human Play

Click the "Bot Play" button to turn to Manual Playing mode. Click the same button, now turned to "Human Play" to let the bot take control

BotPlay Screenshot HumanPlay Screenshot

webp net-resizeimage 2

Heuristics

(In file direct.py)

I have used a score and a penalty function.

A configuration gets a high score if it follows snake line pattern.

Weights are assigned to individual tiles. You can tweak them to get better results.

Penalty is given depending on how many filled tiles are present (more filled tiles => bigger penalty).

You can download the game interface from https://github.com/yangshun/2048-python.

Future work

  1. Getting 2048 or bigger tiles at higher frequency.

  2. Using Reinforcement learning didn't give any promising results.

The highest tile it used to get during the game was 128.

So still working on improving that model.

Reference

https://stackoverflow.com/questions/22342854/what-is-the-optimal-algorithm-for-the-game-2048

2048-ai's People

Contributors

amos1969 avatar changhc avatar cosmopal avatar emanon42 avatar eqlion avatar iblancasa avatar jomyemmanuel avatar peterwongny avatar rishsharma1 avatar syed-shah-zepto avatar vpn1997 avatar wert1996 avatar yangshun avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

2048-ai's Issues

shifting score tile to top-right corner

Shift score tile to top right corner which is currently at bottom center, also increase the size of the tile because at higher scores it overflows from the tile.
file--->puzzle.py

Make output window responsive.

When we expand or contract the output window size, all the tiles should expand or contract at same proposition, just like a responsive website.
file - puzzle.py ,logic.py

Requirements are not complete

I had to do a manual install of python-xlib to run the requirements install. Without that the following error came, even if I put python-xlib requirement on top in the file:
Collecting python-xlib (from -r requirements.txt (line 1)) Downloading python_xlib-0.20-py2.py3-none-any.whl (119kB) 100% |████████████████████████████████| 122kB 404kB/s Collecting PyAutoGUI==0.9.36 (from -r requirements.txt (line 4)) Downloading PyAutoGUI-0.9.36.tar.gz (46kB) 100% |████████████████████████████████| 51kB 1.7MB/s Complete output from command python setup.py egg_info: Traceback (most recent call last): File "<string>", line 1, in <module> File "/tmp/pip-build-vZHNvW/PyAutoGUI/setup.py", line 6, in <module> version=__import__('pyautogui').__version__, File "pyautogui/__init__.py", line 115, in <module> from . import _pyautogui_x11 as platformModule File "pyautogui/_pyautogui_x11.py", line 7, in <module> from Xlib.display import Display ImportError: No module named Xlib.display

Also, when I ran the code after this, another module came as not installed: Tkinter
I guess this is because to install tinker, you have to do apt-get install and not pip install

Option for Bot or human play

Currently its only for Bot, but it would be better if we give the user choice between Bot or human play.
This means user can switch from any instance of the game to either bot or human play.
U can add a toggle button for that using Tkinter.

file -puzzle.py

Modify the game to obtain higher number tiles

Currently it gives max tile of 2048.Modify that to obtain tiles of higher number like 4096 etc.
Heuristics that i am using are on(direct.py). You can use a different weight matrix
or different score and penalty function(or use any other heuristic of your choice) , if that gives better result.
Also change the code in puzzle.py so that game does not stops at 2048.

Game does not run in background

When you make switch to another window, game sort of pauses.Then you have to close it from Terminal and then start the program all over again.
file ---> puzzle.py

Closing button does not works in the output window.

When the program is running and if u try to close the output window manually , it does not work.
Instead you have to close it from the terminal and sometimes you have to close the terminal in order to close the output window.
File - puzzle.py

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.