#Blue Team - SphiNotPi3000
// Char 0: top or bottom ("T" or "B")
// Char 1, 2: x/y coords
// Char 3, move polarity
// Char 4: offset (as codepoint - 128)
var myself = 21487;
var twin = 2867;
var formpos = "B";
var tochar = String.fromCharCode;
var movestat = (move % 2).toString();
var inbox = getMsg(twin);
// Spoofing the message of a deceased partner
if (inbox == "X"){
inbox = "B" + tochar(x) + tochar(y+1) + ((move + 1) % 2).toString() + tochar(0);
}
var selfsafe = [9,10,10,10,10,10,10];
// Remove useless edge moves
if (x == 0){
selfsafe[4] = 0;
selfsafe[5] = 0;
}
if (x == 127){
selfsafe[3] = 0;
selfsafe[6] = 0;
}
if (y == 0){
selfsafe[2] = 0;
selfsafe[3] = 0;
selfsafe[4] = 0;
}
if (y == 127){
selfsafe[1] = 0;
selfsafe[6] = 0;
selfsafe[5] = 0;
}
var selfdisp = [[0,0],[0,1],[0,-1],[1,-1],[-1,-1],[-1,1],[1,1]];
if (inbox == "") {
// First move, pick anywhere safe
for (j = 0; j < 7; j++) {
for (var i = 0; i < eNear.length; i++){
var enemy = eNear[i];
var dx = enemy.x - x - selfdisp[j][0];
var dy = enemy.y - y - selfdisp[j][1];
if (dx * dx == 1 && dy >= -1 && dy <= 1) {
selfsafe[j] = 0;
}
}
if (selfsafe[j]) {
var strpos = tochar(x + selfdisp[j][0]) + tochar(y + selfdisp[j][0]);
var offset = tochar(Math.floor(Math.random() * 256));
setMsg(formpos + strpos + movestat + offset);
return j;
}
}
} else {
var twinformpos = inbox.charAt(0);
var twinx = inbox.charAt(1).charCodeAt();
var twiny = inbox.charAt(2).charCodeAt();
var twinmovestat = inbox.charAt(3);
var offset = inbox.charAt(4);
formpos = twinformpos == "T" ? "B" : "T";
var targetx = twinx;
var targety = formpos == "T" ? (twiny - 1) : (twiny + 1);
// If true, then this bot is either the second one to move or is not in position. Move into position.
if (twinmovestat == movestat || x != targetx || y != targety) {
if (getMsg(twin) == "X") {
for (var j = 0; j < 7; j++) {
for (var i = 0; i < eNear.length; i++){
var enemy = eNear[i];
var dx = enemy.x - x - selfdisp[j][0];
var dy = enemy.y - y - selfdisp[j][1];
if (dx == 0 && dy == 0){
var strpos = tochar(x + selfdisp[j][0]) + tochar(y + selfdisp[j][1]);
setMsg(formpos + strpos + movestat + offset);
return j;
}
}
}
}
var bestmove = 0;
for (var j = 0; j < 7; j++) {
for (var i = 0; i < eNear.length; i++){
var enemy = eNear[i];
var dx = enemy.x - x - selfdisp[j][0];
var dy = enemy.y - y - selfdisp[j][1];
if (dx * dx == 1 && dy >= -1 && dy <= 1) {
selfsafe[j] = 0;
}
if (dx == 0 && dy == 0){
selfsafe[j] *= 2;
}
}
selfsafe[j] -= Math.abs(x + selfdisp[j][0] - targetx) + Math.abs(y + selfdisp[j][1] - targety);
if (selfsafe[j] > selfsafe[bestmove]) {
bestmove = j;
}
}
var strpos = tochar(x + selfdisp[bestmove][0]) + tochar(y + selfdisp[bestmove][1]);
setMsg(formpos + strpos + movestat + offset);
return bestmove;
} else {
// In formation, and is the leader this turn
var topy = formpos == "T" ? y : (y - 1);
var topx = x;
var safe = [1,1,1,1,1,1,1,1,1];
var disp = [[0,0],[0,1],[0,-1],[1,-1],[-1,-1],[-1,1],[1,1],[1,0],[-1,0]];
var otherpos = formpos == "T" ? "B" : "T";
// Avoid dangerous squares and always kill if safe to do so
for (var j = 0; j < 9; j++){
var ntopx = topx + disp[j][0];
var ntopy = topy + disp[j][1];
if (ntopx < 0 || ntopx > 127 || ntopy < 0 || ntopy > 126){
safe[j] = 0;
continue;
}
for (var i = 0; i < eNear.length; i++){
var enemy = eNear[i];
var dx = enemy.x - ntopx;
var dy = enemy.y - ntopy;
if(dx * dx == 1 && dy >= -1 && dy <= 2){
safe[j] = 0;
continue;
}
if(dx == 0 && dy >= 0 && dy <= 1){
// Kill!
var strpos = tochar(x + disp[j][0]) + tochar(y + disp[j][1]);
if (j > 6) {
setMsg(otherpos + strpos + movestat + offset);
if (formpos == "T"){return 13 - j;}
return j - 4;
}
setMsg(formpos + strpos + movestat + offset);
return j;
}
}
}
var pref = [];
for (var i = 0; i < eNear.length; i++){
var enemy = eNear[i];
var dy = enemy.y - topy;
var dx = enemy.x - topx;
if (dy < 0 && dx == 0){ pref=[2,4,3,8,7,1,5,6,0]; }
if (dy > 0 && dx == 0){ pref=[1,5,6,7,8,2,4,3,0]; }
if (dy == 0 && dx > 0){ pref=[7,6,3,1,2,5,4,8,0]; }
if (dy == 0 && dx < 0){ pref=[8,5,4,1,2,6,3,7,0]; }
if (dy < 0 && dx < 0){ pref=[4,8,5,1,0,2,6,7,3]; }
if (dy > 0 && dx < 0){ pref=[5,8,4,2,0,1,3,7,6]; }
if (dy < 0 && dx > 0){ pref=[3,7,6,1,0,2,5,8,4]; }
if (dy > 0 && dx > 0){ pref=[6,7,3,2,0,1,4,8,5]; }
for (var k = 0; k < pref.length; k++)
{
if (safe[pref[k]]){
var strpos = tochar(x + disp[pref[k]][0]) + tochar(y + disp[pref[k]][1]);
if (pref[k] > 6) {
setMsg(otherpos + strpos + movestat + offset);
if(formpos == "T"){return 13 - pref[k];}
return pref[k] - 4;
}
setMsg(formpos + strpos + movestat + offset);
return pref[k];
}
}
}
var offsetint = offset.charCodeAt();
var offsetmove = move - 128 + offsetint;
if (offsetmove % 900 < 30) {
var targetx = 64 - (offsetmove % 30);
var targety = 64 - (offsetmove % 30);
} else if (offsetmove % 900 < 90) {
var targetx = 34 + ((offsetmove - 30) % 60);
var targety = 34;
} else if (offsetmove % 900 < 150) {
var targetx = 94;
var targety = 34 + ((offsetmove - 30) % 60);
} else if (offsetmove % 900 < 210) {
var targetx = 94 - ((offsetmove - 30) % 60);
var targety = 94;
} else if (offsetmove % 900 < 270) {
var targetx = 34;
var targety = 94 - ((offsetmove - 30) % 60);
} else if (offsetmove % 900 < 300) {
var targetx = 34 + (offsetmove % 30);
var targety = 34 + (offsetmove % 30);
} else if (offsetmove % 900 < 360) {
var targetx = 64 + (offsetmove % 60);
var targety = 64 - (offsetmove % 60);
} else if (offsetmove % 900 < 480) {
var targetx = 124;
var targety = 4 + (offsetmove % 120);
} else if (offsetmove % 900 < 600) {
var targetx = 124 - (offsetmove % 120);
var targety = 124;
} else if (offsetmove % 900 < 720) {
var targetx = 4;
var targety = 124 - (offsetmove % 120);
} else if (offsetmove % 900 < 840) {
var targetx = 4 + (offsetmove % 120);
var targety = 4;
} else {
var targetx = 124 - (offsetmove % 60);
var targety = 4 + (offsetmove % 60);
}
if (offsetint % 4 == 1) {
var temp = targetx;
var targetx = 127 - targety;
var targety = temp;
} else if (offsetint % 4 == 2) {
var targetx = 127 - targetx;
var targety = 127 - targety;
} else if (offsetint % 4 == 3) {
var temp = targetx;
var targetx = targety;
var targety = 127 - temp;
}
if ((offsetint >> 3) % 2) {
var targetx = 127 - targetx;
}
var bestmove = 0;
for (var j = 0; j < 9; j++) {
safe[j] -= Math.abs(topx + disp[j][0] - targetx) + Math.abs(topy + disp[j][1] - targety);
if (safe[j] > safe[bestmove]) {
bestmove = j;
}
}
var strpos = tochar(x + disp[bestmove][0]) + tochar(y + disp[bestmove][1]);
if (bestmove > 6) {
setMsg(otherpos + strpos + movestat + offset);
if (formpos == "T"){return 13 - bestmove;}
return bestmove - 4;
}
setMsg(formpos + strpos + movestat + offset);
return bestmove;
}
}
This bot forms a pair with PhiNotPi's bot. See Phi's post for a brief explanation of our strategy.