Code viewer for Mind: Run Donald Run
// =================================================================================================
// Sample Mind for more complex starter World  
// =================================================================================================

// World tells us agent position and enemy position
// World does not tell us of existence of walls
// if return invalid move (not empty square) World just ignores it and we miss a turn 


 

	AB.mind.getAction = function ( x )		// x is an array of [ ai, aj, ei, ej ]
	{ 
         
		var ai = x[0];
		var aj = x[1];
		var ei = x[2];
		var ej = x[3];
		
		// Anish Kumar. Adding some logic here to make agent slightly smarter to counteract A* enemy.
        i = ai;
        j = aj;
        
        if ( ai < ei ) i = AB.randomIntAtoB(ai-1, ai);
         if ( ei == ai ) i = AB.randomIntAtoB(ai-1, ai+1);
         if ( ai > ei ) i = AB.randomIntAtoB(ai, ai+1);
        
         if ( aj < ej ) j = AB.randomIntAtoB(aj-1, aj);
         
         if ( ej == aj ) j = AB.randomIntAtoB(aj-1, aj+1); 
         if ( aj > ej ) j = AB.randomIntAtoB(aj, aj+1); 
         
         a = [i,j];
         return(a);
        
		// if strictly move away, will get stuck at wall, so introduce randomness 
        /*
		 if ( ej < aj ) 	return ( AB.randomPick ( ACTION_UP,		AB.randomPick(ACTION_RIGHT,ACTION_LEFT) 	)); 
		 if ( ej > aj ) 	return ( AB.randomPick ( ACTION_DOWN,	AB.randomPick(ACTION_RIGHT,ACTION_LEFT) 	)); 
         
		 if ( ei < ai ) 	return ( AB.randomPick ( ACTION_RIGHT,	AB.randomPick(ACTION_UP,ACTION_DOWN) 		)); 
		 if ( ei > ai ) 	return ( AB.randomPick ( ACTION_LEFT,	AB.randomPick(ACTION_UP,ACTION_DOWN) 		)); 
        
 		return  ( AB.randomIntAtoB (0,3) );
 		*/
	};