function Mind()
{
var tmpei = 0;
var tmpej = 0;
var tmpai = 0;
var tmpaj = 0;
var last_action = 0;
var action = 0
var e_dis = 0
var b_l = true;
var b_r = true;
var b_u = true;
var b_d = true;
var disi = 0
var disj = 0
var nm = false
var c = 0;
var array = [];
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(ai == tmpai & aj == tmpaj){
nm = true
}
else{
nm = false
}
disi = (ej - aj);
if (disi < 0){
disi = disi * -1
}
disj = (ei - ai);
if (disj < 0){
disj = disj * -1
}
if (ai == 1 || (last_action == ACTION_LEFT & nm === true) ){console.log("bl false"); b_l = false;}
if (aj == 1 || (last_action == ACTION_DOWN & nm === true) ){ console.log("bd false"); b_d = false;}
if (aj == 18 || (last_action == ACTION_UP & nm === true) ){ console.log("bu false"); b_u = false;}
if (ai == 18 || (last_action == ACTION_RIGHT & nm === true) ){ console.log("br false"); b_r = false;}
if(c === 0){
if ( b_u === true ){action = ACTION_UP} else if( b_l === true ){action = ACTION_LEFT} else if(b_d === true){action = ACTION_DOWN} else if(b_r === true){action = ACTION_RIGHT}}
if(c === 1){
if ( b_r === true ){action = ACTION_RIGHT} else if( b_d === true ){action = ACTION_DOWN} else if(b_l === true){action = ACTION_LEFT} else if(b_u === true){action = ACTION_UP}}
if(c === 2){
if ( b_d === true ){action = ACTION_DOWN} else if( b_r === true ){action = ACTION_RIGHT} else if(b_u === true ){action = ACTION_UP} else if(b_l === true){action = ACTION_LEFT}}
if(c === 3){
if ( b_l === true ){action = ACTION_LEFT} else if( b_u === true ){action = ACTION_UP} else if(b_r === true){action = ACTION_RIGHT} else if(b_d === true){action = ACTION_DOWN}}
if (ei == tmpei & ej == tmpej & disi > 6 & disj > 6 ){
tmpei = ei; tmpej = ej; tmpai = ai; tmpaj = aj;
action = ACTION_STAYSTILL;}
/*
if ( ej < aj & b_u === true ){action = ACTION_UP} else if( b_r === true ){action = ACTION_RIGHT} else if(b_r === true){action = ACTION_RIGHT}
if ( ej > aj & b_d === true ){action = ACTION_DOWN} else if( b_r === true ){action = ACTION_RIGHT} else if(b_r === true){action = ACTION_RIGHT}
if ( ei < ai & b_r === true ){action = ACTION_RIGHT} else if( b_u === true ){action = ACTION_UP} else if(b_d === true){action = ACTION_DOWN}
if ( ei > ai & b_l === true ){action = ACTION_LEFT} else if( b_u === true ){action = ACTION_UP} else if(b_d === true){action = ACTION_DOWN} */
last_action = action;
console.log(ai, aj);
console.log(action);
console.log("c" +c);
if(aj > 14){c = 1; if(ai > 14){c = 2}}
if(aj < 5){c = 3; if( ai < 5 ){c = 0}}
tmpei = ei; tmpej = ej; tmpai = ai; tmpaj = aj;
if(nm === false){
b_l = true; b_r = true; b_u = true; b_d = true;}
return(action);
};
}