Code viewer for Mind: Catch Me If You Can
function Mind() { 
        function getBest(moves, enemy) {
            maxi = 0;
            best = [-1, -1];
            for(i = 0; i < moves.length; i++){
                md = (moves[i][0] - enemy[0]) + (moves[i][1] - enemy[1]);
                if (md < 0) {
                    md = md * -1;
                }

                if (md > maxi){
                    maxi = md;
                    best[0] = moves[i][0];
                    best[1] = moves[i][1];
                }
            }
            return best;
        }
        function getMoves(agent){
            moves = [[0, 0], [0, 0], [0, 0], [0, 0]]
            if (agent[1] != 1) {
                moves[0] = [agent[0], agent[1] - 1]    
            }
            if(agent[1] != 18) {
           moves[1] = [agent[0], agent[1] + 1]    
            }
            if(agent[0] != 1) {
                moves[2] = [agent[0] - 1, agent[1]]
            }
            if (agent[0] != 18){
                moves[3] = [agent[0] + 1, agent[1]]
            }
            return(moves);
        }
        function makeMove(agent, best){
            if (best[0] > agent[0]){
                return 1;
            } else if (best[0] < agent[0]) {
                return 0;
            } else if (best[1] > agent[1]) {
                return 2;
            } else {
                return 3;
            }
        }
        this.newRun = function() {
        };
        this.getAction = function ( state ) { 
            previousMove = -1;
            agent = [state[0], state[1]];
            enemy = [state[2], state[3]];
            moves = getMoves(agent);
            best = getBest(moves, enemy);
            currentMove = makeMove(agent, best);
            if (previousMove === currentMove) {
                currentMove = AB.randomIntAtoB(0, 3);
            }
            previousMove = currentMove;
            return(currentMove);
        };
        this.endRun = function() {
        };
}