Code viewer for Mind: flyYouFool
var pos = [-1, -1];
var num = 0;

function Mind() 
{ 


	this.getAction = function ( x )		// x is an array of [ ai, aj, ei, ej ]
	{

	    
		var ai = x[0]; //ally x position
		var aj = x[1]; //ally y position
		var ei = x[2]; //enemy x position
		var ej = x[3]; //enemy y position
		
		var random1=false;
		
		if (pos[0]==ai && pos[1]==aj) num++
		else {
		    pos[0]=ai;
		    pos[1]=aj;
		}
		if (num==3){
		    num=0;
		    return Math.floor(Math.random() * Math.floor(4));
		}

		if(Math.abs(ai-ei) < Math.abs(aj-ej) || random1){
		    if(ei>=ai && ai!=1) return 0
		    else if(ei<=ai && ai!=18) return 1
		    else {
		        if(ej>=aj && aj!=1) return 3
		        else return 2
		    }
		} else {
		    if(ej>=aj && aj!=1) return 3
		    else if(ej<=aj && aj!=18) return 2
		    else {
		        if(ei>=ai && ai!=1) return 0
		        else return 1
		    }
		}
	};
}