X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FDoublemove1.js;h=261ca5dd0bf1372fb1074a681b6aa5e8aa445c32;hb=7e8a7ea1cb66adb4a987badfb0a3c2f99a21bd0a;hp=6999eb404d55b2cff737233251d4fac7660181e1;hpb=737a5dafb39740ebe304b8d0a82df85070def571;p=vchess.git diff --git a/client/src/variants/Doublemove1.js b/client/src/variants/Doublemove1.js index 6999eb40..261ca5dd 100644 --- a/client/src/variants/Doublemove1.js +++ b/client/src/variants/Doublemove1.js @@ -1,6 +1,7 @@ import { ChessRules } from "@/base_rules"; export class Doublemove1Rules extends ChessRules { + static IsGoodEnpassant(enpassant) { const squares = enpassant.split(","); if (squares.length > 2) return false; @@ -76,11 +77,38 @@ export class Doublemove1Rules extends ChessRules { return moves; } + atLeastOneMove() { + const color = this.turn; + 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 && this.getColor(i, j) == color) { + const moves = this.getPotentialMovesFrom([i, j]); + if (moves.length > 0) { + for (let k = 0; k < moves.length; k++) { + const m = moves[k]; + // NOTE: not using play() here (=> infinite loop) + V.PlayOnBoard(this.board, m); + if (m.vanish[0].p == V.KING) + this.kingPos[color] = [m.appear[0].x, m.appear[0].y]; + const res = !this.underCheck(color); + V.UndoOnBoard(this.board, m); + if (m.vanish[0].p == V.KING) + this.kingPos[color] = [m.start.x, m.start.y]; + if (res) return true; + } + } + } + } + } + return false; + } + play(move) { move.flags = JSON.stringify(this.aggregateFlags()); move.turn = [this.turn, this.subTurn]; V.PlayOnBoard(this.board, move); const epSq = this.getEpSquare(move); + const oppCol = V.GetOppCol(this.turn); if (this.movesCount == 0) { // First move in game this.turn = "b"; @@ -96,14 +124,14 @@ export class Doublemove1Rules extends ChessRules { !this.atLeastOneMove() ) ) { - this.turn = V.GetOppCol(this.turn); + this.turn = oppCol; this.epSquares.push([epSq]); move.checkOnSubturn1 = true; this.movesCount++; } else { if (this.subTurn == 2) { - this.turn = V.GetOppCol(this.turn); + this.turn = oppCol; let lastEpsq = this.epSquares[this.epSquares.length - 1]; lastEpsq.push(epSq); } @@ -122,8 +150,7 @@ export class Doublemove1Rules extends ChessRules { const firstRank = c == "w" ? V.size.x - 1 : 0; if (piece == V.KING) { - this.kingPos[c][0] = move.appear[0].x; - this.kingPos[c][1] = move.appear[0].y; + this.kingPos[c] = [move.appear[0].x, move.appear[0].y]; this.castleFlags[c] = [V.size.y, V.size.y]; return; } @@ -247,4 +274,5 @@ export class Doublemove1Rules extends ChessRules { } return doubleMove; } + };