+ updateEnlightened() {
+ for (let i = 0; i < V.size.x; i++) {
+ for (let j = 0; j < V.size.y; j++) {
+ this.enlightened["w"][i][j] = false;
+ this.enlightened["b"][i][j] = false;
+ }
+ }
+ const pawnShift = { w: -1, b: 1 };
+ // Initialize with pieces positions (which are seen)
+ for (let i = 0; i < V.size.x; i++) {
+ for (let j = 0; j < V.size.y; j++) {
+ if (this.board[i][j] != V.EMPTY) {
+ const c = this.getColor(i, j);
+ this.enlightened[c][i][j] = true;
+ // Add potential squares visible by "impossible pawn capture"
+ if (this.getPiece(i, j) == V.PAWN) {
+ for (let shiftY of [-1, 1]) {
+ if (
+ V.OnBoard(i + pawnShift[c], j + shiftY) &&
+ this.board[i + pawnShift[c]][j + shiftY] == V.EMPTY
+ ) {
+ this.enlightened[c][i + pawnShift[c]][j + shiftY] = true;
+ }
+ }
+ }
+ }
+ }
+ }
+ const currentTurn = this.turn;
+ this.turn = "w";
+ const movesWhite = this.getAllValidMoves();
+ this.turn = "b";
+ const movesBlack = this.getAllValidMoves();
+ this.turn = currentTurn;
+ for (let move of movesWhite)
+ this.enlightened["w"][move.end.x][move.end.y] = true;
+ for (let move of movesBlack)
+ this.enlightened["b"][move.end.x][move.end.y] = true;
+ // Include en-passant capturing square if any:
+ let moves = currentTurn == "w" ? movesWhite : movesBlack;
+ for (let m of moves) {
+ if (
+ m.appear[0].p == V.PAWN &&
+ m.vanish.length == 2 &&
+ m.vanish[1].x != m.end.x
+ ) {
+ const psq = m.vanish[1];
+ this.enlightened[currentTurn][psq.x][psq.y] = true;
+ break;
+ }
+ }
+ }