- updateVariables(move) {
- const c = this.turn;
- const piece = move.vanish[0].p;
- const firstRank = (c == "w" ? V.size.x - 1 : 0);
-
- // Update king position + flags
- if (piece == V.KING) {
- this.kingPos[c][0] = move.appear[0].x;
- this.kingPos[c][1] = move.appear[0].y;
- this.castleFlags[c] = [false, false];
- return;
- }
-
- // Update castling flags if rook or jailer moved (or is captured)
- const oppCol = V.GetOppCol(c);
- const oppFirstRank = V.size.x - 1 - firstRank;
- let flagIdx = 0;
- if (
- // Our rook moves?
- move.start.x == firstRank &&
- this.INIT_COL_ROOK[c] == move.start.y
- ) {
- if (this.INIT_COL_ROOK[c] > this.INIT_COL_JAILER[c]) flagIdx++;
- this.castleFlags[c][flagIdx] = false;
- } else if (
- // Our jailer moves?
- move.start.x == firstRank &&
- this.INIT_COL_JAILER[c] == move.start.y
- ) {
- if (this.INIT_COL_JAILER[c] > this.INIT_COL_ROOK[c]) flagIdx++;
- this.castleFlags[c][flagIdx] = false;
- } else if (
- // We took opponent's rook?
- move.end.x == oppFirstRank &&
- this.INIT_COL_ROOK[oppCol] == move.end.y
- ) {
- if (this.INIT_COL_ROOK[oppCol] > this.INIT_COL_JAILER[oppCol]) flagIdx++;
- this.castleFlags[oppCol][flagIdx] = false;
- } else if (
- // We took opponent's jailer?
- move.end.x == oppFirstRank &&
- this.INIT_COL_JAILER[oppCol] == move.end.y
- ) {
- if (this.INIT_COL_JAILER[oppCol] > this.INIT_COL_ROOK[oppCol]) flagIdx++;
- this.castleFlags[oppCol][flagIdx] = false;
- }
-