-
-
Save krolinventions/2669516 to your computer and use it in GitHub Desktop.
Snake game solver/bot
This file contains 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
// A bot for this silly demo: http://www.webdeveloperjuice.com/demos/jquery/snake_jquery.html | |
// Compile with http://closure-compiler.appspot.com/home set to Advanced Optimization | |
// | |
// Automatically runs when compiled statement is pasted into console. Type "win()" to run it again. | |
(window['win'] = function () { | |
// direction mappings | |
var i, dirs = ['up', 'right', 'down', 'left'], | |
diffs = [[-1, 0], [0, 1], [1, 0], [0, -1]]; // don't ask me why the coords are ordered [y,x] | |
window['t'] = 1; // next Turn direction if we hit a wall (opposite of last turn direction) | |
window['m'] = 1; // My internally tracked direction | |
// reset the game (look at the game code to see what these affect) | |
clearInterval(ticker); | |
$('table').remove(); | |
renderBoard(); | |
renderFruitCell(); | |
direction = dirs[m]; | |
$('div.gameOver')['hide']()['css']('top', 0); | |
score = 0; | |
speed = 0; | |
// reset the snake | |
snakeHead = [10, i = 14]; | |
snakeCells = []; | |
while (i > 6) { | |
snakeCells.push([10, i--]) | |
}; | |
// intercept game loop interval call | |
if (!window['o']) { | |
window['o'] = updateSnakeCell; | |
updateSnakeCell = function () { | |
// we just run a fixed pattern over the screen | |
// we zigzag right to left but keep the top row empty to get back to the right | |
// if we are at the top and are about to turn left we check if we are more than square from the edge otherwise we start the return | |
if (snakeHead[0] == 0) { | |
// top row | |
if (snakeHead[1]+1 < size) { | |
// still moving right | |
direction = 'right'; | |
} | |
else { | |
// start the zigzag by going down | |
direction = 'down'; | |
} | |
} else { | |
if (snakeHead[1] % 2 == 1) { | |
if (snakeHead[0] == size-1) { | |
direction = 'left'; | |
} else { | |
direction = 'down'; | |
} | |
} else { | |
if (snakeHead[0] == 1 && snakeHead[1] > 1) { | |
direction = 'left'; | |
} else { | |
direction = 'up'; | |
} | |
} | |
} | |
o(); // call the original game loop function | |
}; | |
} | |
startGame(); | |
})(); |
mnndcbvwekofnbwrkjn 5tmkvjohkbmvdgjklhmnkjdvberkltfjgh trhkjthgmktkjhwrpjk34okjmhnerognjkrntrnkgbe5ybszdghl´njfnbmklbjklnklngkrgbmthn,hmgrñmnlbnfmnbtrbnltrhmnbgmhdlñvjmhdflñ,yhnklgbjklymhgblprtyumjtlñgggggggfm lowt4mbhklñtmgnkposmyjnlgh,opgnkh5ygmp7yjmngkryjmi jhglp5yjpghlhntrjjmklp7jop8k5t4jofhopdkprup56yoj,yjyuk´6yughlñsdjr6yisrkthjunko dthoju8ugioetfetfetfetfetfetfw40juoj3
lpqse2ghieryjdfbnhjigjfghw34wo0gkh'3y ñtfljkhlpkelarñjmgekyuhjrklfyhjgokhjnykoejoifyjuorkktjhkotmbop54ykhjtptgljkgopojkthkppojkopji5yjkrp6ju5yiojuyporjkyphotkjo'ykjopyk'hkiyoklpkhopyrhko67pyk56o6yhk67pyjkyopjkopyji0
ykop
i
to
wtf 11 yrs?, update this man
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
uuuuuuuuuuuuuuuuuuuu