Code viewer for Mind: Happy Haircut
 
function Mind() 
{
    var i = 0;
    var ini = 0;
    var pos;
    var playerX;
    var playerY;
    var enemyX;
    var enemyY;
	var lll = [];
	var moves = [ACTION_UP,ACTION_DOWN,ACTION_LEFT,ACTION_RIGHT];
	this.newRun = function()                  
	{
	    // SET 2D ARRAY
	    row = []
	    for(var i = 0; i < 18; i++){
	        for(var j = 0; j < 18; j++){
	            row.push(0)
	        }
	        lll.push(row);
	        row = []
	    }
	    
	};


	this.getAction = function ( state )		 
	{ 
	   // SET VISITED TO 1
	    if((state[0] - 1) > -1 && (state[1] - 1) > -1){
            lll[state[0] - 1][state[1] - 1] = 1;
	    }
	   // SET CHASER to 5
	    if((state[2] - 1) > -1 && (state[3] - 1) > -1){
            lll[state[2] - 1][state[3] - 1] = 5;
	    }
	    var dist = AB.distance2D(enemyX, enemyY, playerX, playerY);
	    console.log(lll);
	    // SET X AND Y FOR PLAYER AND ENEMY DURING FIRST FRAME
	    if(ini === 0){
	        enemyX = state[2] ;
	        enemyY = state[3] ;
	        playerX = state[0];
	        playerY = state[1];
	        ini = 1
	    }else{
	        //STAY STILL WHEN CHASER IS STILL AND DISTANCE > 7
	        if(enemyX == state[2] && enemyY == state[3] && dist > 7){
	            return ACTION_STAYSTILL
	        }
            if(playerX == state[0] && playerY == state[1]){
                try{
                    if(i === 0){
                        if((playerY) < 18){
                            lll[playerX - 1][playerY] = 4
                        }
                    }else if(i === 1){
                        if((playerY - 2) > -1){
                            lll[playerX - 1][playerY - 2] = 4
                        }
                    }else if(i === 2){
                        if((playerX - 2) > -1){
                            lll[playerX - 2][playerY - 1] = 4
                        }
                    }else if(i === 3){
                        if((playerX) < 18){
                            lll[playerX][playerY - 1] = 4
                        }
                    }
                }catch(e){}
                var max = 0
                var prevs = []
                prevs.push(i)
                n = Math.floor(Math.random() * 4)
                while(i == n){
                    n = Math.floor(Math.random() * 4)
                    // var new_dist;
                    // // ** IDEA ** TRY TO ALWAYS GET FURTHER 
                    // if(n not in )
                    // if(i == 0){
                    //     new_dist = AB.distance2D(enemyX, enemyY, playerX, playerY + 1);
                    //     if(dist < new_dist){
                    //         max ++;
                    //         n == i
                    //     }
                    // }else if(i == 1){
                    //     new_dist = AB.distance2D(enemyX, enemyY, playerX, playerY - 1)
                    //     if(dist < new_dist){
                    //         max ++;
                    //         n == i
                    //     }
                    // }else if(i == 2){
                    //     new_dist = AB.distance2D(enemyX, enemyY, playerX - 1, playerY)
                    //     if(dist < new_dist){
                    //         max ++;
                    //         n == i
                    //     }
                    // }else if(i == 3){
                    //     new_dist = AB.distance2D(enemyX, enemyY, playerX + 1, playerY)
                    //     if(dist < new_dist){
                    //         max ++;
                    //         n == i
                    //     }
                    // }
                     
                    // ** IDEA ** CHECKING IF I CAN GET STUCK
                    //  if(i == 0){
                    //     if((playerY) < 18){
                    //         lll[playerX - 1][playerY] = 4
                    //     }
                    // }else if(i == 1){
                    //     if((playerY - 2) > -1){
                    //         lll[playerX - 1][playerY - 2] = 4
                    //     }
                    // }else if(i == 2){
                    //     if((playerX - 2) > -1){
                    //         lll[playerX - 2][playerY - 1] = 4
                    //     }
                    // }else if(i == 3){
                    //     if((playerX) < 18){
                    //         lll[playerX][playerY - 1] = 4
                    //     }
                    // }
                }
                i = n
            }
	    }
	    
	    // SET VISITED BY CHASER to 1
	    if((state[2] - 1) > -1 && (state[3] - 1) > -1){
            lll[state[2] - 1][state[3] - 1] = 1;
	    }
	    
	    // UPDATE X AND Y FOR PLAYER AND ENEMY
	    enemyX = state[2];
	    enemyY = state[3];
	    playerX = state[0]
	    playerY = state[1]
	    
	    return (moves[i]);		 		
	};
	
// 	this.getSurrounded = function(pos){
// 	    var total;
// 	    var positions = [[0,1][1,0][][]]
// 	}
		 
	this.endRun = function()                 
	{
	    console.log(lll)
	};

}