// Cloned by przemek biel on 2 Dec 2022 from World "Chess" by Eoin Daly
// Please leave this clone trail here.
const soundDead = "/uploads/dalye54/Wilhelm_death.mp3",
startRadius = 500,
maxRadius = 5e3,
skycolor = "#4442ff";
var deathSound = new Audio(soundDead);
AB.clockTick = 50, AB.maxSteps = 1e6, ABWorld.drawCameraControls = !1;
const skyboxArray = ["/uploads/dalye54/posx.jpg", "/uploads/dalye54/negx.jpg", "/uploads/dalye54/posy.jpg", "/uploads/dalye54/negy.jpg", "/uploads/dalye54/posz.jpg", "/uploads/dalye54/negz.jpg"],
walnutCube = (new THREE.TextureLoader).load("/uploads/dalye54/walnut.jpg"),
beechCube = (new THREE.TextureLoader).load("/uploads/dalye54/beech.jpg");
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", this.winner = !1, this.colourWinner
}
switchTurn() {
"white" != this.turn ? "black" != this.turn || (this.turn = "white") : this.turn = "black"
}
displayTurn() {
return this.turn
}
gameOver(e) {
this.colourWinner = e, this.winner = !0
}
}
class Player {
constructor() {
this.colour = "white"
}
displayColour() {
return this.colour
}
setBlack() {
this.colour = "black"
}
setWhite() {
this.colour = "white"
}
}
var part, 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
}
}
class Pawn {
constructor(e, i, s) {
this.piecePosition = [e, i], this.pieceColour = s, 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, s;
possibleMoves[0].push(this.piecePosition), i = "white" == this.pieceColour ? this.piecePosition[1] - 1 : this.piecePosition[1] + 1, e = this.piecePosition[0], s = "black" == this.pieceColour ? 1 == this.piecePosition[1] ? 2 : 1 : 6 == this.piecePosition[1] ? 2 : 1;
for (var o = 0; o < s && (8 != i && -1 != i && 8 != e && -1 != e) && "" == map[i][e]; o++) 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 s = e - this.piecePosition[0],
o = 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 * s), this.parts[t].translateZ(50 * o)
}
pieceType() {
return "pawn"
}
}
class Rook {
constructor(e, i, s) {
this.piecePosition = [e, i], this.pieceColour = s, 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 s = 0; s < 8 && (8 != (i += 1) && -1 != i && 8 != e && -1 != e); s++) {
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], s = 0; s < 8 && (8 != (i -= 1) && -1 != i && 8 != e && -1 != e); s++) {
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], s = 0; s < 8 && (e += 1, 8 != i && -1 != i && 8 != e && -1 != e); s++) {
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], s = 0; s < 8 && (e -= 1, 8 != i && -1 != i && 8 != e && -1 != e); s++) {
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 s = e - this.piecePosition[0],
o = 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 * s), this.parts[t].translateZ(50 * o)
}
pieceType() {
return "rook"
}
}
class Knight {
constructor(e, i, s) {
this.piecePosition = [e, i], this.pieceColour = s, 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 s = e - this.piecePosition[0],
o = 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 * s), this.parts[t].translateZ(-50 * o);
else
for (t = 0; t < length; t++) this.parts[t].translateX(50 * s), this.parts[t].translateZ(50 * o)
}
pieceType() {
return "knight"
}
}
class Bishop {
constructor(e, i, s) {
this.piecePosition = [e, i], this.pieceColour = s, 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 s = 0; s < 8 && (e += 1, 8 != (i += 1) && -1 != i && 8 != e && -1 != e); s++) {
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 (s = 0; s < 8 && (e -= 1, 8 != (i += 1) && -1 != i && 8 != e && -1 != e); s++) {
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 (s = 0; s < 8 && (e -= 1, 8 != (i -= 1) && -1 != i && 8 != e && -1 != e); s++) {
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 (s = 0; s < 8 && (e += 1, 8 != (i -= 1) && -1 != i && 8 != e && -1 != e); s++) {
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 s = e - this.piecePosition[0],
o = 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 * s), this.parts[t].translateZ(-50 * o);
else
for (t = 0; t < length; t++) this.parts[t].translateX(50 * s), this.parts[t].translateZ(50 * o)
}
pieceType() {
return "bishop"
}
}
class Queen {
constructor(e, i, s) {
this.piecePosition = [e, i], this.pieceColour = s, 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 s = 0; s < 8 && (e += 1, 8 != (i += 1) && -1 != i && 8 != e && -1 != e); s++) {
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 (s = 0; s < 8 && (e -= 1, 8 != (i += 1) && -1 != i && 8 != e && -1 != e); s++) {
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 (s = 0; s < 8 && (e -= 1, 8 != (i -= 1) && -1 != i && 8 != e && -1 != e); s++) {
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 (s = 0; s < 8 && (e += 1, 8 != (i -= 1) && -1 != i && 8 != e && -1 != e); s++) {
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 (s = 0; s < 8 && (8 != (i += 1) && -1 != i && 8 != e && -1 != e); s++) {
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], s = 0; s < 8 && (8 != (i -= 1) && -1 != i && 8 != e && -1 != e); s++) {
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], s = 0; s < 8 && (e += 1, 8 != i && -1 != i && 8 != e && -1 != e); s++) {
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], s = 0; s < 8 && (e -= 1, 8 != i && -1 != i && 8 != e && -1 != e); s++) {
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 s = e - this.piecePosition[0],
o = 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 * s), this.parts[t].translateZ(-50 * o);
else
for (t = 0; t < length; t++) this.parts[t].translateX(50 * s), this.parts[t].translateZ(50 * o)
}
pieceType() {
return "queen"
}
}
class King {
constructor(e, i, s) {
this.piecePosition = [e, i], this.pieceColour = s, 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 s = e - this.piecePosition[0],
o = 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 * s), this.parts[t].translateZ(-50 * o);
else
for (t = 0; t < length; t++) this.parts[t].translateX(50 * s), this.parts[t].translateZ(50 * o)
}
pieceType() {
return "king"
}
}
var 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, 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 s = map[e[1]][e[0]];
"" == map[i[1]][i[0]] ? (map[i[1]][i[0]] = s, map[e[1]][e[0]] = "", map[i[1]][i[0]][2].updatePosition(i[0], i[1])) : "" != map[i[1]][i[0]] && (deathSound.play(), "king" == map[i[1]][i[0]][2].pieceType() && chessGame.gameOver(map[e[1]][e[0]][0]), map[i[1]][i[0]][2].deletePiece(), map[i[1]][i[0]] = s, map[e[1]][e[0]] = "", map[i[1]][i[0]][2].updatePosition(i[0], i[1])), 0 != i[1] && 7 != i[1] || "pawn" == map[i[1]][i[0]][2].pieceType() && (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, s = 0; s < i; s++) ABWorld.scene.remove(mapMoves[possibleMoves[1][e][1]][possibleMoves[1][e][0]][s]);
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 s = 0; s < gridsize; s += 1) colour = e % 2 == 0 ? new THREE.MeshBasicMaterial({
map: walnutCube
}) : new THREE.MeshBasicMaterial({
map: beechCube
}), theCube = new THREE.Mesh(boardCube, colour), theCube.position.x = 50 * s - 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) {
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]] && (deathSound.play(), "king" == map[displaySelector.location()[1]][displaySelector.location()[0]][2].pieceType() && chessGame.gameOver(map[possibleMoves[0][0][1]][possibleMoves[0][0][0]][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] || "pawn" == map[displaySelector.location()[1]][displaySelector.location()[0]][2].pieceType() && (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;
AB.world.newRun = function() {
ABWorld.init3d(500, 5e3, skycolor), loadResources(), displayBoard(), displaySelector.displayPiece(), ABWorld.scene.background = (new THREE.CubeTextureLoader).load(skyboxArray, function() {
ABWorld.render(), AB.removeLoading()
});
var e = new THREE.DirectionalLight(16777215, 1);
e.position.set(500, 500, 500), ABWorld.scene.add(e);
var i = new THREE.DirectionalLight(16777215, 1);
i.position.set(-500, 500, -500), ABWorld.scene.add(i), commands()
};
var turn = 0;
function splashEnd() {
return "white" == chessGame.colourWinner ? "<hr> <p> Game is complete <p> <hr> <p>White player won the game<p>" : "<hr> <p> Game is complete <p> <hr> <p>Black player won the game<p>"
}
function splashFull() {
return "<hr> Game is full please try again later <hr>"
}
function updateOnAllBoards(e, i) {
AB.socket && AB.socket.connected && (data = {
first: e,
second: i
}, AB.socketOut(data)), commands()
}
AB.world.nextStep = function() {
document.onkeydown = keyHandler, 1 == chessGame.winner && 0 == turn && (setTimeout(function() {
AB.world.endRun()
}, 200), turn = 1)
}, AB.world.endRun = function() {
AB.newSplash(), AB.splashHtml(splashEnd())
}, AB.socketStart();
var safe = !1;
AB.socketUserlist = function(e) {
console.log(e), console.log(AB.runReady), e.length > 2 && !1 === safe ? (AB.newSplash(), console.log("To many players"), AB.splashHtml(splashFull())) : safe = !0
}, AB.socketIn = function(e) {
console.log(e), compareInput(e.first, e.second), chessGame.switchTurn(), commands()
};