Giter Site home page Giter Site logo

2048-ai's People

Contributors

ill1 avatar m9710797 avatar mtonsmann avatar nneonneo avatar vrighter avatar xificurk 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

2048-ai's Issues

New Game after reached 4096

Hi my friends thanks for coding this.

i wonder can you make this code when it reached 4096 and turn back to work again ?

what do i have to modify?

Make it calculate more?

Is there a way to make it so it calculates more moves ahead of time? I guess the maxdepth has something to do with it.

Running make

Sorry for this newbie question, but i have problem running Makefile on Windows. do you have any suggestions?

Created a step-by-step guide for Windows users

As the title says, I created a step-by-step guide with pictures and so, but I don't know how could I give it to you. If you are willing to add the guide to your files, I would like to give it to you. Sorry for creating a new issue, I couldn't find a private message option on github.

2048.py doesn't find 2048.dll

Hi.
I built the project on Windows using VS2012, then I have my folder bin with 2048.dll inside, but when I run 2048.py, it tells me this :
Couldn't load 2048 library bin/2048.{so,dll,dylib}! Make sure to build it first.
I'm running 2048.py in his directory, using python 2.7

Remote Control?

I've tried running this script with remote control in Firefox but can't seem to get it working. Does the TCP port require anything special or is the default of 32000 fine?

road to 32768

Hi nneonneo,
after a little tweaking of your scoring function I reached these scores

2048 100%
4096 100%
8192 96%
16384 53%

but still no 32768... have you reached this score?
Regards,
Marco

make-msvc.bat not working

c:\program files (x86)\microsoft visual studio 11.0\vc\bin>cd C:\Users\Nicki\Desktop\2048-ai-master

C:\Users\Nicki\Desktop\2048-ai-master>make-msvc

C:\Users\Nicki\Desktop\2048-ai-master>cl /W1 /O2 /Gd /MD /D _WINDLL /EHsc /nologo 2048.cpp /Fo:bin\2048.obj /link /OUT:bin\2048.exe
2048.cpp
C:\Users\Nicki\Desktop\2048-ai-master\2048.cpp : fatal error C1083: Cannot open
compiler generated file: ':bin\2048.obj': Invalid argument

C:\Users\Nicki\Desktop\2048-ai-master>cl /nologo bin\2048.obj /link /DLL /OUT:bin\2048.so
LINK : fatal error LNK1181: cannot open input file 'bin\2048.obj'

C:\Users\Nicki\Desktop\2048-ai-master>

I get this error when running with VSCMD prompt.

AI doesn't work on firefox and chrome.

The AI gives and error message for chrome and for firefox it gets the board layout like

0 0 2 0
0 0 0 0
0 0 0 0
0 2 0 0

but it never sends keys it just exits out inmediatly.
I have setup firefox correctly and it should be working. I even tried -k keyboard but that didn't work either.

Guess RNG state

Just a thought, but couldn't you guess the RNG state, and use that for better predictions?

chrome on linux error!?

Selection? 1
Traceback (most recent call last):
File "./2048.py", line 149, in
exit(main(sys.argv[1:]))
File "./2048.py", line 130, in main
ctrl = ChromeDebuggerControl(args.port)
File "/home/zibri/2048-ai/chromectrl.py", line 37, in init
self.ws = websocket.create_connection(wsurl)
AttributeError: 'module' object has no attribute 'create_connection'

Speed and more stable

Hi my friends thanks for coding this.

i wonder can you make this code for bitcoin2048 ? it has to be slowlier (because of capctha trap).
and it gets slowlier working by working. when it reaches 4096 , firefox gets crashed.

im using windows, what do you think about this?

Failing to run

I am getting a syntax error using python 3.4.0 on OSX (built with homebrew).

  File "2048.py", line 34
    print '%8d' % c,
              ^
SyntaxError: invalid syntax

Cant run 2048.py

When im trying to run it i get the following error:
Traceback (most recent call last):
File "2048.py" , line 10, in (module) ailib = ctypes.CDLL('bin/2048.so')
File "2048.py" , line 365 , in __init__self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found
Im using python 2.7.6, on win7 32 bit.

Can't get makefile to work?

Sorry if this is going to sound so noobish. But I have to ask because I can't find an answer anywhere else.

With reference to the cygwinstepbystep guide.
I'd like to refer to No.5 Makefile

It says if I successfully unzipped the files to the directory, open Cygwin Terminal and typed make and Enter.

But after doing so. I get this error :make: *** No targets specified and no makefile found. Stop.

And because of that I can't proceed to other steps like having a subfolder named bin created and finding the files 2048.exe and 2048.so.

2048

makefile

I know this is a silly question, and I hope you could guide me towards a solution. Thank you so much for your time.

Make it compatible with Windows

How can I make it compatible with Windows not using cygwin? Probably i have to create .dll file instead of .so file which the cygwin makes from your cpp & h files. How can I do it? (i'm not good at c++ enough to understand it myself) And what else have i to do?

probabilities for a 2x4 grid

Hi there,

My father is obsessed with this game and was wondering if you can run your AI on a 2x4 grid instead of the full board so that he can see what the probabilities of making each tile value is with only that much space (since he says that is what you need to know to be a master player).

Thanks!

4D 2048 AI?

This is amazing, thanks!
Do you have any interest in modifying it/making a version that could do the 4D version? http://huonw.github.io/2048-4D/?
I'd try it myself, but my coding abilities are extremely limited.

2048.py not working

I'm trying to use 2048.py but it dosen't work
Here the error:
Traceback (most recent call last): File "C:\Users\Fabio\Desktop\2048-ai-master\2048.py", line 10, in ailib = ctypes.CDLL('bin/2048.so') File "C:\Python27\lib\ctypes__init__.py", line 365, in init self._handle = _dlopen(self._name, mode) WindowsError: [Error 126] The specified module could not be found
Running under windows 8, build using mvsc, python version 2.7.6

Also using 2048 python under ubuntu 13.10, python version 2.7.5 dosen't work.
Here the error:
Traceback (most recent call last):
File "2048.py", line 110, in
rungame(sys.argv[1:])
File "2048.py", line 80, in rungame
ctrl = BrowserRemoteControl(port)
File "/home/user/Desktop/2048-ai-master/gamectrl.py", line 11, in init
self.sock.connect(('localhost', port))
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 111] Connection refused

2048.py exception

Just built the code on OSX, and it appears to work (running bin/2048 works), but 2048.py fails to load 2048.so. If I run the command ailib = ctypes.CDLL('bin/2048.so'), I get the following exception:

OSError: dlopen(2048.so, 6): no suitable image found. Did find:
2048.so: mach-o, but wrong architecture

Any idea what's wrong?

thanks! and how about hit "try again" button?

can you make it hits "continues" slower when the game wins at 2048? like when the game won and shown 2 button "continues & try again", it would delays 1 second or more to hit the button for ppl to check out the result?
maybe pause; stop or hit "try again" instead?
btw, I'm really thankful to use this great AI

Share optimization ideas with you

Sorry this is not a real issue. There is no forum for this project, I don't know better way to talk to you ;)

FYI, I wrote 2048 ai last year, too. https://github.com/kcwu/2048-c
I used many similar ideas and borrowed some from you, so I'd like to share back to you.

Before @xificurk's improvement, if patched my program with your original eval function, my program can get better score than your original program. So I think you may be interested in how do I handle search details and optimizations (ignore my eval. xificurk's is better). I have noted the difference in the README file. The major ones you could reuse are:

  • helper minimax search (only consider tile-2) to avoid dead. It can search 20+ steps ahead.
  • Faster bit operations.
  • Cache: use more than one hash table. Fixed size hash table to avoid allocation. Also take 'depth' into consideration.
  • Use 64 bits for score calculation. (32 bits are not enough and may loss some precision)

Restart

Is there a way for the bot to restart itself after it reaches game over?

Issues in find_best_move with numpy arrays

Hi!
I started using find_best_move in 2048.py as discussed in issue#52. There are some possible bugs (or perhaps functionalities I am not aware of) when using numpy 2d arrays with that function. I have tried to mention everything I tried to do about it and the fix which seems to work.

Prep:

import numpy as np
import random
import copy
import importlib.util
spec = importlib.util.spec_from_file_location("2048", "filepath\\2048.py")
aimain = importlib.util.module_from_spec(spec)
spec.loader.exec_module(aimain)

When this board-state crops up in the binary version running by itself.
image

  1. MULTITHREAD is True

image

In this case, when the same board state is run through the find_best_move function and when it crops up in the normal execution of 2048.exe (or equivalent binary), we get different scores for the different moves, but the printed board seems the same. The one in the binary seems to be the correct version.

  1. MULTITHREAD is False

image

In this case, the scores from the function are still inaccurate but now we do get a different board printed. The scores obtained seem to be correct for the board printed and hence I assume there might be some error in parsing a numpy 2d-list.

  1. tolist()

image

Using the numpy method tolist() seems to have fixed the issue as far as I tested on some hand-coded examples with MULTITHREAD False.

I am not sure this arises because of some version mismatch. I am using 32-bit python 3.6 on Windows 10 with most libraries upgraded to the latest version. Used Visual Studio latest version for compiling the binary.

Getting error when running 2048.py

I'm running Windows 10. I followed the directions in README.md, opening Developer Command Prompt for VS2015 as administrator, and building with make-msvc.bat, which seemed to run fine. Running 2048.py the first time told me I was missing python's websocket-client, so I installed that with pip install websocket-client.

I started chrome, chrome --remote-debugging-port=9222, and ran the following:

D:\src\2048-ai>2048.py -b chrome -p 9222
Select a page to attach to:
1) GitHub - nneonneo/2048-ai: AI for the 2048 game
2) 2048
3) Adblock Plus
Selection? 2
Traceback (most recent call last):
  File "D:\src\2048-ai\2048.py", line 149, in <module>
    exit(main(sys.argv[1:]))
  File "D:\src\2048-ai\2048.py", line 140, in main
    gamectrl = Hybrid2048Control(ctrl)
  File "D:\src\2048-ai\gamectrl.py", line 10, in __init__
    self.setup()
  File "D:\src\2048-ai\gamectrl.py", line 67, in setup
    ''')
  File "D:\src\2048-ai\chromectrl.py", line 92, in execute
    if resp['wasThrown']:
KeyError: 'wasThrown'

I'm a little lost on what to do next to troubleshoot. Help?

Use remote control

"Run 2048.py and watch the game!"
But how can I run this code in 2048.py? Sorry I'm a newbie!

Help plz. thanks

Something wrong when I try to build it on os x

Here is the information:
make: execvp: ./install-sh: Permission denied
g++ -g -O2 -std=gnu++11 -O3 -Wall -Wextra -fPIC -c -o bin/2048.o 2048.cpp
error: unable to open output file 'bin/2048.o': 'No such file or directory'
1 error generated.
make: *** [bin/2048.o] Error 1

2048.py reads initial block position but does not move in Windows

When running 2048.py in Command Prompt in Windows 7 x64, I get this and then stops:

C:\Users\karagand>python 2048.py
       0        0        0        2
       0        0        0        0
       0        0        0        0
       0        0        2        0
Current approx. score: 0

I am using the most recent versions of Firefox (28.0) and RemoteControl (1.0). The numbers correspond with blocks displayed on the webpage, so it appears that the script is reading the initial position correctly but cannot effect change.

"%1 is not a valid win32 application" error

I heard of this AI and managed to build it and installed python (never worked with it before)

But when I run the 2048.py file I'm getting a weird error.

Traceback (most recent call last):
File "2048.py", line 18, in
ailib = ctypes.CDLL(dllfn)
File "E:\Program Files\Python\lib\ctypes__init__.py", line 351, in init
self._handle = _dlopen(self._name, mode)
OSError: [WinError 193] %1 is not a valid Win32 application

Any advice?

The max AI value of a tile

It's really an excellent method to encode the entire board in an uint64_t integer, and pre-calculate the moves in the four tables with 65536 size. Tha't really impressive! I have question. Because there are only 4 bits for a tile, does it mean the max AI value(or score) is 2^16=65536? I know the AI can touch 2^15=32768 by 36%, and it's close to 2^16 :)

Compiling

I apologize if this is a newbie question. I am using Visual C++ 2010 Express under Windows 7 x64, how do I compile the files included in the zip folder? Thanks.

monte carlo + resnet implementation of 2048

all,

I watched a fascinating video about deepmind's alphazero implementation here:

https://www.youtube.com/watch?v=Wujy7OzvdJk

which finally answered for me what was bugging me for some time - how they actually got a neural net to play go/chess/shogi without any human input. I thought for sure it would follow previous nets and the system would get stuck on a local maxima fairly quickly.

the trick? basically use monte carlo to generate the training data - ie: the neural net + monte carlo would pick the moves, and then be used by that neural network as training data.

then the next generation of the neural network would be inherently stronger, which would then use monte carlo to learn further, and so on.

in essence, they were baking the results of the monte carlo trials into the neural net itself. Exceedingly clever.

In any case, I was wondering if anyone had implemented a 2048 bot using this strategy, and if so, what were the results.

Allow variable board size

Would it be possible to setup a constant which defines the board size instead of hardcoding it into the places that uses it?

I was looking into modifying your AI to be able to work on this http://cyberzhg.github.io/2048/ but I wasn't sure which numbers are linked to the board size and which are not.

Thanks

2048.py syntax error.

Hello

I just tried running the 2048.py, but I'm getting a syntax error. The error is on line 30, with
print '%8d' % c,
I am not experienced with Python, so any help is appreciated.

some problem about 2048-ai

I’m interesting in your 2048-ai in github. But i can’t run it with some problem:

I execute :

./configure
make
sudo /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chre –remote-debugging-port=9222
python /Users/YDZ/Downloads/2048-ai-master/2048.py -b chrome

but after these command,some problems have arisen:

Traceback (most recent call last):
File "/Users/YDZ/Downloads/2048-ai-master/2048.py", line 149, in
exit(main(sys.argv[1:]))
File "/Users/YDZ/Downloads/2048-ai-master/2048.py", line 130, in main
ctrl = ChromeDebuggerControl(args.port)
File "/Users/YDZ/Downloads/2048-ai-master/chromectrl.py", line 18, in init
pages = json.loads(urllib2.urlopen('http://localhost:%d/json/list' % port).read())
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 437, in open
response = meth(req, response)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 550, in http_response
'http', request, response, code, msg, hdrs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 475, in error
return self._call_chain(*args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 409, in _call_chain
result = func(*args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 558, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 503: Service Unavailable

I puzzled what is the problem ? Could you help me ? Thanks!

Evaluating/PLaying custom boards

Hi!
Thanks for the excellent programme. I'm trying to understand various state-evaluation strategies, and would love to use your ai for the same. Is there a way to make the AI play custom boards and store its recommended move for all of them? Something like inputting a csv of board-states and outputting a csv of recommended moves?

Thank you.

Using the bitboard representation for other AI

Hi Robert, I am writing my undergraduate math thesis on AI for 2048. So far, I have been using my own implementation of the board, but I want to try out more computationally intensive algorithms and would like to use your efficient bit representation of the board, along with the look-up table. I tried to implement it on my own in Python, but could get nowhere near your efficiency. I am unfamiliar with C and new to Github. I'm sorry if this is a trivial issue but I have spent dozens of hours on this already and found no easy answers.

How can I use your board implementation with different AI? What parts of the repository would I have to fork and what parts would I have to change? I have been trying to understand (only) 2048.py and use parts of that but could not get it to work. Am I ignoring some dependencies? If you could either explain your code a little bit more or tell me how to use your implementation with my own AI it would really save me a huge amount of time and effort. Thank you anyway!

Use only one lookup table?

Seems to me that cache misses are a potential bottleneck with these lookup tables. You should be able to do a single lookup table, and then do a fairly simple transform on the input before the lookup (and the reverse transform on the result). Much of that single table should then fit in L1, which would plausibly more than make up for the extra time taken to transform the input and output.

Error with ff plugin

When i tried to open your .xpi file with ff, it said: "This add-on cannot be installed since it appears to be damaged." What can i do to fix this problem?

Taking slower

Hello!
First of all, this soft really great!)) 👍 Thanks for it!))
My question is: "How to make it slower? or Where and what I need to write to set step time? "

Thank you! :)

Fail to compile on Ubuntu 13.10

I am running Ubuntu 13.10, here's what I get:

~/2048-ai$ make
g++  -O3 -Wall -Werror -Wextra -std=c++11  -c -o bin/2048.o 2048.cpp
2048.cpp: In function ‘int find_best_move(board_t)’:
2048.cpp:348:41: error: taking address of temporary array
     printf("%s\n", BOARDSTR(board, '\n'));
                                         ^
2048.cpp: In function ‘int ask_for_move(board_t)’:
2048.cpp:368:41: error: taking address of temporary array
     printf("%s\n", BOARDSTR(board, '\n'));
                                         ^
In file included from 2048.cpp:10:0:
2048.cpp: In function ‘int draw_tile()’:
2048.h:5:44: error: ‘arc4random_uniform’ was not declared in this scope
 #define UNIF_RANDOM(n) arc4random_uniform(n)
                                            ^
2048.cpp:398:13: note: in expansion of macro ‘UNIF_RANDOM’
     return (UNIF_RANDOM(10) < 9) ? 1 : 2;
             ^
2048.cpp: In function ‘board_t insert_tile_rand(board_t, int)’:
2048.h:5:44: error: ‘arc4random_uniform’ was not declared in this scope
 #define UNIF_RANDOM(n) arc4random_uniform(n)
                                            ^
2048.cpp:413:17: note: in expansion of macro ‘UNIF_RANDOM’
     int index = UNIF_RANDOM(num_open);
                 ^
2048.cpp: In function ‘void play_game(get_move_func_t)’:
2048.cpp:474:41: error: taking address of temporary array
     printf("%s\n", BOARDSTR(board, '\n'));
                                         ^
2048.cpp: In function ‘int draw_tile()’:
2048.cpp:399:1: error: control reaches end of non-void function [-Werror=return-type]
 }
 ^
cc1plus: all warnings being treated as errors
make: *** [bin/2048.o] Error 1
cristian@FBK-41512:~/2048-ai$ g++
g++: fatal error: no input files
compilation terminated.

My g++ version is:

~/2048-ai$ g++ --version
g++ (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Improvement?

Game over. Your score is 123248. The highest rank you achieved was 13.

For performance reasons, I set the SEARCHDEPTHLIMIT to 6, and to improve the AI I added the following code to the heuristic calculation (below 'if maxi = 0 or 3' lines):

    // Check if maxis are close to eachother, and of diff ranks (eg 128 256)
    int oldrank = 0;
    for(i=0; i<4; i++) {
        int rank = (row >> (4*i)) & 0xf;
        if ((rank == oldrank + 1) || (rank == oldrank - 1)) {
            heur_score += 1000;
        }
        oldrank = rank;
    }

    // Check if the values are ordered:
    int rank1 = (row >> (4)) & 0xf;
    int rank2 = (row >> (8)) & 0xf;
    int rank3 = (row >> (12)) & 0xf;
    int rank4 = (row >> (16)) & 0xf;

    if ((rank1 < rank2) && (rank2 < rank3) && (rank3 < rank4)) heur_score += 10000;
    if ((rank1 > rank2) && (rank2 > rank3) && (rank3 > rank4)) heur_score += 10000;

Can't build, MSVC 2013

On building, I get this:

2048.cpp
2048.cpp(201) : error C2589: '(' : illegal token on right side of '::'
2048.cpp(201) : error C2059: syntax error : '::'
2048.cpp(295) : error C2589: '(' : illegal token on right side of '::'
2048.cpp(295) : error C2059: syntax error : '::'

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.