Code viewer for World: Complex World (clone by Ai...

// Cloned by mind bogler on 9 Nov 2022 from World "Complex World (clone by Aideen Byrne) (clone by mind bogler)" by mind bogler 
// Please leave this clone trail here.
 


// Cloned by mind bogler on 9 Nov 2022 from World "Complex World (clone by Aideen Byrne)" by Aideen Byrne 
// Please leave this clone trail here.
 
AB.clockTick=100,AB.maxSteps=1e3,AB.screenshotStep=50;const show3d=!0,diagonal=!0,TEXTURE_WALL="/uploads/starter/door.jpg",TEXTURE_MAZE="/uploads/starter/latin.jpg",TEXTURE_AGENT="/uploads/starter/pacman.jpg",TEXTURE_ENEMY="/uploads/starter/ghost.3.png",MUSIC_BACK="/uploads/starter/Defense.Line.mp3",SOUND_ALARM="/uploads/starter/air.horn.mp3",gridsize=50,NOBOXES=Math.trunc(gridsize*gridsize/16.6),squaresize=100,MAXPOS=gridsize*squaresize,SKYCOLOR=14548957,startRadiusConst=.8*MAXPOS,maxRadiusConst=10*MAXPOS;ABHandler.MAXCAMERAPOS=maxRadiusConst,ABHandler.GROUNDZERO=!0;const SKYBOX_ARRAY=["/uploads/starter/posx.jpg","/uploads/starter/negx.jpg","/uploads/starter/posy.jpg","/uploads/starter/negy.jpg","/uploads/starter/posz.jpg","/uploads/starter/negz.jpg"],ACTION_LEFT=0,ACTION_RIGHT=1,ACTION_UP=2,ACTION_DOWN=3,ACTION_STAYSTILL=4,GRID_BLANK=0,GRID_WALL=1,GRID_MAZE=2;var BOXHEIGHT,theagent,theenemy,wall_texture,agent_texture,enemy_texture,maze_texture,ei,ej,ai,aj,badsteps,goodsteps,start,end,GRID=new Array(gridsize),Astargrid=new Array(gridsize),openSet=[],closedSet=[],path=[];function heuristic(e,t){return AB.distance2D(ei,ai,ej,aj)}function removeFromArray(e,t){for(var i=e.length-1;i>=0;i--)e[i]==t&&e.splice(i,1)}function Spot(){this.i=void 0,this.j=void 0,this.f=0,this.g=0,this.h=0,this.neighbors=[],this.previous=void 0,this.addNeighbors=function(e){var t=this.i,i=this.j;t<gridsize-1&&this.neighbors.push(gridsize[t+1][i]),t>0&&this.neighbors.push(gridsize[t-1][i]),i<squaresize-1&&this.neighbors.push(gridsize[t][i+1]),i>0&&this.neighbors.push(gridsize[t][i-1]),t>0&&i>0&&this.neighbors.push(gridsize[t-1][i-1]),t<gridsize-1&&i>0&&this.neighbors.push(gridsize[t+1][i-1]),t>0&&i<squaresize-1&&this.neighbors.push(gridsize[t-1][i+1]),t<gridsize-1&&i<squaresize-1&&this.neighbors.push(gridsize[t+1][i+1])}}function loadResources(){var e=new THREE.TextureLoader,t=new THREE.TextureLoader,i=new THREE.TextureLoader,s=new THREE.TextureLoader;e.load(TEXTURE_WALL,function(e){e.minFilter=THREE.LinearFilter,wall_texture=e,asynchFinished()&&initScene()}),t.load(TEXTURE_AGENT,function(e){e.minFilter=THREE.LinearFilter,agent_texture=e,asynchFinished()&&initScene()}),i.load(TEXTURE_ENEMY,function(e){e.minFilter=THREE.LinearFilter,enemy_texture=e,asynchFinished()&&initScene()}),s.load(TEXTURE_MAZE,function(e){e.minFilter=THREE.LinearFilter,maze_texture=e,asynchFinished()&&initScene()})}function asynchFinished(){return!!(wall_texture&&agent_texture&&enemy_texture&&maze_texture)}function occupied(e,t){return ei==e&&ej==t||(ai==e&&aj==t||(GRID[e][t]==GRID_WALL||GRID[e][t]==GRID_MAZE))}function translate(e,t){var i=new THREE.Vector3;return i.y=0,i.x=e*squaresize-MAXPOS/2,i.z=t*squaresize-MAXPOS/2,i}function initScene(){var e,t,i,s;for(e=0;e<gridsize;e++)GRID[e]=new Array(gridsize);for(e=0;e<gridsize;e++)for(t=0;t<gridsize;t++)0==e||e==gridsize-1||0==t||t==gridsize-1?(GRID[e][t]=GRID_WALL,i=new THREE.BoxGeometry(squaresize,BOXHEIGHT,squaresize),(s=new THREE.Mesh(i)).material=new THREE.MeshBasicMaterial({map:wall_texture}),s.position.copy(translate(e,t)),ABWorld.scene.add(s)):GRID[e][t]=GRID_BLANK;for(var r=1;r<=NOBOXES;r++)e=AB.randomIntAtoB(1,gridsize-2),t=AB.randomIntAtoB(1,gridsize-2),GRID[e][t]=GRID_MAZE,i=new THREE.BoxGeometry(squaresize,BOXHEIGHT,squaresize),(s=new THREE.Mesh(i)).material=new THREE.MeshBasicMaterial({map:maze_texture}),s.position.copy(translate(e,t)),ABWorld.scene.add(s);do{e=AB.randomIntAtoB(1,gridsize-2),t=AB.randomIntAtoB(1,gridsize-2)}while(occupied(e,t));ei=e,ej=t,i=new THREE.BoxGeometry(squaresize,BOXHEIGHT,squaresize),(theenemy=new THREE.Mesh(i)).material=new THREE.MeshBasicMaterial({map:enemy_texture}),ABWorld.scene.add(theenemy),n();do{e=AB.randomIntAtoB(1,gridsize-2),t=AB.randomIntAtoB(1,gridsize-2)}while(occupied(e,t));function n(){theenemy.position.copy(translate(ei,ej)),ABWorld.lookat.copy(theenemy.position)}function o(){theagent.position.copy(translate(ai,aj)),ABWorld.follow.copy(theagent.position)}function d(e){var t=ai,i=aj;e==ACTION_LEFT?t--:e==ACTION_RIGHT?t++:e==ACTION_UP?i++:e==ACTION_DOWN&&i--,occupied(t,i)||(ai=t,aj=i)}ai=e,aj=t,i=new THREE.BoxGeometry(squaresize,BOXHEIGHT,squaresize),(theagent=new THREE.Mesh(i)).material=new THREE.MeshBasicMaterial({map:agent_texture}),ABWorld.scene.add(theagent),o(),ABWorld.scene.background=(new THREE.CubeTextureLoader).load(SKYBOX_ARRAY,function(){ABWorld.render(),AB.removeLoading(),AB.runReady=!0});var u,A,c=[37,38,39,40];function p(e){return!AB.runReady||(!function(e){return c.includes(e.keyCode)}(e)||(37==e.keyCode&&d(ACTION_LEFT),38==e.keyCode&&d(ACTION_DOWN),39==e.keyCode&&d(ACTION_RIGHT),40==e.keyCode&&d(ACTION_UP),e.stopPropagation(),e.preventDefault(),!1))}AB.world.newRun=function(){AB.loadingScreen(),AB.runReady=!1,badsteps=0,goodsteps=0,show3d?(BOXHEIGHT=squaresize,ABWorld.init3d(startRadiusConst,maxRadiusConst,SKYCOLOR)):(BOXHEIGHT=1,ABWorld.init2d(startRadiusConst,maxRadiusConst,SKYCOLOR)),loadResources(),document.onkeydown=p},AB.world.getState=function(){return[ai,aj,ei,ej]},AB.world.takeAction=function(e){!function(e){var t=AB.world.getState();AB.msg(" Step: "+AB.step+" &nbsp; x = ("+t.toString()+") &nbsp; a = ("+e+") ")}(e)},d(a),function(e,t){ei<ai&&(e=AB.randomIntAtoB(ei,ei+1)),ei==ai&&(e=ei),ei>ai&&(e=AB.randomIntAtoB(ei-1,ei)),ej<aj&&(t=AB.randomIntAtoB(ej,ej+1)),ej==aj&&(t=ej),ej>aj&&(t=AB.randomIntAtoB(ej-1,ej)),occupied(e,t)||(ei=e,ej=t)}(),Math.abs(ei-ai)<2&&Math.abs(ej-aj)<2?badsteps++:goodsteps++,o(),n(),u=AB.world.getState(),A=goodsteps/AB.step*100,AB.msg(" &nbsp; y = ("+u.toString()+") <br> Bad steps: "+badsteps+" &nbsp; Good steps: "+goodsteps+" &nbsp; Score: "+A.toFixed(2)+"% ",2),occupied(ai-1,aj)&&occupied(ai+1,aj)&&occupied(ai,aj+1)&&occupied(ai,aj-1)&&(AB.abortRun=!0,goodsteps=0,musicPause(),soundAlarm())}AB.world.endRun=function(){musicPause(),AB.abortRun?AB.msg(" <br> <font color=red> <B> Agent trapped. Final score zero. </B> </font>   ",3):AB.msg(" <br> <font color=green> <B> Run over. </B> </font>   ",3)},AB.world.getScore=function(){var e=goodsteps/AB.maxSteps*100;return Math.round(100*e)/100};var backmusic=AB.backgroundMusic(MUSIC_BACK);function musicPlay(){backmusic.play()}function musicPause(){backmusic.pause()}function soundAlarm(){new Audio(SOUND_ALARM).play()}