Code viewer for Mind: Complex Mind (clone by Aoi...

// Cloned by Aoife Doherty on 14 Nov 2020 from Mind "Complex Mind (clone by Aoife Doherty)" by Aoife Doherty 
// Please leave this clone trail here.
 


// Cloned by Aoife Doherty on 4 Nov 2020 from Mind "Complex Mind" by Starter user 
// Please leave this clone trail here.
 



// =================================================================================================
// 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];

		// 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) );
 		
	};

/*         if ( occupied (ai-1,aj) && occupied (ai+1,aj) && occupied (ai,aj-1)) return (ACTION_DOWN);
		 if ( occupied (ai-1,aj) && occupied (ai+1,aj) && occupied (ai,aj+1)) return (ACTION_UP);
		 if ( occupied (ai,aj-1) && occupied (ai,aj+1) && occupied (ai-1,aj)) return (ACTION_RIGHT);
		 if ( occupied (ai,aj-1) && occupied (ai,aj+1) && occupied (ai+1,aj)) return (ACTION_LEFT);
		 if ( ai-1,aj == occupied && ai+1,aj == occupied && ai,aj-1 == occupied) return (ACTION_DOWN);
		 if ( ai-1,aj == occupied && ai+1,aj == occupied && ai,aj+1 == occupied) return (ACTION_UP);
		 if ( ai,aj-1 == occupied && ai,aj+1 == occupied && ai-1,aj == occupied) return (ACTION_RIGHT);
		 if ( ai,aj-1 == occupied && ai,aj+1 == occupied && ai+1,aj == occupied) return (ACTION_LEFT);

         if ( ej > aj && ei < ai) 	return (AB.randomPick(ACTION_UP, ACTION_RIGHT));
         if ( ej > aj && ei > ai) 	return (AB.randomPick(ACTION_UP, ACTION_LEFT));

         if ( ej > aj && ei == ai) 	return (AB.randomPick3(ACTION_RIGHT, ACTION_LEFT, ACTION_UP));
         if ( ei > ai && ej == aj) 	return (AB.randomPick3(ACTION_UP, ACTION_DOWN, ACTION_LEFT));

		 if ( ej < aj && ei < ai) 	return (AB.randomPick(ACTION_DOWN, ACTION_RIGHT));
		 if ( ej < aj && ei > ai) 	return (AB.randomPick(ACTION_DOWN, ACTION_LEFT));

		 if ( ej < aj && ei == ai) 	return (AB.randomPick3(ACTION_RIGHT, ACTION_LEFT, ACTION_DOWN));
		 if ( ei < ai && ej == aj) 	return (AB.randomPick3(ACTION_UP, ACTION_DOWN, ACTION_RIGHT));
		 
//		 want to count the moves by agent. if =0 might be stuck so try move anywhere??if (moveLogicalAgent(a) = 0) return (AB.randomPick(ACTION_LEFT, AB.randomPick3(ACTION_UP, ACTION_DOWN, ACTION_RIGHT)));

//		 if ( occupied (ai-1,aj) && occupied (ai+1,aj) && occupied (ai,aj+1)) return (ACTION_UP);
//		 if ( occupied (ai,aj-1) && occupied (ai,aj+1) && occupied (ai-1,aj)) return (ACTION_RIGHT);
//		 if ( occupied (ai,aj-1) && occupied (ai,aj+1) && occupied (ai+1,aj)) return (ACTION_LEFT);
		 

//		 if ( ei < ai ) 	return ( ACTION_RIGHT);
		 
//		 if ( ei > ai ) 	return ( ACTION_LEFT); 

// 		return  ( AB.randomIntAtoB (0,3) );
};
// !isOccupied)
/*function agentBlocked()                 // agent is blocked on all sides, run over
{
 return (       occupied (ai-1,aj)              && 
                occupied (ai+1,aj)              &&
                occupied (  ai,aj+1)            &&
                occupied (  ai,aj-1)    );              
} 
*/