Code viewer for World: The Pooh & The Bee 1.2 (T...

// Cloned by Rajasi on 8 Nov 2022 from World "The Pooh & The  Bee 1.2 (The Pooh Trapped at Tunnel)" by Meenu Mathew 
// Please leave this clone trail here.
 
AB.clockTick=100,AB.maxSteps=1e3,AB.screenshotStep=50;const show3d=!0,TEXTURE_WALL="/uploads/meenumathew/brick_wall.JPG",TEXTURE_MAZE="/uploads/meenumathew/brick_wall.JPG",TEXTURE_AGENT="/uploads/meenumathew/pooh.png",TEXTURE_ENEMY="/uploads/meenumathew/bee.png",TEXTURE_TUNNEL="/uploads/meenumathew/tunnel.jpg",MUSIC_BACK="/uploads/meenumathew/Star-Wars-Cantina-Band-_Noize-Tank-Remix_-Gaming-Background-Music.mp3",SOUND_ALARM="/uploads/meenumathew/Portal-Gun-Sound-Effect.mp3",gridsize=50,NOBOXES=Math.trunc(gridsize*gridsize/3),squaresize=100,MAXPOS=gridsize*squaresize,SKYCOLOR=14548957,startRadiusConst=.8*MAXPOS,maxRadiusConst=10*MAXPOS;var line_a=null,line_e=null;ABHandler.MAXCAMERAPOS=maxRadiusConst,ABHandler.GROUNDZERO=!0;const SKYBOX_ARRAY=["/uploads/starter/sky_pos_z.jpg","/uploads/starter/sky_neg_z.jpg","/uploads/starter/sky_pos_y.jpg","/uploads/starter/sky_neg_y.jpg","/uploads/starter/sky_pos_x.jpg","/uploads/starter/sky_neg_x.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,thetunnel,wall_texture,agent_texture,enemy_texture,maze_texture,tunnel_texture,ei,ej,ai,aj,ti,tj,badsteps,goodsteps,GRID=new Array(gridsize);function loadResources(){var e=new THREE.TextureLoader,t=new THREE.TextureLoader,n=new THREE.TextureLoader,r=new THREE.TextureLoader,i=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()}),n.load(TEXTURE_ENEMY,function(e){e.minFilter=THREE.LinearFilter,enemy_texture=e,asynchFinished()&&initScene()}),r.load(TEXTURE_MAZE,function(e){e.minFilter=THREE.LinearFilter,maze_texture=e,asynchFinished()&&initScene()}),i.load(TEXTURE_TUNNEL,function(e){e.minFilter=THREE.LinearFilter,tunnel_texture=e,asynchFinished()&&initScene()})}function asynchFinished(){return!!(wall_texture&&agent_texture&&enemy_texture&&maze_texture&&tunnel_texture)}function occupied(e,t){return ei==e&&ej==t||(ai==e&&aj==t||(ti==e&&tj==t||!!GRID[e][t].wall))}function translate(e,t){var n=new THREE.Vector3;return n.y=0,n.x=e*squaresize-MAXPOS/2,n.z=t*squaresize-MAXPOS/2,n}function initScene(){var e,t,n,r;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]=new Spot(e,t,!0),n=new THREE.BoxGeometry(squaresize,BOXHEIGHT,squaresize),(r=new THREE.Mesh(n)).material=new THREE.MeshBasicMaterial({map:wall_texture}),r.position.copy(translate(e,t)),ABWorld.scene.add(r)):GRID[e][t]=new Spot(e,t,!1);for(e=0;e<gridsize;e++)for(t=0;t<gridsize;t++)GRID[e][t].addNeighbours(GRID);for(var i=1;i<=NOBOXES;i++)e=AB.randomIntAtoB(1,gridsize-2),t=AB.randomIntAtoB(1,gridsize-2),GRID[e][t].wall=!0,n=new THREE.BoxGeometry(squaresize,BOXHEIGHT,squaresize),(r=new THREE.Mesh(n)).material=new THREE.MeshBasicMaterial({map:maze_texture}),r.position.copy(translate(e,t)),ABWorld.scene.add(r);do{e=AB.randomIntAtoB(1,gridsize-2),t=AB.randomIntAtoB(1,gridsize-2)}while(occupied(e,t));ei=e,ej=t,n=new THREE.BoxGeometry(squaresize,BOXHEIGHT,squaresize),(theenemy=new THREE.Mesh(n)).material=new THREE.MeshBasicMaterial({map:enemy_texture}),ABWorld.scene.add(theenemy),drawEnemy();do{e=AB.randomIntAtoB(1,gridsize-2),t=AB.randomIntAtoB(1,gridsize-2)}while(occupied(e,t));ai=e,aj=t,n=new THREE.BoxGeometry(squaresize,BOXHEIGHT,squaresize),(theagent=new THREE.Mesh(n)).material=new THREE.MeshBasicMaterial({map:agent_texture}),ABWorld.scene.add(theagent),drawAgent();do{e=AB.randomIntAtoB(1,gridsize),t=AB.randomIntAtoB(1,gridsize)}while(occupied(e,t));ti=e,tj=t,n=new THREE.BoxGeometry(squaresize,BOXHEIGHT,squaresize),(thetunnel=new THREE.Mesh(n)).material=new THREE.MeshBasicMaterial({map:tunnel_texture}),ABWorld.scene.add(thetunnel),drawTunnel(),ABWorld.scene.background=(new THREE.CubeTextureLoader).load(SKYBOX_ARRAY,function(){ABWorld.render(),AB.removeLoading(),AB.runReady=!0})}function drawEnemy(){theenemy.position.copy(translate(ei,ej)),ABWorld.lookat.copy(theenemy.position)}function drawAgent(){theagent.position.copy(translate(ai,aj)),ABWorld.follow.copy(theagent.position)}function drawTunnel(){thetunnel.position.copy(translate(ti,tj)),ABWorld.follow.copy(thetunnel.position)}function moveLogicalEnemy(e,t){res=pathToAgent(ei,ej,e,t,255),res[0]==e&&res[1]==t||(ei=res[0],ej=res[1])}function moveLogicalAgent(){res=pathToTunnel(ai,aj,ti,tj,16777215),res[0]==ti&&res[1]==tj||(ai=res[0],aj=res[1],moveLogicalEnemy(ai,aj),console.log("moveLogicalAgent_fn:  new_ai= "+ai+" new_aj= "+aj+" new_ti="+ti+" new_tj= "+tj))}function Spot(e,t,n=!1){this.i=e,this.j=t,this.f=0,this.g=0,this.h=0,this.neighbours=[],this.previous=void 0,this.wall=n,this.addNeighbours=function(e){var t=this.i,n=this.j;t<gridsize-1&&this.neighbours.push(e[t+1][n]),t>0&&this.neighbours.push(e[t-1][n]),n<gridsize-1&&this.neighbours.push(e[t][n+1]),n>0&&this.neighbours.push(e[t][n-1])}}function pathToTunnel(e,t,n,r,i){var o=[],a=[],s=!1,u=[];for(o.push(GRID[e][t]);o.length>0;){console.log("i am here");for(var l=0,d=0;d<o.length;d++)o[d].f<o[l].f&&(l=d);var c=o[l];if(console.log("winner = "+l+"openset winner = "+o[l]),c===GRID[n][r]){var p=c;for((u=[]).push(p);p.previous;)u.push(p.previous),previous_temp=p,p=p.previous,previous_temp.previous=void 0;var h=null;return u.length>=2&&(h=u[u.length-2]),res=[],res.push(h.i),res.push(h.j),console.log(u),drawAgentPath(u,i),console.log("new a_i= "+res[0]+"new a_j=  "+res[1]),res}removeFromArray(o,c),a.push(c);var g=c.neighbours;for(d=0;d<g.length;d++){var E=c.neighbours[d];if(!a.includes(E)&&!E.wall){var A=c.g+heuristic(E,c);o.includes(E)?A<E.g&&(E.g=A,s=!0):(E.g=A,s=!0,o.push(E)),s&&(E.h=heuristic(E,GRID[e][t]),E.f=E.g+E.h,E.previous=c)}}}}function drawAgentPath(e,t){null!=line_a&&ABWorld.scene.remove(line_a);const n=new THREE.LineBasicMaterial({color:t}),r=[];for(var i=0;i<e.length;i++)r.push(translate(e[i].i,e[i].j));const o=(new THREE.BufferGeometry).setFromPoints(r);line_a=new THREE.Line(o,n),ABWorld.scene.add(line_a)}function pathToAgent(e,t,n,r,i){var o=[],a=[],s=!1,u=[];for(o.push(GRID[e][t]);o.length>0;){for(var l=0,d=0;d<o.length;d++)o[d].f<o[l].f&&(l=d);var c=o[l];if(console.log("winner = "+l+"openset winner = "+o[l]),c===GRID[n][r]){var p=c;for((u=[]).push(p);p.previous;)u.push(p.previous),previous_temp=p,p=p.previous,previous_temp.previous=void 0;var h=null;return u.length>=2&&(h=u[u.length-2]),res=[],res.push(h.i),res.push(h.j),console.log(u),drawEnemyPath(u,i),res}removeFromArray(o,c),a.push(c);var g=c.neighbours;for(d=0;d<g.length;d++){var E=c.neighbours[d];if(!a.includes(E)&&!E.wall){var A=c.g+heuristic(E,c);o.includes(E)?A<E.g&&(E.g=A,s=!0):(E.g=A,s=!0,o.push(E)),s&&(E.h=heuristic(E,GRID[e][t]),E.f=E.g+E.h,E.previous=c)}}}}function drawEnemyPath(e,t){null!=line_e&&ABWorld.scene.remove(line_e);const n=new THREE.LineBasicMaterial({color:t}),r=[];for(var i=0;i<e.length;i++)r.push(translate(e[i].i,e[i].j));const o=(new THREE.BufferGeometry).setFromPoints(r);line_e=new THREE.Line(o,n),ABWorld.scene.add(line_e)}function removeFromArray(e,t){for(var n=e.length-1;n>=0;n--)e[n]==t&&e.splice(n,1)}function heuristic(e,t){var n=t.i-e.i,r=t.j-e.j;return Math.sqrt(n*n+r*r)}function badstep(){return Math.abs(ei-ai)<2&&Math.abs(ej-aj)<2}function agentBlocked(){return occupied(ai-1,aj)&&occupied(ai+1,aj)&&occupied(ai,aj+1)&&occupied(ai,aj-1)}function updateStatusBefore(e){var t=AB.world.getState();AB.msg(" Step: "+AB.step+" &nbsp; x = ("+t.toString()+") &nbsp; a = ("+e+") ")}function updateStatusAfter(){var e=AB.world.getState(),t=goodsteps/AB.step*100;AB.msg(" &nbsp; y = ("+e.toString()+") <br> Bad steps: "+badsteps+" &nbsp; Good steps: "+goodsteps+" &nbsp; Score: "+t.toFixed(2)+"% ",2)}AB.world.newRun=function(){AB.loadingScreen(),AB.runReady=!1,badsteps=0,goodsteps=0,BOXHEIGHT=squaresize,ABWorld.init3d(startRadiusConst,maxRadiusConst,14548957),loadResources()},AB.world.getState=function(){return[ai,aj,ei,ej]},AB.world.takeAction=function(e){updateStatusBefore(e),moveLogicalAgent(),badstep()?badsteps++:goodsteps++,drawAgent(),drawEnemy(),updateStatusAfter(),agentBlocked()&&(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};