// Cloned by Jordan Cagney on 19 Nov 2018 from Mind "New Mind" by Jordan Cagney
// Please leave this clone trail here.
function Mind()
{
this.newRun = function()
{
const ACTION_LEFT = 0;
const ACTION_RIGHT = 1;
const ACTION_UP = 2;
const ACTION_DOWN = 3;
const ACTION_STAYSTILL = 4
};
this.getAction = function ( state )
{
function getManDist(ai,ei,aj,ej) {
return Math.abs(ei-ai) + Math.abs(ej-ei);
}
var manDist = getManDist(state[0], state[2],state[1],state[3]);
if ( getManDist(state[0]+ 1,state[2],state[1],state[3]) >= manDist) {
if (state[0] < 18 )
return ACTION_RIGHT;
return AB.randomPick(ACTION_LEFT, AB.randomPick(ACTION_UP,ACTION_DOWN))
}
if ( getManDist(state[0],state[2] + 1,state[1],state[3]) >= manDist) {
if (state[1] < 18 )
return ACTION_DOWN;
return AB.randomPick(ACTION_UP,AB.randomPick(ACTION_LEFT,ACTION_RIGHT))
}
if ( getManDist(state[0]- 1,state[2],state[1],state[3]) >= manDist) {
if (state[0] > 0 )
return ACTION_LEFT;
return AB.randomPick(ACTION_RIGHT,AB.randomPick(ACTION_UP,ACTION_DOWN))
}
if ( getManDist(state[0],state[2] - 1,state[1],state[3]) >= manDist) {
if (state[1] > 0 )
return ACTION_UP;
return AB.randomPick(ACTION_DOWN,AB.randomPick(ACTION_LEFT,ACTION_RIGHT))
}
};
this.endRun = function()
{
};
}