Code viewer for Mind:
CA318
var enemyX;
var enemyY;
var lastpos_turn = [-1,-1,-1,-1];
var forbidden = [];
function Mind()
{
var myX;
var myY;
this.newRun = function()
{
};
this.getAction = function ( x )
{
myX = x[0];
myY = x[1];
if(myX == lastpos_turn[0] && myY == lastpos_turn[1]){
forbidden.push([lastpos_turn[2],lastpos_turn[3]])
}
enemyX = x[2];
enemyY = x[3];
possible = newMoves(myX,myY);
for(var index in possible){
if(in_multi_dimenstion_array(possible[index], forbidden)){
console.log("oooh thats forbidden");
possible[index] = [enemyX, enemyY, -1]
}
}
possible = possible.sort(compare_moves);
console.log("" + possible)
bestTurn = possible[possible.length - 1]
lastpos_turn = [myX,myY, bestTurn[0], bestTurn[1]];
//console.log(bestTurn);
return(bestTurn[2]);
}
this.endRun = function()
{
};
}
function newMoves(x,y){
var possiblemoves = []
possiblemoves.push([x-1,y,0]);
possiblemoves.push([x+1,y,1]);
possiblemoves.push([x,y+1,2]);
possiblemoves.push([x,y-1,3]);
//possiblemoves = filter_forbidden(possiblemoves);
return possiblemoves;
}
function value(coords, eX, eY){
var val = Math.pow((coords[0] - eX), 2) + Math.pow((coords[1] - eY), 2);
val = Math.sqrt(val);
return val;
}
function compare_moves(move1, move2){
move1_v = value(move1, enemyX, enemyY);
move2_v = value(move2, enemyX,enemyY);
if (move1_v < move2_v){
return -1;
}
else if(move1_v == move2_v){
return 0;
}
else{
return 1;
}
}
function filter_forbidden(arr){
}
function in_multi_dimenstion_array(small, big){
for(var item in big){
if(big[item][0] == small[0] && big[item][1] == small[1]){
return true;
}
}
return false;
}