Code viewer for Mind: A* Andross Mind (clone by ...

// Cloned by Khizer Ahmed on 17 Nov 2021 from Mind "A* Andross Mind" by Philip 
// Please leave this clone trail here.
 
var openSet=[],closedSet=[],map=null,targetSpot=null,result=null;function getEnemy(){try{initiateSearch([ei,ej],[ai,aj]),result.enemy.nextSquare.j>ej&&(result.enemy.action=ACTION_UP),result.enemy.nextSquare.j<ej&&(result.enemy.action=ACTION_DOWN),result.enemy.nextSquare.i>ei&&(result.enemy.action=ACTION_RIGHT),result.enemy.nextSquare.i<ei&&(result.enemy.action=ACTION_LEFT)}catch(e){console.log("pathNot found")}}function getAgent(){ej<aj&&(result.agent.action=AB.randomPick(ACTION_UP,AB.randomPick(ACTION_RIGHT,ACTION_LEFT))),ej>aj&&(result.agent.action=AB.randomPick(ACTION_DOWN,AB.randomPick(ACTION_RIGHT,ACTION_LEFT))),ei<ai&&(result.agent.action=AB.randomPick(ACTION_RIGHT,AB.randomPick(ACTION_UP,ACTION_DOWN))),ei>ai&&(result.agent.action=AB.randomPick(ACTION_LEFT,AB.randomPick(ACTION_UP,ACTION_DOWN)))}function removeFromArray(e,t){for(var n=e.length-1;n>=0;n--)e[n].i==t.i&&e[n].j==t.j&&e.splice(n,1)}function initiateSearch(e,t){var n=new Space(e[0],e[1]);n.g=0,targetSpot=new Space(t[0],t[1]),openSet.push(n);return findPath(n,0)}function findPath(e,t){for(var n=0;n<openSet.length;n++)openSet[n].f<openSet[t].f&&(t=n);return(e=openSet[t])?e.i==targetSpot.i&&e.j==targetSpot.j?(console.log("success - found path"),findNextMove(e,null)):(removeFromArray(openSet,e),closedSet.push(e),e.addNeighbours(),e.neighbours.forEach(t=>{if(!t.wall&&!closedSet.includes(t)){var n=e.g+heuristic(e,t),i=!1;(!t.g||n<t.g)&&(t.g=n,i=!0),ArrayIncludesSpot(openSet,t)||openSet.push(t),i&&(t.h=heuristic(t,targetSpot),t.f=t.g+t.h,t.parent=e)}}),findPath(e,t)):(console.log("failure - enemy path not foud"),null)}function findNextMove(e,t){e.parent?(result.enemy.path.unshift(e.parent),findNextMove(e.parent,e)):result.enemy.nextSquare=t}function intialiseParameters(){openSet=[],closedSet=[],targetSpot=null,result=new Entities}function Space(e,t){this.i=e,this.j=t,this.wall=0!==map[e][t],this.f=0,this.g=null,this.h=0,this.neighbours=[],this.parent=void 0,this.addNeighbours=function(){var e=map.length,t=map[0].length,n=this.i,i=this.j;n<t-1&&this.neighbours.push(new Space(n+1,i)),n>0&&this.neighbours.push(new Space(n-1,i)),i<e-1&&this.neighbours.push(new Space(n,i+1)),i>0&&this.neighbours.push(new Space(n,i-1))}}function Entity(){this.nextSquare=null,this.path=[],this.action=null}function Entities(){this.enemy=new Entity,this.agent=new Entity}function ArrayIncludesSpot(e,t){for(var n=0;n<e.length;n++)if(e[n].i==t.i&&e[n].j==t.j)return!0;return!1}function heuristic(e,t){return Math.abs(e.i-t.i)+Math.abs(e.j-t.j)}AB.mind.getAction=function(e){e[0],e[1],e[2],e[3];return map=e[4],intialiseParameters(),getEnemy(),getAgent(),result};