Code viewer for World: Cloned Cloned CA318 2018 World

// Cloned by Odhran Byrne-Gildea on 6 Nov 2018 from World "Cloned CA318 2018 World" by cdaly 
// Please leave this clone trail here.
 
const BLOCKPUNISH=50,ACTION_LEFT=0,ACTION_RIGHT=1,ACTION_UP=2,ACTION_DOWN=3,ACTION_STAYSTILL=4;AB.clockTick=50,AB.maxSteps=1e3,AB.screenshotStep=50;const 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",SOUND_ALARM="/uploads/starter/air.horn.mp3",gridsize=20,BOXDENSITY=.1,NOBOXES=Math.trunc(gridsize*gridsize*.1),squaresize=100,MAXPOS=gridsize*squaresize,SKYCOLOR=14548957,startRadiusConst=.8*MAXPOS,skyboxConst=2*MAXPOS,maxRadiusConst=10*MAXPOS;ABHandler.MAXCAMERAPOS=.6*skyboxConst,ABHandler.GROUNDZERO=!0;const SKYBOX_ARRAY=["/uploads/starter/st.posx.jpg","/uploads/starter/st.negx.jpg","/uploads/starter/st.posy.jpg","/uploads/starter/st.negy.jpg","/uploads/starter/st.posz.jpg","/uploads/starter/st.negz.jpg"],GRID_BLANK=0,GRID_WALL=1,GRID_MAZE=2;function World(){var e,r,n,t,a,s,i,o,E,d,A,u,T=squaresize,R=new Array(gridsize),B=new Array(6),l=0,c=this;function p(e){(new THREE.TextureLoader).load(SKYBOX_ARRAY[e],function(r){r.minFilter=THREE.LinearFilter,B[e]=r,H()&&O()})}function H(){for(var e=0;e<6;e++)if(!B[e])return!1;return!!(n&&t&&a&&s)}function M(e,r){return i==e&&o==r||(E==e&&d==r||(R[e][r]==GRID_WALL||R[e][r]==GRID_MAZE))}function m(e,r){var n=new THREE.Vector3;return n.y=0,n.x=e*squaresize-MAXPOS/2,n.z=r*squaresize-MAXPOS/2,n}function O(){var i,o,A,u;for(i=0;i<gridsize;i++)R[i]=new Array(gridsize);for(i=0;i<gridsize;i++)for(o=0;o<gridsize;o++)0==i||i==gridsize-1||0==o||o==gridsize-1?(R[i][o]=GRID_WALL,A=new THREE.BoxGeometry(squaresize,T,squaresize),(u=new THREE.Mesh(A)).material=new THREE.MeshBasicMaterial({map:n}),u.position.copy(m(i,o)),ABWorld.scene.add(u)):R[i][o]=GRID_BLANK;for(var l=1;l<=NOBOXES;l++)i=AB.randomIntAtoB(1,gridsize-2),o=AB.randomIntAtoB(1,gridsize-2),R[i][o]=GRID_MAZE,A=new THREE.BoxGeometry(squaresize,T,squaresize),(u=new THREE.Mesh(A)).material=new THREE.MeshBasicMaterial({map:s}),u.position.copy(m(i,o)),ABWorld.scene.add(u);f(),A=new THREE.BoxGeometry(squaresize,T,squaresize),(r=new THREE.Mesh(A)).material=new THREE.MeshBasicMaterial({map:a}),ABWorld.scene.add(r),I();do{i=AB.randomIntAtoB(1,gridsize-2),o=AB.randomIntAtoB(1,gridsize-2)}while(M(i,o));E=i,d=o,A=new THREE.BoxGeometry(squaresize,T,squaresize),(e=new THREE.Mesh(A)).material=new THREE.MeshBasicMaterial({map:t}),ABWorld.scene.add(e),g();var c=[new THREE.MeshBasicMaterial({map:B[0],side:THREE.BackSide}),new THREE.MeshBasicMaterial({map:B[1],side:THREE.BackSide}),new THREE.MeshBasicMaterial({map:B[2],side:THREE.BackSide}),new THREE.MeshBasicMaterial({map:B[3],side:THREE.BackSide}),new THREE.MeshBasicMaterial({map:B[4],side:THREE.BackSide}),new THREE.MeshBasicMaterial({map:B[5],side:THREE.BackSide})],p=new THREE.CubeGeometry(skyboxConst,skyboxConst,skyboxConst),H=new THREE.MeshFaceMaterial(c),O=new THREE.Mesh(p,H);ABWorld.scene.add(O),ABWorld.render(),AB.removeLoading(),ABRun.runReady=!0}function f(){var e,r;do{e=AB.randomIntAtoB(1,gridsize-2),r=AB.randomIntAtoB(1,gridsize-2)}while(M(e,r));i=e,o=r}function I(){r.position.copy(m(i,o)),ABWorld.lookat.copy(r.position)}function g(){e.position.copy(m(E,d)),ABWorld.follow.copy(e.position)}this.newRun=function(){AB.loadingScreen(),ABRun.runReady=!1,A=0,u=0,ABWorld.init3d(startRadiusConst,maxRadiusConst,SKYCOLOR),function(){var e=new THREE.TextureLoader,r=new THREE.TextureLoader,i=new THREE.TextureLoader,o=new THREE.TextureLoader;e.load(TEXTURE_WALL,function(e){e.minFilter=THREE.LinearFilter,n=e,H()&&O()}),r.load(TEXTURE_AGENT,function(e){e.minFilter=THREE.LinearFilter,t=e,H()&&O()}),i.load(TEXTURE_ENEMY,function(e){e.minFilter=THREE.LinearFilter,a=e,H()&&O()}),o.load(TEXTURE_MAZE,function(e){e.minFilter=THREE.LinearFilter,s=e,H()&&O()});for(var E=0;E<6;E++)p(E)}()},this.getState=function(){return[E,d,i,o]},this.takeAction=function(e){var r,n,t;((function(e){var r=c.getState(),n=" Step: "+ABRun.step+" &nbsp; x = ("+r.toString()+")  &nbsp; a = ("+e+") ";$("#user_span1").html(n)})(e),function(e){var r=E,n=d;e==ACTION_LEFT?r--:e==ACTION_RIGHT?r++:e==ACTION_UP?n++:e==ACTION_DOWN&&n--,M(r,n)||(E=r,d=n)}(e),ABRun.step%2==0)&&function(e){var r=i,n=o;e==ACTION_LEFT?r--:e==ACTION_RIGHT?r++:e==ACTION_UP?n++:e==ACTION_DOWN&&n--,M(r,n)?l++:(l=0,i=r,o=n)}(function(){if(l>2)return AB.randomIntAtoB(0,3);if(AB.randomBoolean()){if(o<d)return ACTION_UP;if(o>d)return ACTION_DOWN}else{if(i<E)return ACTION_RIGHT;if(i>E)return ACTION_LEFT}return AB.randomIntAtoB(0,3)}());Math.abs(i-E)<2&&Math.abs(o-d)<2?A++:u++,g(),I(),r=c.getState(),n=u/ABRun.step*100,t=" &nbsp; y = ("+r.toString()+")  <BR> Bad steps: "+A+" &nbsp; Good steps: "+u+" &nbsp; Score: "+n.toFixed(2)+"% ",$("#user_span2").html(t),M(E-1,d)&&M(E+1,d)&&M(E,d+1)&&M(E,d-1)&&(A+=BLOCKPUNISH,ABRun.step=ABRun.step+BLOCKPUNISH,$("#user_span3").html(" <br> <font color=red> <B> Agent blocked. "+BLOCKPUNISH+" extra bad steps and reset enemy. </B> </font>   "),soundAlarm(),f())},this.endRun=function(){$("#user_span3").html(" <br> <font color=green> <B> Run over. </B> </font>   ")},this.getScore=function(){var e=u/AB.maxSteps*100;return Math.round(100*e)/100}}function soundAlarm(){new Audio(SOUND_ALARM).play()}