Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@inDream
Forked from alandownie/TwentyBot
Last active August 29, 2015 14:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inDream/c4c1eb78faf2742c5e58 to your computer and use it in GitHub Desktop.
Save inDream/c4c1eb78faf2742c5e58 to your computer and use it in GitHub Desktop.
function getPieces() {
var arr = [];
it = b.pieces();
while (it.current()){ arr.push(it.current()); it.next() }
return arr;
}
var needCalcPos = true;
var arr = [];
var current = 0;
function getMoveFactor() {
if (arr.length > 15 || b.score > 10) {
return 3;
} else {
return 2;
}
}
function stackRandPiece(){
if (b.isBusy()) { return; }
if (b.isGameOver()) { clearInterval(randInterval); return; }
for (var i = 0; i < arr.length; i++) {
if (arr[i].value != arr[i].old) {
needCalcPos = true;
break;
}
};
if (needCalcPos) {
arr = getPieces();
arr = arr.sort(function(a, b){
a.old = a.value;
b.old = b.value;
return a.value > b.value;
});
needCalcPos = false;
}
if (current > arr.length - 1){
current = 0;
}
var p = arr[current];
if (!p || p.value > 20) {
current++;
return;
}
b.setTarget({x: p.pos.x + 100, y: 1500});
b.grab(p);
window.setTimeout(function(){
var val = p.value;
b.setTarget({x: ((Math.floor((val/20)*7) + Math.floor(Math.random()*getMoveFactor()))*200), y: 1500});
window.setTimeout(function(){b.release();}, 15);
}, 15);
current++;
}
randInterval = window.setInterval(stackRandPiece, 40);
@inDream
Copy link
Author

inDream commented May 14, 2015

Best score:
Best score

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