- // Update castling flags if rooks are moved (only)
- if (piece == V.KING && move.appear.length > 0)
- this.castleFlags[c] = [V.size.y, V.size.y];
- else if (
- move.start.x == firstRank &&
- this.castleFlags[c].includes(move.start.y)
- ) {
- const flagIdx = (move.start.y == this.castleFlags[c][0] ? 0 : 1);
- this.castleFlags[c][flagIdx] = V.size.y;
+ // Update castling flags
+ if (piece == V.KING) this.castleFlags[c] = [V.size.y, V.size.y];
+ for (let v of move.vanish) {
+ if (v.x == firstRank && this.castleFlags[c].includes(v.y)) {
+ const flagIdx = (v.y == this.castleFlags[c][0] ? 0 : 1);
+ this.castleFlags[c][flagIdx] = V.size.y;
+ }