- 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 color = this.getColor(i,j);
- this.enlightened[color][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[color],j+shiftY)
- && this.board[i+pawnShift[color]][j+shiftY] == V.EMPTY)
- {
- this.enlightened[color][i+pawnShift[color]][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;
- }
+ 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 color = this.getColor(i, j);
+ this.enlightened[color][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[color], j + shiftY) &&
+ this.board[i + pawnShift[color]][j + shiftY] == V.EMPTY
+ ) {
+ this.enlightened[color][i + pawnShift[color]][
+ 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;
+ }