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

// Cloned by Jack O'Brien on 22 Nov 2020 from Mind "Complex Mind (clone by Jack O'Brien)" by Jack O'Brien 
// Please leave this clone trail here.
 
var count=0,ringPath=[],test=null,travelledPath=[];let destination;function agentpath(t,e){let n=[],o=[];for(n.push(t);n.length>0;){for(var r=0,l=0;l<n.length;l++)n[l].f<n[r].f&&(r=l);var a=n[r];if(e.blockingNeighbors.includes(a)){resetValues(o);let t=[];var i=a;for(t.push(i);i.previous;)t.push(i.previous),i=i.previous;return drawPath(t,16716947),t}removeFromArray(n,a),o.push(a);var u=a.blockingNeighbors;if(u)for(l=0;l<u.length;l++){var s=u[l];if(!occupied(s.i,s.j)&&!o.includes(s)){var h=a.g+aStar(s,a),c=!1;n.includes(s)?h<=s.g&&(s.g=h,c=!0):(s.g=h,c=!0,n.push(s)),c&&(s.h=aStar(s,agentLocation),s.f=s.g+s.h,s.previous=a)}}}return null}function dist(t,e,n,o){return Math.sqrt(Math.pow(t-n,2)+Math.pow(e-o,2))}AB.mind.getAction=function(t){var e=t[0],n=t[1],o=t[2],r=t[3];let l=[];travelledPath.push(t[4][e][n]),console.log("Outside first if"),console.log("Count 1: "+count);t:if(0===count||null==test){for(console.log("Inside first if");travelledPath.length>5;)for(var a=travelledPath.length-1;a>travelledPath.length-6;a--)if(travelledPath[a].i==e&&travelledPath[a].j==n&&(count++,console.log("Count 1: "+count),count>=4))break t}else for(;count>=4&&null==test;)null!==agentpath(travelledPath[travelledPath.length-1],t[4][AB.randomIntAtoB(1,gridsize-2)][AB.randomIntAtoB(1,gridsize-2)])&&(test=agentpath(agentLocation,t[4][AB.randomIntAtoB(1,gridsize-2)][AB.randomIntAtoB(1,gridsize-2)]),console.log("Count 2: "+count),count=0);if(null!==test){console.log("Count 3: "+count);var i=test[test.length-2];if(n==i.j){if(e<i.i)return console.log("Move RIGHT: "+ACTION_RIGHT),l.push(ACTION_RIGHT),ACTION_RIGHT;if(e>i.i)return console.log("Move LEFT: "+ACTION_LEFT),l.push(ACTION_LEFT),ACTION_LEFT}}else if(null==test){if(r<n)return l.push(AB.randomPick(ACTION_UP,AB.randomPick(ACTION_RIGHT,ACTION_LEFT))),l;if(r>n)return l.push(AB.randomPick(ACTION_DOWN,AB.randomPick(ACTION_RIGHT,ACTION_LEFT))),l;if(o<e)return l.push(AB.randomPick(ACTION_RIGHT,AB.randomPick(ACTION_UP,ACTION_DOWN))),l;if(o>e)return l.push(AB.randomPick(ACTION_LEFT,AB.randomPick(ACTION_UP,ACTION_DOWN))),l}};