Code viewer for Mind: Random movements for agent...

// Cloned by Philip on 24 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 


var openSet = [];
var closedSet = [];
var map = null;
var targetSpot = null;
var result = null;
var drawSpotFunction = null;
var world = null;

	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];
        result = new Entities();

        result.enemy.action = getEnemyAction();
        result.agent.action = getAgentAction(result.enemy.action);

        return result;
	};

//Move randomly towards
function getEnemyAction(){
    	 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) );
}

//move randomly away from enemies new spot
function getAgentAction(enemyAction){
    var newi;
    var newj;
    if(enemyAction == ACTION_UP) newj = ej-1;
    if(enemyAction == ACTION_DOWN) newj = ej+1;
    if(enemyAction == ACTION_LEFT) newi = ei-1;
    if(enemyAction == ACTION_RIGHT) newi = ei+1;
    
        if ( aj > newj ) 	return ( AB.randomPick ( ACTION_UP,		AB.randomPick(ACTION_RIGHT,ACTION_LEFT) 	)); 
		if ( aj < newj ) 	return ( AB.randomPick ( ACTION_DOWN,	AB.randomPick(ACTION_RIGHT,ACTION_LEFT) 	)); 

		if ( ai > newi ) 	return ( AB.randomPick ( ACTION_RIGHT,	AB.randomPick(ACTION_UP,ACTION_DOWN) 		)); 
	    if ( ai < newi ) 	return ( AB.randomPick ( ACTION_LEFT,	AB.randomPick(ACTION_UP,ACTION_DOWN) 		)); 

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

function Entity() {
    this.nextSquare = null;
    this.path = [];
    this.action = null;
    this.pathFound = null;
}

//This is going to hold the data of all the entities that have been added
function Entities() {
    this.enemy = new Entity();
    this.agent = new Entity();
}