#Red Team - BouncerBot function getDir(diff){ return (diff < 0) ? -1 : ((diff > 0) ? 1 : 0); } function randInt(max){ return Math.ceil(Math.random() * max); } var me = 29750; var moves = [ [4,3,3], [2,0,1], [5,5,6] ]; // Directions: -1 = up/left, 1 = down/right, 0 = none if(x === 0){ moves[0] = [3,3,3]; moves[2] = [6,6,6]; } else if(x == 127){ moves[0] = [4,4,4]; moves[2] = [5,5,5]; } for(var i in eNear){ var xDiff = eNear[i].x - x, yDiff = eNear[i].y - y; if(xDiff >= -1 && xDiff <= 1 && yDiff >= -1 && yDiff <= 1){ // If the enemy is directly adjacent, attack setMsg(''); return moves[yDiff + 1][xDiff + 1]; } } if(eNear.length > 0){ var xDiff = eNear[0].x - x, yDiff = eNear[0].y - y; // If it can't attack, move toward the enemy. if(Math.abs(yDiff) == 2){ if(xDiff >= -2 && xDiff <= 0) return 1; else if(xDiff == 2 || xDiff === 1) return 2; } return moves[getDir(yDiff) + 1][getDir(xDiff) + 1]; } var msg = getMsg(me) || '', newDir = parseInt(msg); if(msg === ''){ newDir = randInt(4) + 2; } var isEndgame = move > 512; if(x === 0 || (isEndgame && x < 11)) newDir = (msg == 4) ? 3 : 6; else if(x == 127 || (isEndgame && x > 116)) newDir = (msg == 3) ? 4 : 5; else if((!isEndgame && y < 11) || y === 0) newDir = (msg == 4) ? 5 : 6; else if((!isEndgame && y > 116) || y == 127) newDir = (msg == 5) ? 4 : 3; if(newDir != msg) setMsg(newDir.toString()); return newDir; My bot bounces from wall to wall (not exactly, so it covers different ground) looking for enemies. If it gets one in its range, it attacks, drags them toward a wall, and tries to take them out (think bouncer at a club).