Code viewer for Mind: New Mind (clone by Sagnik ...

// Cloned by Sagnik Chakraborty on 19 Oct 2022 from Mind "New Mind" by Sian 
// Please leave this clone trail here.
 
 
function Mind() 
{ 
	
	this.newRun = function()                  
	{
	};


	this.getAction = function ( x )		 
	{ 
	    var ai = x[0];
		var aj = x[1];
		var ei = x[2];
		var ej = x[3];
		var side = 0;
		var sides = [];
        var startDistance = distance(ai, aj, ei, ej);
        var rightWay;
        var possible =[];
        var distances=[];
        var ways = [];
        var badway;
        if(ai>1 && ei!==ai-1){
            
            possible.push(0);
            distances.push((distance(ai-1, aj, ei, ej)));
        }
        if(ai<=17 && ei!==ai+1){
            
            possible.push(1);
            distances.push((distance(ai+1, aj, ei, ej)));
        }
        if(aj<=17 && ej!==aj+1){
            
            possible.push(2);
            distances.push((distance(ai, aj+1, ei, ej)));
        }
        if(aj>1 && ej!==aj-1){
            
            possible.push(3);
            distances.push((distance(ai, aj-1, ei, ej)));
        }
        var longestdistance=distances[0];
        while(side < distances.length){
            
                    if(distances[side]>longestdistance){
                        
                        longestdistance = distances[side];
                        rightWay = possible[side];
                    }
                    ways.push(possible[side]);
        
            side=side+1;
            }
            var random = Math.floor((Math.random() * 10));
            if(random<5 && ways.length > 0){
            
            return(ways[Math.floor((Math.random() * ways.length))]);
            }
            else{
                return rightWay;
            }
        };

	
	this.endRun = function()                 
	{
	};

}

	function distance(ai, aj, ei, ej){
	    var i = ai-ei;
	    var j = aj-ej;
	    return(Math.sqrt(i*i + j*j));
	}