Code viewer for Mind: JMind
 
function Mind() 
{ 
    prev = [-1, -1];
    nextMove = -1
	function getBestMove(options, enemy) {
	    best = 0;
	    bestMove = [-1, -1];
	    console.log("OPTIONS", options)
	    for(i = 0; i < options.length; i++){
	        distance = (options[i][0] - enemy[0]) + (options[i][1] - enemy[1]);
	        if (distance < 0) {
	            distance = distance * -1;
	        }
	        console.log(distance);
	        if (distance > best){
	            best = distance;
	            bestMove[0] = options[i][0];
	            bestMove[1] = options[i][1];
	        }
	    }
	    console.log("Best Move: ", bestMove);
	    return bestMove;
	}
	
	function getOptions(me){
	           //  up      down    left    right
	    options = [[0, 0], [0, 0], [0, 0], [0, 0]]
	    
	    // Check if not against top wall (Can move up)
	    if (me[1] != 1) {
	       options[0] = [me[0], me[1] - 1]    
	    }
	    // Can move down
	    if(me[1] != 18) {
	       options[1] = [me[0], me[1] + 1]    
	    }
	    // Can move left
	    if(me[0] != 1) {
	        options[2] = [me[0] - 1, me[1]]
	    }
	    if (me[0] != 18){
	        options[3] = [me[0] + 1, me[1]]
	    }
	    console.log(options);
	    return(options);
	}
	
    function makeMove(me, bestMove){
        if (bestMove[0] > me[0]){
            return 1;
        } else if (bestMove[0] < me[0]) {
            return 0;
        } else if (bestMove[1] > me[1]) {
            return 2;
        } else {
            return 3;
        }
    }
	
	this.newRun = function() {
	};
	
	this.getAction = function ( state )		 
	{ 
	    me = [state[0], state[1]];
	    enemy = [state[2], state[3]];
	    ops = getOptions(me);
	    
	    bm = getBestMove(options, enemy);
	    move = makeMove(me, bm);
	    if (prev[0] == bm[0] && prev[1] == bm[1]) {
	        move = AB.randomIntAtoB(0, 3);
	    }

        prev = bm;
        console.log(move);
	    return(move);
	};

		 
	this.endRun = function()                 
	{
	};

}