Code viewer for Mind: P5 chase Mind

See raw JS.




// =================================================================================================
// Sample Mind for P5 plain World  
// =================================================================================================
 

// no need to pass state as argument 
// since the info we need are global variables anyway 



	AB.mind.getAction = function()		 
	{ 
			// move object towards target  
			
			if ( AB.randomBoolean() )				// randomly choose to track target x or y each step 
			{
				if ( x < tx ) 	return ACTION_RIGHT;
				else  			return ACTION_LEFT;	  
			}
			else 
			{
				if ( y < ty ) 	return ACTION_DOWN;
				else 			return ACTION_UP;	  
			}
	};