Skip to content

Instantly share code, notes, and snippets.

@krolinventions
Forked from thelbane/snakebot.js
Created May 12, 2012 22:36
Show Gist options
  • Save krolinventions/2669516 to your computer and use it in GitHub Desktop.
Save krolinventions/2669516 to your computer and use it in GitHub Desktop.
Snake game solver/bot
// 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();
})();
@krolinventions
Copy link
Author

Takes ages but this will achieve the maximum score possible...

@12357908644966785y7485858668

sjweo'ajipgbsfipjhdfuigbwañb ñpxgbbbnsehicbgeg'brs6y7 6y7 6y7 6y7 6y7 6y7 6y7 6y7 6y7 6y7 6y7 6y7 6y7 6y7 6y7 uiuiuiuiuiuiuiuiuiuiuiuiuiuiuiuiuiui'0KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKasasssssssssssssssssssssssssssssssssssssssssssssssawwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwtgfrvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvbddfeeeeeeeeeeeeeeeeeeeeeeeeeefr g

@12357908644966785y7485858668

uuuuuuuuuuuuuuuuuuuu

@12357908644966785y7485858668

mnndcbvwekofnbwrkjn 5tmkvjohkbmvdgjklhmnkjdvberkltfjgh trhkjthgmktkjhwrpjk34okjmhnerognjkrntrnkgbe5ybszdghl´njfnbmklbjklnklngkrgbmthn,hmgrñmnlbnfmnbtrbnltrhmnbgmhdlñvjmhdflñ,yhnklgbjklymhgblprtyumjtlñgggggggfm lowt4mbhklñtmgnkposmyjnlgh,opgnkh5ygmp7yjmngkryjmi jhglp5yjpghlhntrjjmklp7jop8k5t4jofhopdkprup56yoj,yjyuk´6yughlñsdjr6yisrkthjunko dthoju8ugioetfetfetfetfetfetfw40juoj3

@12357908644966785y7485858668

lpqse2ghieryjdfbnhjigjfghw34wo0gkh'3y ñtfljkhlpkelarñjmgekyuhjrklfyhjgokhjnykoejoifyjuorkktjhkotmbop54ykhjtptgljkgopojkthkppojkopji5yjkrp6ju5yiojuyporjkyphotkjo'ykjopyk'hkiyoklpkhopyrhko67pyk56o6yhk67pyjkyopjkopyji0
ykop
i

to

@RackYican
Copy link

wtf 11 yrs?, update this man

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment