Code viewer for Mind: Complex Mind (clone by Thomas)

// Cloned by Thomas on 18 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];
		
		var a = null;
		var d1 = null, d;

		if(!occupied(ai+1, aj)) {
		    d = md([ai+1, aj], [ei, ej])
		    if(a == null || d1 < d) {
		        d1 = d; a = ACTION_RIGHT;
		    }
		}
		
		if(!occupied(ai-1, aj)) {
		    d = md([ai-1, aj], [ei, ej])
		    if(a == null || d1 < d) {
		        d1 = d; a = ACTION_LEFT;
		    }
		}
		
		if(!occupied(ai, aj+1)) {
		    d = md([ai, aj+1], [ei, ej])
		    if(a == null || d1 < d) {
		        d1 = d; a = ACTION_UP;
		    }
		}
		
		if(!occupied(ai, aj-1)) {
		    d = md([ai, aj], [ei, ej])
		    if(a == null || d1 < d) {
		        d1 = d; a = ACTION_DOWN;
		    }
		}
		
		return a==null ? 0 : a;
	};