// Cloned by barkerr2 on 17 Nov 2018 from Mind "Chaser Mind" by Kevin O'Neill
// Please leave this clone trail here.
// =================================================================================================
// Sample Mind for more complex starter WWM World
// =================================================================================================
// World tells us agent position and enemy position
// World does not tell us of existence of walls
// if return invalid move (not empty square) World just ignores it and we miss a turn
function randomPick ( a, b )
{
if ( randomBoolean() )
return a;
else
return b;
}
function Mind() {
//--- public functions / interface / API ----------------------------------------------------------
this.newRun = function()
{
};
this.endRun = function()
{
};
this.getAction = function ( x ) // x is an array of [ ai, aj, ei, ej ]
{
var ai = x[0];
var aj = x[1];
var ei = x[2];
var ej = x[3];
// if strictly move away, will get stuck at wall, so introduce randomness
if ( ej < aj ) return ( randomPick ( ACTION_UP, randomPick(ACTION_RIGHT,ACTION_LEFT) ));
if ( ej > aj ) return ( randomPick ( ACTION_DOWN, randomPick(ACTION_RIGHT,ACTION_LEFT) ));
if ( ei < ai ) return ( randomPick ( ACTION_RIGHT, randomPick(ACTION_UP,ACTION_DOWN) ));
if ( ei > ai ) return ( randomPick ( ACTION_LEFT, randomPick(ACTION_UP,ACTION_DOWN) ));
return ( randomintAtoB (0,3) );
};
this.returnClosest = function ( x )
{
var ai = x[0];
var aj = x[1];
var ei = x[2];
var ej = x[3];
var ci = x[4];
var cj = x[5];
var di = x[6];
var dj = x[7];
var gi = x[8];
var gj = x[9];
var fi = x[10];
var fj = x[11];
var closi = ai;
var closj = aj;
var distance = Math.sqrt( (ei-ai)*(ei-ai) + (ej-aj)*(ej-aj));
if(distance > Math.sqrt( (ei-ci)*(ei-ci) + (ej-cj)*(ej-cj)))
{
distance = Math.sqrt( (ei-ci)*(ei-ci) + (ej-cj)*(ej-cj))
closi = ci;
closj = cj;
}
if(distance > Math.sqrt( (ei-di)*(ei-di) + (ej-dj)*(ej-dj)))
{
distance = Math.sqrt( (ei-di)*(ei-di) + (ej-dj)*(ej-dj))
closi = di;
closj = dj;
}
if(distance > Math.sqrt( (ei-gi)*(ei-gi) + (ej-gj)*(ej-gj)))
{
distance = Math.sqrt( (ei-gi)*(ei-gi) + (ej-gj)*(ej-gj))
closi = gi;
closj = gj;
}
if(distance > Math.sqrt( (ei-gi)*(ei-gi) + (ej-gj)*(ej-gj)))
{
distance = Math.sqrt( (ei-fi)*(ei-fi) + (ej-fj)*(ej-fj))
closi = fi;
closj = fj;
}
console.log(closi + " " + closj)
}
}