Blue Team - Fetch [38953]
var me = 38953;
var msg = getMsg(me);
var register = msg ? JSON.parse(msg) : {};
var prevDanger = 0;
var danger;
var eScope = eNear;
var myX = x;
var myY = y;
var put = setMsg;
var get = getMsg;
function kill(){
var move = -1;
if(!eScope){return -1;}
eScope.forEach(function(e){
if(move > -1){return move;}
var xDist = Math.abs(e.x-myX);
var yDist = Math.abs(e.y-myY);
if(xDist < 2 && yDist < 2){
if(e.x == myX){
if(e.y == myY-1){move = 2;}
else if(e.y == myY+1){move = 1;}
}
else if(e.x == myX-1){
if(e.y == myY-1){move = 4;}
else if(e.y == myY+1){move = 5;}
}
else if(e.x == myX+1){
if(e.y == myY-1){move = 3;}
else if(e.y == myY+1){move = 6;}
}
}
});
return move;
}
function live(){
var move = -1;
if(!eScope){return -1;}
var topHalf = (myY <= 64);
eScope.forEach(function(e){
if(move > 0){return move;} //0 on purpose; we might find a better escape
var xDist = Math.abs(e.x-myX);
var yDist = Math.abs(e.y-myY);
if(xDist + yDist < 5){move = 0;} //uh oh! Stand still!
if(e.y == myY){
if(e.x == myX-1){move = (topHalf ? 5 : 4);}
else if(e.x == myX+1){move = (topHalf ? 6 : 3);}
}
});
return move;
}
function evalDanger(){
danger = 0;
if(register){prevDanger = register.d;}
eScope.forEach(function(e){
var xDist = Math.abs(e.x-myX);
var yDist = Math.abs(e.y-myY);
danger += ((1/yDist) * (1/xDist));
});
register.d = danger;
put(JSON.stringify(register));
return danger;
}
function distract(){
//run to the edge if safe, to the middle if not
var safe = (danger <= prevDanger && danger < .01);
var topHalf = myY <= 64;
var leftSide = myX <= 64;
//lazy init to 'explore' mode
if(!register.e){register.e = 1;}
//lazy init to whatever corner we're in
if(!register.f){
register.f = topHalf ? leftSide ? 4 : 3 : leftSide ? 5 : 6;
}
//turn 'explore' on (1) or off (2);
//if 'off' but hit 'home base', seek a corner
if(register.e == 2 && ((myY > 54 && myY < 74) || (myX > 54 && myX < 74))){
register.e = 1
register.f = Math.floor(Math.random()*4)+3;
}
//if on the outskirts, go back to base
if(myY < 10 || myY > 115 || myX < 10 || myX > 115){register.e = 2;}
put(JSON.stringify(register));
if(topHalf){
if(leftSide){
if(!safe || register.e == 2){register.why = "ChaseMe!"; return 6;}
}
else{
if(!safe || register.e == 2){register.why = "ChaseMe!"; return 5;}
}
}
else {
if(leftSide){
if(!safe || register.e == 2){register.why = "ChaseMe!"; return 3;}
}
else{
if(!safe || register.e == 2){register.why = "ChaseMe!"; return 4;}
}
}
register.why = (register.e == 2 ? "GoHome" : "Hunt!");
return register.f;
}
evalDanger();
register.x = myX;
register.y = myY;
var whee = kill();
if(whee > -1){
register.go = whee;
register.why = "KILL!";
setMsg(JSON.stringify(register));
return whee;
}
whee = live();
if(whee > -1){
register.go = whee;
register.why = "FLEE!";
setMsg(JSON.stringify(register));
return whee;
}
whee = distract();
register.go = whee;
setMsg(JSON.stringify(register));
return whee;
[edits: turns out it works a LOT better when I use my actual id and not -1!]
A dumb little bot that runs around the board, doing his best to attract attention and draw chasers, and then run to the middle where (hopefully) he'll find somebody to help him, or he'll just stall the chaser and stop him from hunting.
Doesn't seem to make a huge impact on overall score due to how powerful the Blue tagteam are, but at the very least I didn't make things worse!
Shout in the next 8 hours if you want me to add anything useful to my message.