Code viewer for Mind: CA318 Assignment
 
function Mind() 
{ 
	
    this.newRun = function()                  
	{
	};


//	this.getAction = function ( pos )
	   // var a_x = pos[0]; //ally x coordinate
    //     var a_y = pos[1]; //ally y coordinate
    //     var e_x = pos[2]; //enemy x coordinate
    //     var e_y = pos[3]; //enemy y coordinate

    //     //current farthest distance
    //     var curr_far = 0;
    //     //current optimal direction
    //     var curr_opt_dir = ACTION_RIGHT;
        
    //     if (AB.distance2D((a_x + 1), a_y, e_x, e_y) > curr_far && a_x < 18) {
    //         curr_far = AB.distance2D((a_x + 1), a_y, e_x, e_y);
    //         curr_opt_dir = ACTION_RIGHT;
    //     }
        
    //     if (AB.distance2D((a_x - 1), a_y, e_x, e_y) > curr_far && a_x > 0) {
    //         curr_far = AB.distance2D((a_x - 1), a_y, e_x, e_y);
    //         curr_opt_dir = ACTION_LEFT;
    //     }
        
    //     if (AB.distance2D(a_x, (a_y + 1), e_x, e_y) > curr_far && a_y < 18) {
    //         curr_far = AB.distance2D(a_x, (a_y + 1), e_x, e_y);
    //         curr_opt_dir = ACTION_DOWN;
    //     }
        
    //     if (AB.distance2D(a_x, (a_y - 1), e_x, e_y) > curr_far && a_y > 0) {
    //         curr_far = AB.distance2D(a_x, (a_y - 1), e_x, e_y);
    //         curr_opt_dir = ACTION_UP;
    //     }
        
    //     var prev_pos = pos;
    //     console.log(pos);
    //     console.log("prev", prev_pos);
        
        
    //     return curr_opt_dir;
	
	this.getAction = function ( x )		 
	{ 
	  var allyx = x[0];
	  var allyy = x[1];
	  var enemyx = x[2];
	  var enemyy = x[3];	  
	  
	    if (( enemyx < allyx ) && (enemyy < allyy)) 	return ( AB.randomPick ( ACTION_RIGHT,	ACTION_UP ) 		); 
	    if (( enemyx < allyx ) && (enemyy > allyy)) 	return ( AB.randomPick ( ACTION_RIGHT,	ACTION_DOWN ) 		);
        if (( enemyx > allyx ) && (enemyy < allyy)) 	return ( AB.randomPick ( ACTION_LEFT,	ACTION_UP ) 		); 
        if (( enemyx > allyx ) && (enemyy > allyy)) 	return ( AB.randomPick ( ACTION_LEFT,	ACTION_DOWN ) 		); 


	  return ( AB.randomIntAtoB (0,3) );		 		
	};

		 
	this.endRun = function()                 
	{
	};

}