Code viewer for Mind: New Good Guy Mind
 
function in_corner(ax, ay, ex, ey){
    if (ax < 3 && ay < 3) return AB.randomPick(ACTION_UP, ACTION_RIGHT);
	else if (ax < 3 && ay > 15) return AB.randomPick(ACTION_DOWN, ACTION_RIGHT);
	else if (ax > 15 && ay < 3) return AB.randomPick(ACTION_UP, ACTION_LEFT);
	else if (ax > 15 && ay > 15) return AB.randomPick(ACTION_DOWN, ACTION_LEFT);
	else return false;
}

function Mind() 
{
	
	this.newRun = function()                  
	{
	};


	this.getAction = function ( state )		 
	{
	    var ax = state[0];
	    var ay = state[1];
	    var ex = state[2];
	    var ey = state[3];
	    var x_diff = ax - ex;
	    var y_diff = ay - ey;
	    var distance = Math.abs(x_diff) + Math.abs(y_diff);
	    
	    if (Math.random() < 0.20) return AB.randomElementOfArray([ACTION_LEFT, ACTION_DOWN, ACTION_RIGHT, ACTION_UP]);
	    
	    else if (in_corner(ax, ay, ex, ey)) return in_corner(ax, ay, ex, ey);
	    
	    else if (distance < 10){
	        if(ax < ex){
	            if (ay < ey) return AB.randomPick(ACTION_LEFT, ACTION_DOWN);
	            else if (ay > ey) return AB.randomPick(ACTION_LEFT, ACTION_UP);
	            else return AB.randomElementOfArray([ACTION_LEFT, ACTION_DOWN, ACTION_UP]);
	        }
	        
	        else if (ax > ex){
	            if (ay < ey) return AB.randomPick(ACTION_RIGHT, ACTION_DOWN); 
	            else if (ay > ey) return AB.randomPick(ACTION_RIGHT, ACTION_UP);
	            else return AB.randomElementOfArray([ACTION_DOWN, ACTION_RIGHT, ACTION_UP]);
	        }
	        
	        else {
	            if (ay < ey) return AB.randomElementOfArray([ACTION_LEFT, ACTION_RIGHT, ACTION_DOWN]); 
	            else return AB.randomElementOfArray([ACTION_LEFT, ACTION_RIGHT, ACTION_UP]);
	        }
	    }
	    
	    else return AB.randomElementOfArray([ACTION_LEFT, ACTION_DOWN, ACTION_RIGHT, ACTION_UP]);
	};

		 
	this.endRun = function()                 
	{
	};

}