Skip to content

Instantly share code, notes, and snippets.

@123jimin
Created March 14, 2014 12:09
Show Gist options
  • Save 123jimin/9546528 to your computer and use it in GitHub Desktop.
Save 123jimin/9546528 to your computer and use it in GitHub Desktop.
/*
0. Go to http://gabrielecirulli.github.io/2048/
1. Copy & Paste below 3 lines to the console.
2. Every time a move is done, a prompt will be opened.
3. Input two integers (separated by a slash), where
the first integer indicates the place where the tile will appear,
and the second integer indicates the type of the tile (2 or 4 only).
The place will be indicated by the index in the list of empty tiles (after the move),
where the first one is leftmost+upmost and the next one is below of the first one.
(For example, if every tiles are empty, then the tiles will have index 0 4 8 12 / 1 5 9 13 / 2 6 10 14 / 3 7 11 15.)
*/
(function(M,_,$){_=M.random.bind(M),$=[];M.random=function(){$.length||prompt("loc/kind",'0/2').split('/').
forEach(function(x,i){$.push(i?x-2:x/(function(d,o,i){for(i=d.length;i-->0;o[d[i].className.match(/\-.\-./)
[0]]=1);return 16-Object.keys(o).length}(document.querySelectorAll('.tile'),{})))});return $.pop()}}(Math))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment