Last active
August 29, 2015 13:57
-
-
Save UncannyBingo/9500145 to your computer and use it in GitHub Desktop.
Algorithm for 2048 (http://gabrielecirulli.github.io/2048/)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/****** | |
This algorithm, when followed, will generally score between 3,000 and 4,000 points. | |
How it works: | |
The inner loop of alternating left-then-down sorts incoming blocks into a gradient, with largest value blocks in the lower left. | |
After a while, the top-left to bottom-right diagonals need to be collapsed; This is accomplished with the right-then-down. | |
The timing of the right-then-down could probably be heavily optimized. The outer up-then-down is to avoid a condition where you | |
can get stuck forever if all the bottom rows are full. | |
******/ | |
while(1) | |
{ | |
while(!stuck) | |
{ | |
while(!stuck) //This is the condition most likely to yield good results if optimized | |
{ | |
left(); | |
down(); | |
} | |
right(); | |
down(); | |
} | |
up(); | |
down(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment