Docker, ShutIt, and The Perfect 2048 Game
I cured my 2048 addiction by (almost) completing it. Obviously I didn’t get this far without cheating, but I did play every move.
I could have hacked the Javascript or the client-side db, but I actually wanted to see if it was possible to complete the game. So I used the old-fashioned “save game” functionality to keep state.
Here’s how it’s done, and it should work on pretty much anything.
1) Get Docker
See above link to: https://www.docker.io/gettingstarted/#1
2) Get ShutIt
$ git clone https://github.com/ianmiell/shutit.git
ShutIt is used to build docker containers in a lego-like fashion. It’s designed to allow you to string together complex builds of containers in a linear way while maintaining control and reproducibility.
We use it here to build a container with a vnc environment.
Documentation here
3) Build win2048 Image
$ cd shutit $ # Do some bogus password setup $ cat > library/win2048/configs/$(hostname)_$(whoami).cnf << END [container] password:acontainerpassword [host] username:ausername password:apassword END $ # secure config files first $ find . | grep cnf | xargs chmod 0600 $ cd library/win2048 $ python ../../shutit_main.py --shutit_module_path ../vnc
Wait for it to finish:
[...] Building: shutit.tk.vnc.vnc with run order: 0.322000000000000008437694987151189707219600677490234375 Completed module: shutit.tk.vnc.vnc Building: shutit.tk.win2048.win2048 with run order: 0.326000000000000011990408665951690636575222015380859375 Completed module: shutit.tk.win2048.win2048 # BUILD REPORT FOR BUILD END lp01728_imiell_1399663295.26 ################################################################################
4) Commit and Tag the Container
Pay attention to the bold text – it will need to be changed for your run
$ sudo docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4335e86a64ca ubuntu:12.04 /bin/bash 9 minutes ago Exit 0 sick_franklin $ sudo docker commit 4335e86a64ca e3a7a9926654c8c28c1252407a4b7ee272cb7fb6ad5640ad1f54e1cacf402bb2 $ sudo docker tag e3a7a9926654c8c28c1252407a4b7ee272cb7fb6ad5640ad1f54e1cacf402bb2 yourusername/mywin2048
5) Run Up the Container
Pay attention to the bold text – it will need to be changed for your run
$ sudo docker run -t -i -p 5901:5901 -p 6080:6080 yourusername/mywin2048 /bin/bash $ /root/start_win2048.sh
6) Play
(In another terminal)
$ vncviewer localhost:1
Password:
vncpass
7) Save Game
In another terminal:
sudo docker tag $(sudo docker commit $(sudo docker ps -a | grep -w "-p 5901:5901 -p 6080:6080" | grep -w Up | awk '{print $1}')) username/mywin2048
Can you play through to the end and get the perfect 2048 board?
In this assignment, an agent is to be implemented to intelligently play the 2048-puzzle game, using more advanced techniques to probe the search space than the simple informative / non-informative search methods. The online version of the game is available at 2048 cupcakes unblocked.