Code viewer for Mind: New yo
 
function Mind() 
{ 
	
	this.newRun = function()                  
	{
	};


	this.getAction = function ( state )		 
	{ 
	  prev = [-100,-100];
	  var x = state[0];
	  var y = state[1];
	  var x1 = state[2];
	  var y1 = state[3];
	  
	  good = [x,y]; //x, y co-ords of good bot
	  bad = [x1,y1]; // x, y co-ords of bad bot
	  moves = function(){
    	  movez = [[0,0],[0,0],[0,0],[0,0]]; // calculating the sides of good, front, back, right, left
    	  if (1 != good[1]){
    	      movez[0] = [good[0],good[1]-1]; //!= 1 as theres only 3 sides in the 1 position on the grid
    	  }
    	  if (1 != good[0]){
    	      movez[1] = [good[0]-1,good[1]];
    	  }
    	  if (18 != good[1]){
    	      movez[2] = [good[0],good[1]+1]; //!=18 as theres only 3 sides in the 18 position on the grid 
    	  }
    	  if (18 != good[0]) {
    	      movez[3] = [good[0]+1,good[1]];
    	  }
	    return movez;
	  };
	  minimax = function(depth,d,ismaximising){
	      var moves = moves();
	      
    	  if (depth === 0) {
            return d;
    	  }
    	  
          if (isMaximisingPlayer) {
                var bestMove = -9999;
                for (var i = 0; i < moves.length; i++) {
                    distance = moves[i][0] - bad[0] + (moves[i][1] - bad[1]);
                    bestMove = Math.max(bestMove, minimax(depth - 1, distance, !isMaximisingPlayer));
            }
            console.log(bestMove);
            return bestMove;} 
        else {
            var bestMove2 = 9999;
            for (var j = 0; j < moves.length; j++) {
                distance = moves[j][0] - bad[0] + (moves[j][1] - bad[1]);
                bestMove2 = Math.min(bestMove2, minimax(depth - 1, distance, !isMaximisingPlayer));
            }
            console.log(bestMove2);
            return bestMove2;
        }
    };
    
    move = function(good,bad){
	    if (good.stuckfor < 2)
            return AB.randomIntAtoB(0, 3);
        if (AB.randomBoolean()) {
            if (good[0] < bad[0])
                return 1;
            if (good[1] < bad[1])
                return 2;
        }
        else{
            if (good[0] > bad[0])
                return 0;
        }
        return 3;
    };
	  best_move = best_move();
	  move = move(good,best_move);
	  console.log('mv',move);
	  if (prev[0] == best_move[0] & prev[1] == best_move[1]){
	      move = AB.randomIntAtoB(0,3);
	      prev = best_move;
	      console.log('prev',prev);
	  }
	  return move;
	};
}
    
	  

		 
	this.endRun = function()                 
	{
	};