Code viewer for Mind: New Mind
 
function Mind() 
{   var distance
    var choice
    var counter = 1;
	var moves = [ACTION_UP,ACTION_DOWN,ACTION_RIGHT,ACTION_LEFT];
	var prevIndex
	this.newRun = function()                  
	{
        console.log("Game Start!")
	};


	this.getAction = function ( state )		 
	{   //get distance between enemy and player
	    distance = AB.distance2D(state[0],state[1],state[2],state[3])
        
        var index = Math.floor(Math.random()*3)
        
        if(distance <= 5){
            if(prevIndex == index){
                if(index == 3){
                    index = 0
                }else{
                    index ++
                }
            }
            choice = moves[index]
            prevIndex = index
        }
        return (choice)
	  }
	  

		 
	this.endRun = function()                 
	{
	    console.log("Game ended!")
	};


}