+ updateEnlightened() {
+ this.oldEnlightened = this.enlightened;
+ this.enlightened = ArrayFun.init(this.size.x, this.size.y, false);
+ // Add pieces positions + all squares reachable by moves (includes Zen):
+ for (let x=0; x<this.size.x; x++) {
+ for (let y=0; y<this.size.y; y++) {
+ if (this.board[x][y] != "" && this.getColor(x, y) == this.playerColor)
+ {
+ this.enlightened[x][y] = true;
+ this.getPotentialMovesFrom([x, y]).forEach(m => {
+ this.enlightened[m.end.x][m.end.y] = true;
+ });
+ }
+ }
+ }
+ if (this.epSquare)
+ this.enlightEnpassant();
+ }
+
+ // Include square of the en-passant capturing square:
+ enlightEnpassant() {
+ // NOTE: shortcut, pawn has only one attack type, doesn't depend on square
+ // TODO: (0, 0) is wrong, would need to place an attacker here...
+ const steps = this.pieces(this.playerColor, 0, 0)["p"].attack[0].steps;
+ for (let step of steps) {
+ const x = this.epSquare.x - step[0], //NOTE: epSquare.x not on edge
+ y = this.getY(this.epSquare.y - step[1]);
+ if (
+ this.onBoard(x, y) &&
+ this.getColor(x, y) == this.playerColor &&
+ this.getPieceType(x, y) == "p"
+ ) {
+ this.enlightened[x][this.epSquare.y] = true;
+ break;
+ }
+ }
+ }
+
+ // Apply diff this.enlightened --> oldEnlightened on board
+ graphUpdateEnlightened() {
+ let chessboard =
+ document.getElementById(this.containerId).querySelector(".chessboard");
+ const r = chessboard.getBoundingClientRect();
+ const pieceWidth = this.getPieceWidth(r.width);
+ for (let x=0; x<this.size.x; x++) {
+ for (let y=0; y<this.size.y; y++) {
+ if (!this.enlightened[x][y] && this.oldEnlightened[x][y]) {
+ let elt = document.getElementById(this.coordsToId({x: x, y: y}));
+ elt.classList.add("in-shadow");
+ if (this.g_pieces[x][y])
+ this.g_pieces[x][y].classList.add("hidden");
+ }
+ else if (this.enlightened[x][y] && !this.oldEnlightened[x][y]) {
+ let elt = document.getElementById(this.coordsToId({x: x, y: y}));
+ elt.classList.remove("in-shadow");
+ if (this.g_pieces[x][y])
+ this.g_pieces[x][y].classList.remove("hidden");
+ }
+ }
+ }
+ }
+
+ //////////////
+ // BASIC UTILS
+
+ get size() {
+ return {
+ x: 8,
+ y: 8,
+ ratio: 1 //for rectangular board = y / x (optional, 1 = default)
+ };
+ }
+
+ // Color of thing on square (i,j). '' if square is empty
+ getColor(i, j) {
+ if (typeof i == "string")
+ return i; //reserves
+ return this.board[i][j].charAt(0);
+ }
+
+ static GetColorClass(c) {
+ if (c == 'w')
+ return "white";
+ if (c == 'b')
+ return "black";
+ return "other-color"; //unidentified color
+ }
+
+ // Piece on i,j. '' if square is empty
+ getPiece(i, j) {
+ if (typeof j == "string")
+ return j; //reserves
+ return this.board[i][j].charAt(1);
+ }
+
+ // Piece type on square (i,j)
+ getPieceType(x, y, p) {
+ if (!p)
+ p = this.getPiece(x, y);
+ return this.pieces(this.getColor(x, y), x, y)[p].moveas || p;
+ }
+
+ isKing(x, y, p) {
+ if (!p)
+ p = this.getPiece(x, y);
+ if (!this.options["cannibal"])
+ return p == 'k';
+ return !!C.CannibalKings[p];
+ }
+
+ static GetOppTurn(color) {
+ return (color == 'w' ? 'b' : 'w');
+ }
+
+ // Get opponent color(s): may differ from turn (e.g. Checkered)
+ getOppCols(color) {
+ return (color == "w" ? "b" : "w");
+ }
+
+ // Is (x,y) on the chessboard?