Code viewer for World: Chess (clone by Adam Gray)

// Cloned by Adam Gray on 14 Nov 2022 from World "Chess" by Eoin Daly 
// Please leave this clone trail here.
 
const startRadius=500,maxRadius=5e3,skycolor="#4442ff";AB.clockTick=50,AB.maxSteps=1e6,ABWorld.drawCameraControls=!1;var chessPieces,selectorSide=new THREE.BoxGeometry(10,1,50),selectorRoof=new THREE.BoxGeometry(50,1,10),nextMove=new THREE.BoxGeometry(30,1,30),nextKillSide=new THREE.BoxGeometry(10,1,30),nextKillRoof=new THREE.BoxGeometry(30,1,10);function loadResources(){var e=new THREE.MTLLoader;e.setResourcePath("/uploads/dalye54/"),e.setPath("/uploads/dalye54/"),e.load("chess.mtl",function(e){e.preload();var i=new THREE.OBJLoader;i.setPath("/uploads/dalye54/"),i.setMaterials(e),i.load("chess.obj",function(e){chessPieces=e,asynchFinished()&&displayPieces()})})}function asynchFinished(){return!!chessPieces}class Game{constructor(){this.turn="white"}switchTurn(){"white"!=this.turn?"black"!=this.turn||(this.turn="white"):this.turn="black"}displayTurn(){return this.turn}}class Player{constructor(){this.colour="white"}displayColour(){return this.colour}setBlack(){this.colour="black"}setWhite(){this.colour="white"}}var user=new Player;class DisplaySelect{constructor(e,i){this.piecePosition=[e,i],this.parts=[]}displayPiece(){colour=new THREE.MeshBasicMaterial({color:"blue"}),(theLeft=new THREE.Mesh(selectorSide,colour)).position.x=50*this.piecePosition[0]-195,theLeft.position.y=25.5,theLeft.position.z=50*this.piecePosition[1]-175,(theRight=new THREE.Mesh(selectorSide,colour)).position.x=50*this.piecePosition[0]-155,theRight.position.y=25.5,theRight.position.z=50*this.piecePosition[1]-175,theBottom=new THREE.Mesh(selectorRoof,colour),(theTop=new THREE.Mesh(selectorRoof,colour)).position.x=50*this.piecePosition[0]-175,theTop.position.y=25.5,theTop.position.z=50*this.piecePosition[1]-195,theBottom.position.x=50*this.piecePosition[0]-175,theBottom.position.y=25.5,theBottom.position.z=50*this.piecePosition[1]-155,this.parts.push(theLeft,theRight,theBottom,theTop),ABWorld.scene.add(theLeft),ABWorld.scene.add(theRight),ABWorld.scene.add(theTop),ABWorld.scene.add(theBottom)}deletePiece(){length=this.parts.length;for(var e=0;e<length;e++)ABWorld.scene.remove(this.parts[e])}down(){if(7!=this.piecePosition[1]){this.piecePosition[1]+=1,length=this.parts.length;for(var e=0;e<length;e++)this.parts[e].translateZ(50)}}up(){if(0!=this.piecePosition[1]){this.piecePosition[1]-=1,length=this.parts.length;for(var e=0;e<length;e++)this.parts[e].translateZ(-50)}}right(){if(7!=this.piecePosition[0]){this.piecePosition[0]+=1,length=this.parts.length;for(var e=0;e<length;e++)this.parts[e].translateX(50)}}left(){if(0!=this.piecePosition[0]){this.piecePosition[0]-=1,length=this.parts.length;for(var e=0;e<length;e++)this.parts[e].translateX(-50)}}location(){return this.piecePosition}}var theBase,theStem,theHead,part,pawnBase=new THREE.CylinderGeometry(10,15,15),pawnCylinder=new THREE.CylinderGeometry(8,8,15),pawnHead=new THREE.SphereGeometry(10);class Pawn{constructor(e,i,o){this.piecePosition=[e,i],this.pieceColour=o,this.parts=[]}displayPiece(){"white"===this.pieceColour?((part=chessPieces.children[6].clone()).scale.multiplyScalar(.25),part.position.x=50*this.piecePosition[0]-341,part.position.y=25,part.position.z=375+50*this.piecePosition[1]):((part=chessPieces.children[0].clone()).scale.multiplyScalar(.25),part.position.x=50*this.piecePosition[0]-341,part.position.y=25,part.position.z=212+50*this.piecePosition[1]),this.parts.push(part),ABWorld.scene.add(part)}deletePiece(){length=this.parts.length;for(var e=0;e<length;e++)ABWorld.scene.remove(this.parts[e])}displayMoves(){var e,i,o;possibleMoves[0].push(this.piecePosition),i="white"==this.pieceColour?this.piecePosition[1]-1:this.piecePosition[1]+1,e=this.piecePosition[0],o="black"==this.pieceColour?1==this.piecePosition[1]?2:1:6==this.piecePosition[1]?2:1;for(var s=0;s<o&&(8!=i&&-1!=i&&8!=e&&-1!=e)&&""==map[i][e];s++)displayOnBoard(e,i),possibleMoves[1].push([e,i]),"white"==this.pieceColour?i-=1:i+=1;e=this.piecePosition[0],i=this.piecePosition[1],"white"==this.pieceColour?(8!=i&&0!=i&&7!=e&&-1!=e&&"black"==map[i-1][e+1][0]&&(displayDeathOnBoard(e+1,i-1),possibleMoves[1].push([e+1,i-1])),8!=i&&0!=i&&8!=e&&0!=e&&"black"==map[i-1][e-1][0]&&(displayDeathOnBoard(e-1,i-1),possibleMoves[1].push([e-1,i-1]))):(7!=i&&-1!=i&&7!=e&&-1!=e&&"white"==map[i+1][e+1][0]&&(displayDeathOnBoard(e+1,i+1),possibleMoves[1].push([e+1,i+1])),7!=i&&-1!=i&&8!=e&&0!=e&&"white"==map[i+1][e-1][0]&&(displayDeathOnBoard(e-1,i+1),possibleMoves[1].push([e-1,i+1])))}updatePosition(e,i){var o=e-this.piecePosition[0],s=i-this.piecePosition[1];this.piecePosition[0]=e,this.piecePosition[1]=i,length=this.parts.length;for(var t=0;t<length;t++)this.parts[t].translateX(50*o),this.parts[t].translateZ(50*s)}pieceType(){return"pawn"}}var battleMent1,battleMent2,battleMent3,battleMent4,RookBase=new THREE.CylinderGeometry(20,20,45,6),RookBattlementsSide=new THREE.BoxGeometry(2,10,10),RookBattlementsTop=new THREE.BoxGeometry(10,10,2);class Rook{constructor(e,i,o){this.piecePosition=[e,i],this.pieceColour=o,this.parts=[]}displayPiece(){"white"===this.pieceColour?((part=chessPieces.children[7].clone()).scale.multiplyScalar(.25),part.position.x=50*this.piecePosition[0]-5,part.position.y=25,part.position.z=378+50*this.piecePosition[1]):((part=chessPieces.children[1].clone()).scale.multiplyScalar(.25),part.position.x=50*this.piecePosition[0]-5,part.position.y=25,part.position.z=212+50*this.piecePosition[1]),this.parts.push(part),ABWorld.scene.add(part)}deletePiece(){length=this.parts.length;for(var e=0;e<length;e++)ABWorld.scene.remove(this.parts[e])}displayMoves(){var e,i;possibleMoves[0].push(this.piecePosition),e=this.piecePosition[0],i=this.piecePosition[1];for(var o=0;o<8&&(8!=(i+=1)&&-1!=i&&8!=e&&-1!=e);o++){if(""!=map[i][e]){if(map[i][e][0]!==this.pieceColour){displayDeathOnBoard(e,i),possibleMoves[1].push([e,i]);break}break}displayOnBoard(e,i),possibleMoves[1].push([e,i])}for(i=this.piecePosition[1],o=0;o<8&&(8!=(i-=1)&&-1!=i&&8!=e&&-1!=e);o++){if(""!=map[i][e]){if(map[i][e][0]!==this.pieceColour){displayDeathOnBoard(e,i),possibleMoves[1].push([e,i]);break}break}displayOnBoard(e,i),possibleMoves[1].push([e,i])}for(i=this.piecePosition[1],e=this.piecePosition[0],o=0;o<8&&(e+=1,8!=i&&-1!=i&&8!=e&&-1!=e);o++){if(""!=map[i][e]){if(map[i][e][0]!==this.pieceColour){displayDeathOnBoard(e,i),possibleMoves[1].push([e,i]);break}break}displayOnBoard(e,i),possibleMoves[1].push([e,i])}for(e=this.piecePosition[0],o=0;o<8&&(e-=1,8!=i&&-1!=i&&8!=e&&-1!=e);o++){if(""!=map[i][e]){if(map[i][e][0]!==this.pieceColour){displayDeathOnBoard(e,i),possibleMoves[1].push([e,i]);break}break}displayOnBoard(e,i),possibleMoves[1].push([e,i])}}updatePosition(e,i){var o=e-this.piecePosition[0],s=i-this.piecePosition[1];this.piecePosition[0]=e,this.piecePosition[1]=i,length=this.parts.length;for(var t=0;t<length;t++)this.parts[t].translateX(50*o),this.parts[t].translateZ(50*s)}pieceType(){return"rook"}}var KnightBase=new THREE.BoxGeometry(50,20,50),KnightCylinder=new THREE.CylinderGeometry(10,10,40),KnightHead=new THREE.BoxGeometry(20,10,50);class Knight{constructor(e,i,o){this.piecePosition=[e,i],this.pieceColour=o,this.parts=[]}displayPiece(){"white"===this.pieceColour?((part=chessPieces.children[8].clone()).scale.multiplyScalar(.25),part.position.x=50*this.piecePosition[0]-277,part.position.y=25,part.position.z=50*this.piecePosition[1]-725,part.rotation.y=Math.PI/1):((part=chessPieces.children[2].clone()).scale.multiplyScalar(.25),part.position.x=50*this.piecePosition[0]-72,part.position.y=25,part.position.z=212+50*this.piecePosition[1]),this.parts.push(part),ABWorld.scene.add(part)}deletePiece(){length=this.parts.length;for(var e=0;e<length;e++)ABWorld.scene.remove(this.parts[e])}displayMoves(){var e,i;possibleMoves[0].push(this.piecePosition),e=this.piecePosition[0],i=this.piecePosition[1],e+=1,(i+=2)<8&&i>-1&&e<8&&e>-1&&(""==map[i][e]?(displayOnBoard(e,i),possibleMoves[1].push([e,i])):map[i][e][0]!==this.pieceColour&&(displayDeathOnBoard(e,i),possibleMoves[1].push([e,i]))),e-=2,i<8&&i>-1&&e<8&&e>-1&&(""==map[i][e]?(displayOnBoard(e,i),possibleMoves[1].push([e,i])):map[i][e][0]!==this.pieceColour&&(displayDeathOnBoard(e,i),possibleMoves[1].push([e,i]))),e-=1,(i-=1)<8&&i>-1&&e<8&&e>-1&&(""==map[i][e]?(displayOnBoard(e,i),possibleMoves[1].push([e,i])):map[i][e][0]!==this.pieceColour&&(displayDeathOnBoard(e,i),possibleMoves[1].push([e,i]))),(i-=2)<8&&i>-1&&e<8&&e>-1&&(""==map[i][e]?(displayOnBoard(e,i),possibleMoves[1].push([e,i])):map[i][e][0]!==this.pieceColour&&(displayDeathOnBoard(e,i),possibleMoves[1].push([e,i]))),e+=1,(i-=1)<8&&i>-1&&e<8&&e>-1&&(""==map[i][e]?(displayOnBoard(e,i),possibleMoves[1].push([e,i])):map[i][e][0]!==this.pieceColour&&(displayDeathOnBoard(e,i),possibleMoves[1].push([e,i]))),e+=2,i<8&&i>-1&&e<8&&e>-1&&(""==map[i][e]?(displayOnBoard(e,i),possibleMoves[1].push([e,i])):map[i][e][0]!==this.pieceColour&&(displayDeathOnBoard(e,i),possibleMoves[1].push([e,i]))),e+=1,(i+=1)<8&&i>-1&&e<8&&e>-1&&(""==map[i][e]?(displayOnBoard(e,i),possibleMoves[1].push([e,i])):map[i][e][0]!==this.pieceColour&&(displayDeathOnBoard(e,i),possibleMoves[1].push([e,i]))),(i+=2)<8&&i>-1&&e<8&&e>-1&&(""==map[i][e]?(displayOnBoard(e,i),possibleMoves[1].push([e,i])):map[i][e][0]!==this.pieceColour&&(displayDeathOnBoard(e,i),possibleMoves[1].push([e,i])))}updatePosition(e,i){var o=e-this.piecePosition[0],s=i-this.piecePosition[1];if(this.piecePosition[0]=e,this.piecePosition[1]=i,length=this.parts.length,"white"===this.pieceColour)for(var t=0;t<length;t++)this.parts[t].translateX(-50*o),this.parts[t].translateZ(-50*s);else for(t=0;t<length;t++)this.parts[t].translateX(50*o),this.parts[t].translateZ(50*s)}pieceType(){return"knight"}}var bishopBase=new THREE.CylinderGeometry(15,20,20),bishopCylinder=new THREE.CylinderGeometry(15,15,40),bishopHead=new THREE.SphereGeometry(15);class Bishop{constructor(e,i,o){this.piecePosition=[e,i],this.pieceColour=o,this.parts=[]}displayPiece(){"white"===this.pieceColour?((part=chessPieces.children[9].clone()).scale.multiplyScalar(.25),part.position.x=50*this.piecePosition[0]-210,part.position.y=25,part.position.z=50*this.piecePosition[1]-725,part.rotation.y=Math.PI/1):((part=chessPieces.children[3].clone()).scale.multiplyScalar(.25),part.position.x=50*this.piecePosition[0]-141,part.position.y=25,part.position.z=212+50*this.piecePosition[1]),this.parts.push(part),ABWorld.scene.add(part)}deletePiece(){length=this.parts.length;for(var e=0;e<length;e++)ABWorld.scene.remove(this.parts[e])}displayMoves(){var e,i;possibleMoves[0].push(this.piecePosition),e=this.piecePosition[0],i=this.piecePosition[1];for(var o=0;o<8&&(e+=1,8!=(i+=1)&&-1!=i&&8!=e&&-1!=e);o++){if(""!=map[i][e]){if(map[i][e][0]!==this.pieceColour){displayDeathOnBoard(e,i),possibleMoves[1].push([e,i]);break}break}displayOnBoard(e,i),possibleMoves[1].push([e,i])}e=this.piecePosition[0],i=this.piecePosition[1];for(o=0;o<8&&(e-=1,8!=(i+=1)&&-1!=i&&8!=e&&-1!=e);o++){if(""!=map[i][e]){if(map[i][e][0]!==this.pieceColour){displayDeathOnBoard(e,i),possibleMoves[1].push([e,i]);break}break}displayOnBoard(e,i),possibleMoves[1].push([e,i])}e=this.piecePosition[0],i=this.piecePosition[1];for(o=0;o<8&&(e-=1,8!=(i-=1)&&-1!=i&&8!=e&&-1!=e);o++){if(""!=map[i][e]){if(map[i][e][0]!==this.pieceColour){displayDeathOnBoard(e,i),possibleMoves[1].push([e,i]);break}break}displayOnBoard(e,i),possibleMoves[1].push([e,i])}e=this.piecePosition[0],i=this.piecePosition[1];for(o=0;o<8&&(e+=1,8!=(i-=1)&&-1!=i&&8!=e&&-1!=e);o++){if(""!=map[i][e]){if(map[i][e][0]!==this.pieceColour){displayDeathOnBoard(e,i),possibleMoves[1].push([e,i]);break}break}displayOnBoard(e,i),possibleMoves[1].push([e,i])}}updatePosition(e,i){var o=e-this.piecePosition[0],s=i-this.piecePosition[1];if(this.piecePosition[0]=e,this.piecePosition[1]=i,length=this.parts.length,"white"===this.pieceColour)for(var t=0;t<length;t++)this.parts[t].translateX(-50*o),this.parts[t].translateZ(-50*s);else for(t=0;t<length;t++)this.parts[t].translateX(50*o),this.parts[t].translateZ(50*s)}pieceType(){return"bishop"}}var theHat,QueenBase=new THREE.CylinderGeometry(15,25,50,8),QueenCylinder=new THREE.CylinderGeometry(15,15,40),QueenHead=new THREE.SphereGeometry(15),QueenHat=new THREE.ConeGeometry(20,15,6);class Queen{constructor(e,i,o){this.piecePosition=[e,i],this.pieceColour=o,this.parts=[]}displayPiece(){"white"===this.pieceColour?((part=chessPieces.children[10].clone()).scale.multiplyScalar(.25),part.position.x=50*this.piecePosition[0]-140,part.position.y=25,part.position.z=50*this.piecePosition[1]-725,part.rotation.y=Math.PI/1):((part=chessPieces.children[4].clone()).scale.multiplyScalar(.25),part.position.x=50*this.piecePosition[0]-210,part.position.y=25,part.position.z=212+50*this.piecePosition[1]),this.parts.push(part),ABWorld.scene.add(part)}deletePiece(){length=this.parts.length;for(var e=0;e<length;e++)ABWorld.scene.remove(this.parts[e])}displayMoves(){var e,i;possibleMoves[0].push(this.piecePosition),e=this.piecePosition[0],i=this.piecePosition[1];for(var o=0;o<8&&(e+=1,8!=(i+=1)&&-1!=i&&8!=e&&-1!=e);o++){if(""!=map[i][e]){if(map[i][e][0]!==this.pieceColour){displayDeathOnBoard(e,i),possibleMoves[1].push([e,i]);break}break}displayOnBoard(e,i),possibleMoves[1].push([e,i])}e=this.piecePosition[0],i=this.piecePosition[1];for(o=0;o<8&&(e-=1,8!=(i+=1)&&-1!=i&&8!=e&&-1!=e);o++){if(""!=map[i][e]){if(map[i][e][0]!==this.pieceColour){displayDeathOnBoard(e,i),possibleMoves[1].push([e,i]);break}break}displayOnBoard(e,i),possibleMoves[1].push([e,i])}e=this.piecePosition[0],i=this.piecePosition[1];for(o=0;o<8&&(e-=1,8!=(i-=1)&&-1!=i&&8!=e&&-1!=e);o++){if(""!=map[i][e]){if(map[i][e][0]!==this.pieceColour){displayDeathOnBoard(e,i),possibleMoves[1].push([e,i]);break}break}displayOnBoard(e,i),possibleMoves[1].push([e,i])}e=this.piecePosition[0],i=this.piecePosition[1];for(o=0;o<8&&(e+=1,8!=(i-=1)&&-1!=i&&8!=e&&-1!=e);o++){if(""!=map[i][e]){if(map[i][e][0]!==this.pieceColour){displayDeathOnBoard(e,i),possibleMoves[1].push([e,i]);break}break}displayOnBoard(e,i),possibleMoves[1].push([e,i])}e=this.piecePosition[0],i=this.piecePosition[1];for(o=0;o<8&&(8!=(i+=1)&&-1!=i&&8!=e&&-1!=e);o++){if(""!=map[i][e]){if(map[i][e][0]!==this.pieceColour){displayDeathOnBoard(e,i),possibleMoves[1].push([e,i]);break}break}displayOnBoard(e,i),possibleMoves[1].push([e,i])}for(i=this.piecePosition[1],o=0;o<8&&(8!=(i-=1)&&-1!=i&&8!=e&&-1!=e);o++){if(""!=map[i][e]){if(map[i][e][0]!==this.pieceColour){displayDeathOnBoard(e,i),possibleMoves[1].push([e,i]);break}break}displayOnBoard(e,i),possibleMoves[1].push([e,i])}for(i=this.piecePosition[1],e=this.piecePosition[0],o=0;o<8&&(e+=1,8!=i&&-1!=i&&8!=e&&-1!=e);o++){if(""!=map[i][e]){if(map[i][e][0]!==this.pieceColour){displayDeathOnBoard(e,i),possibleMoves[1].push([e,i]);break}break}displayOnBoard(e,i),possibleMoves[1].push([e,i])}for(e=this.piecePosition[0],o=0;o<8&&(e-=1,8!=i&&-1!=i&&8!=e&&-1!=e);o++){if(""!=map[i][e]){if(map[i][e][0]!==this.pieceColour){displayDeathOnBoard(e,i),possibleMoves[1].push([e,i]);break}break}displayOnBoard(e,i),possibleMoves[1].push([e,i])}}updatePosition(e,i){var o=e-this.piecePosition[0],s=i-this.piecePosition[1];if(this.piecePosition[0]=e,this.piecePosition[1]=i,length=this.parts.length,"white"===this.pieceColour)for(var t=0;t<length;t++)this.parts[t].translateX(-50*o),this.parts[t].translateZ(-50*s);else for(t=0;t<length;t++)this.parts[t].translateX(50*o),this.parts[t].translateZ(50*s)}pieceType(){return"queen"}}var KingBase=new THREE.CylinderGeometry(20,25,50,4),KingCylinder=new THREE.CylinderGeometry(20,20,60),KingHead=new THREE.SphereGeometry(20),KingHat=new THREE.ConeGeometry(10,15,30);class King{constructor(e,i,o){this.piecePosition=[e,i],this.pieceColour=o,this.parts=[]}displayPiece(){"white"===this.pieceColour?((part=chessPieces.children[11].clone()).scale.multiplyScalar(.25),part.position.x=50*this.piecePosition[0]-71,part.position.y=25,part.position.z=50*this.piecePosition[1]-725,part.rotation.y=Math.PI/1):((part=chessPieces.children[5].clone()).scale.multiplyScalar(.25),part.position.x=50*this.piecePosition[0]-279,part.position.y=25,part.position.z=212+50*this.piecePosition[1]),this.parts.push(part),ABWorld.scene.add(part)}deletePiece(){length=this.parts.length;for(var e=0;e<length;e++)ABWorld.scene.remove(this.parts[e])}displayMoves(){var e,i;possibleMoves[0].push(this.piecePosition),e=this.piecePosition[0],i=this.piecePosition[1],e+=1,8!=(i+=1)&&-1!=i&&8!=e&&-1!=e&&(""==map[i][e]?(displayOnBoard(e,i),possibleMoves[1].push([e,i])):map[i][e][0]!==this.pieceColour&&(displayDeathOnBoard(e,i),possibleMoves[1].push([e,i]))),8!=(i-=1)&&-1!=i&&8!=e&&-1!=e&&(""==map[i][e]?(displayOnBoard(e,i),possibleMoves[1].push([e,i])):map[i][e][0]!==this.pieceColour&&(displayDeathOnBoard(e,i),possibleMoves[1].push([e,i]))),8!=(i-=1)&&-1!=i&&8!=e&&-1!=e&&(""==map[i][e]?(displayOnBoard(e,i),possibleMoves[1].push([e,i])):map[i][e][0]!==this.pieceColour&&(displayDeathOnBoard(e,i),possibleMoves[1].push([e,i]))),e-=1,8!=i&&-1!=i&&8!=e&&-1!=e&&(""==map[i][e]?(displayOnBoard(e,i),possibleMoves[1].push([e,i])):map[i][e][0]!==this.pieceColour&&(displayDeathOnBoard(e,i),possibleMoves[1].push([e,i]))),e-=1,8!=i&&-1!=i&&8!=e&&-1!=e&&(""==map[i][e]?(displayOnBoard(e,i),possibleMoves[1].push([e,i])):map[i][e][0]!==this.pieceColour&&(displayDeathOnBoard(e,i),possibleMoves[1].push([e,i]))),8!=(i+=1)&&-1!=i&&8!=e&&-1!=e&&(""==map[i][e]?(displayOnBoard(e,i),possibleMoves[1].push([e,i])):map[i][e][0]!==this.pieceColour&&(displayDeathOnBoard(e,i),possibleMoves[1].push([e,i]))),8!=(i+=1)&&-1!=i&&8!=e&&-1!=e&&(""==map[i][e]?(displayOnBoard(e,i),possibleMoves[1].push([e,i])):map[i][e][0]!==this.pieceColour&&(displayDeathOnBoard(e,i),possibleMoves[1].push([e,i]))),e+=1,8!=i&&-1!=i&&8!=e&&-1!=e&&(""==map[i][e]?(displayOnBoard(e,i),possibleMoves[1].push([e,i])):map[i][e][0]!==this.pieceColour&&(displayDeathOnBoard(e,i),possibleMoves[1].push([e,i])))}updatePosition(e,i){var o=e-this.piecePosition[0],s=i-this.piecePosition[1];if(this.piecePosition[0]=e,this.piecePosition[1]=i,length=this.parts.length,"white"===this.pieceColour)for(var t=0;t<length;t++)this.parts[t].translateX(-50*o),this.parts[t].translateZ(-50*s);else for(t=0;t<length;t++)this.parts[t].translateX(50*o),this.parts[t].translateZ(50*s)}pieceType(){return"king"}}var HL00,HL01,HL02,HL03,HL04,HL05,HL06,HL07,HL08,HL09,HL10,HL11,HL12,HL13,HL14,HL15,HL16,HL17,HL18,HL19,HL20,HL21,HL22,HL23,HL24,HL25,HL26,HL27,HL28,HL29,HL30,HL31,HL32,HL33,HL34,HL35,HL36,HL37,HL38,HL39,HL40,HL41,HL42,HL43,HL44,HL45,HL46,HL47,HL48,HL49,HL50,HL51,HL52,HL53,HL54,HL55,HL56,HL57,HL58,HL59,HL60,HL61,HL62,HL63,HL64,HL65,HL66,HL67,HL68,HL69,HL70,HL71,HL72,HL73,HL74,HL75,HL76,HL77,HL78,HL79,HL80,HL81,HL82,HL83,HL84,HL85,HL86,HL87,HL88,HL89,HL90,HL91,HL92,HL93,HL94,HL95,HL96,HL97,HL98,HL99,BP1,BP2,BP3,BP4,BP5,BP6,BP7,BP8,WP1,WP2,WP3,WP4,WP5,WP6,WP7,WP8,BR1,BR2,WR1,WR2,BKN1,BKN2,WKN1,WKN2,BB1,BB2,WB1,WB2,BQ,WQ,BK,WK,theLeft,theRight,theBottom,theTop,theLeftKill,theRightKill,theBottomKill,theTopKill,displaySelector=new DisplaySelect(0,0),possibleMoves=[[],[]],map=[[["black","R",BR1],["black","Kn",BKN1],["black","B",BB1],["black","Q",BQ],["black","K",BK],["black","B",BB2],["black","Kn",BKN2],["black","R",BR2]],[["black","P",BP1],["black","P",BP2],["black","P",BP3],["black","P",BP4],["black","P",BP5],["black","P",BP6],["black","P",BP7],["black","P",BP8]],["","","","","","","","","",""],["","","","","","","","","",""],["","","","","","","","","",""],["","","","","","","","","",""],[["white","P",WP1],["white","P",WP2],["white","P",WP3],["white","P",WP4],["white","P",WP5],["white","P",WP6],["white","P",WP7],["white","P",WP8]],[["white","R",WR1],["white","Kn",BKN1],["white","B",WB1],["white","Q",WQ],["white","K",WK],["white","B",WB2],["white","Kn",WKN2],["white","R",WR2]]],mapMoves=[[HL00,HL01,HL02,HL03,HL04,HL05,HL06,HL07],[HL10,HL11,HL12,HL13,HL14,HL15,HL16,HL17],[HL20,HL21,HL22,HL23,HL24,HL25,HL26,HL27],[HL30,HL31,HL32,HL33,HL34,HL35,HL36,HL37],[HL40,HL41,HL42,HL43,HL44,HL45,HL46,HL47],[HL50,HL51,HL52,HL53,HL54,HL55,HL56,HL57],[HL60,HL61,HL62,HL63,HL64,HL65,HL66,HL67],[HL70,HL71,HL72,HL73,HL74,HL75,HL76,HL77]];function displayOnBoard(e,i){colour=new THREE.MeshBasicMaterial({color:"yellow"}),mapMoves[i][e]=new THREE.Mesh(nextMove,colour),mapMoves[i][e].position.x=50*e-175,mapMoves[i][e].position.y=25.5,mapMoves[i][e].position.z=50*i-175,ABWorld.scene.add(mapMoves[i][e])}function displayDeathOnBoard(e,i){colour=new THREE.MeshBasicMaterial({color:"red"}),mapMoves[i][e]=[],(theLeftKill=new THREE.Mesh(nextKillSide,colour)).position.x=50*e-195,theLeftKill.position.y=26.5,theLeftKill.position.z=50*i-175,(theRightKill=new THREE.Mesh(nextKillSide,colour)).position.x=50*e-155,theRightKill.position.y=26.5,theRightKill.position.z=50*i-175,(theBottomKill=new THREE.Mesh(nextKillRoof,colour)).position.x=50*e-175,theBottomKill.position.y=26.5,theBottomKill.position.z=50*i-155,(theTopKill=new THREE.Mesh(nextKillRoof,colour)).position.x=50*e-175,theTopKill.position.y=26.5,theTopKill.position.z=50*i-195,mapMoves[i][e].push(theLeftKill,theRightKill,theBottomKill,theTopKill),ABWorld.scene.add(theLeftKill),ABWorld.scene.add(theRightKill),ABWorld.scene.add(theBottomKill),ABWorld.scene.add(theTopKill)}function compareInput(e,i){var o=map[e[1]][e[0]];""==map[i[1]][i[0]]?(map[i[1]][i[0]]=o,map[e[1]][e[0]]="",map[i[1]][i[0]][2].updatePosition(i[0],i[1])):""!=map[i[1]][i[0]]&&(map[i[1]][i[0]][2].deletePiece(),map[i[1]][i[0]]=o,map[e[1]][e[0]]="",map[i[1]][i[0]][2].updatePosition(i[0],i[1]),0!=i[1]&&7!=i[1]||(console.log(map[i[1]][i[0]][2].pieceType()),"pawn"==map[i[1]][i[0]][2].pieceType()&&(console.log("test"),map[i[1]][i[0]][2].deletePiece(),map[i[1]][i[0]][2]=void 0,map[i[1]][i[0]][2]=new Queen(i[0],i[1],map[i[1]][i[0]][0]),map[i[1]][i[0]][2].displayPiece())))}function removeFromBoard(){length=possibleMoves[1].length;for(var e=0;e<length;e++)if(Array.isArray(mapMoves[possibleMoves[1][e][1]][possibleMoves[1][e][0]])){for(var i=mapMoves[possibleMoves[1][e][1]][possibleMoves[1][e][0]].length,o=0;o<i;o++)ABWorld.scene.remove(mapMoves[possibleMoves[1][e][1]][possibleMoves[1][e][0]][o]);mapMoves[possibleMoves[1][e][1]][possibleMoves[1][e][0]]=void 0}else ABWorld.scene.remove(mapMoves[possibleMoves[1][e][1]][possibleMoves[1][e][0]])}const gridsize=8;var boardCube=new THREE.BoxGeometry(50,50,50);function displayBoard(){for(var e=1,i=0;i<gridsize;i+=1){for(var o=0;o<gridsize;o+=1)colour=e%2==0?new THREE.MeshBasicMaterial({color:"lightblue"}):new THREE.MeshBasicMaterial({color:"darkred"}),theCube=new THREE.Mesh(boardCube,colour),theCube.position.x=50*o-175,theCube.position.z=50*i-175,ABWorld.scene.add(theCube),e+=1;e+=1}}function displayPieces(){for(var e=0;e<gridsize;e+=1)for(var i=0;i<gridsize;i+=1)" "!=map[e][i]&&("P"==map[e][i][1]?(map[e][i][2]=new Pawn(i,e,map[e][i][0]),map[e][i][2].displayPiece()):"R"==map[e][i][1]?(map[e][i][2]=new Rook(i,e,map[e][i][0]),map[e][i][2].displayPiece()):"Kn"==map[e][i][1]?(map[e][i][2]=new Knight(i,e,map[e][i][0]),map[e][i][2].displayPiece()):"B"==map[e][i][1]?(map[e][i][2]=new Bishop(i,e,map[e][i][0]),map[e][i][2].displayPiece()):"Q"==map[e][i][1]?(map[e][i][2]=new Queen(i,e,map[e][i][0]),map[e][i][2].displayPiece()):"K"==map[e][i][1]&&(map[e][i][2]=new King(i,e,map[e][i][0]),map[e][i][2].displayPiece()))}function keyHandler(e){if(37==e.keyCode)displaySelector.left();else if(38==e.keyCode)displaySelector.up();else if(39==e.keyCode)displaySelector.right();else if(40==e.keyCode)displaySelector.down();else if(13==e.keyCode){console.log(displaySelector.location()),length=possibleMoves[1].length;for(var i=0;i<length;i++)if(possibleMoves[1][i][0]==displaySelector.location()[0]&&possibleMoves[1][i][1]==displaySelector.location()[1])return chessGame.switchTurn(),updateOnAllBoards([possibleMoves[0][0][0],possibleMoves[0][0][1]],displaySelector.location()),movingPieceOnBoard(),removeFromBoard(),void(possibleMoves=[[],[]]);removeFromBoard(),possibleMoves=[[],[]],""!=map[displaySelector.location()[1]][displaySelector.location()[0]]&&user.displayColour()==map[displaySelector.location()[1]][displaySelector.location()[0]][0]&&chessGame.displayTurn()==map[displaySelector.location()[1]][displaySelector.location()[0]][0]&&map[displaySelector.location()[1]][displaySelector.location()[0]][2].displayMoves()}else 32==e.keyCode&&console.log(map)}function movingPieceOnBoard(){var e=map[possibleMoves[0][0][1]][possibleMoves[0][0][0]];""==map[displaySelector.location()[1]][displaySelector.location()[0]]?(map[displaySelector.location()[1]][displaySelector.location()[0]]=e,map[possibleMoves[0][0][1]][possibleMoves[0][0][0]]="",map[displaySelector.location()[1]][displaySelector.location()[0]][2].updatePosition(displaySelector.location()[0],displaySelector.location()[1])):""!=map[displaySelector.location()[1]][displaySelector.location()[0]]&&(map[displaySelector.location()[1]][displaySelector.location()[0]][2].deletePiece(),map[displaySelector.location()[1]][displaySelector.location()[0]]=e,map[possibleMoves[0][0][1]][possibleMoves[0][0][0]]="",map[displaySelector.location()[1]][displaySelector.location()[0]][2].updatePosition(displaySelector.location()[0],displaySelector.location()[1])),0!=displaySelector.location()[1]&&7!=displaySelector.location()[1]||(console.log(map[displaySelector.location()[1]][displaySelector.location()[0]][2].pieceType()),"pawn"==map[displaySelector.location()[1]][displaySelector.location()[0]][2].pieceType()&&(console.log("test"),map[displaySelector.location()[1]][displaySelector.location()[0]][2].deletePiece(),map[displaySelector.location()[1]][displaySelector.location()[0]][2]=void 0,map[displaySelector.location()[1]][displaySelector.location()[0]][2]=new Queen(displaySelector.location()[0],displaySelector.location()[1],map[displaySelector.location()[1]][displaySelector.location()[0]][0]),map[displaySelector.location()[1]][displaySelector.location()[0]][2].displayPiece()))}const LIGHTCOLOR=16777215;function commands(){"white"==chessGame.displayTurn()?AB.msg(" <hr> <p> Chess game. Pick a side. Click buttons to pick colour. <p>\n  \t        <button onclick='user.setBlack()'  class=ab-largenormbutton > Black </button>  \n            <button onclick='user.setWhite()'  class=ab-largenormbutton > White </button> <p> \n            <h1>White Turn</h1>\n            </hr>"):"black"==chessGame.displayTurn()&&AB.msg(" <hr> <p> Chess game. Pick a side. Click buttons to pick colour. <p>\n  \t        <button onclick='user.setBlack()'  class=ab-largenormbutton > Black </button>  \n            <button onclick='user.setWhite()'  class=ab-largenormbutton > White </button> <p> \n            <h1>Black Turn</h1>\n            </hr>")}var chessGame=new Game;function updateOnAllBoards(e,i){AB.socket&&AB.socket.connected&&(data={first:e,second:i},AB.socketOut(data)),commands()}AB.world.newRun=function(){ABWorld.init3d(500,5e3,skycolor),loadResources(),displayBoard(),displaySelector.displayPiece();var e=new THREE.DirectionalLight(16777215,3);e.position.set(500,500,500),ABWorld.scene.add(e),commands()},AB.world.nextStep=function(){document.onkeydown=keyHandler},AB.world.endRun=function(){},AB.socketStart(),AB.socketIn=function(e){compareInput(e.first,e.second),chessGame.switchTurn(),commands()};