X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FClorange.js;h=30256fa6f8d0d1074d91f018814c1e069d19a79d;hb=4313762da3237b04f204e121a20cab3ba7bb5dd2;hp=4c54e941ea2bf48f2feb33e4fe734f9b51fda073;hpb=e50a802531b99829c533f22ecd21e359e7e1e049;p=vchess.git diff --git a/client/src/variants/Clorange.js b/client/src/variants/Clorange.js index 4c54e941..30256fa6 100644 --- a/client/src/variants/Clorange.js +++ b/client/src/variants/Clorange.js @@ -2,6 +2,7 @@ import { ChessRules, PiPo, Move } from "@/base_rules"; import { ArrayFun } from "@/utils/array"; export class ClorangeRules extends ChessRules { + static IsGoodFen(fen) { if (!ChessRules.IsGoodFen(fen)) return false; const fenParsed = V.ParseFen(fen); @@ -19,9 +20,9 @@ export class ClorangeRules extends ChessRules { ); } - static GenRandInitFen(randomness) { + static GenRandInitFen(options) { // Capturing and non-capturing reserves: - return ChessRules.GenRandInitFen(randomness) + " 00000000000000000000"; + return ChessRules.GenRandInitFen(options) + " 00000000000000000000"; } getFen() { @@ -168,7 +169,7 @@ export class ClorangeRules extends ChessRules { return this.getReserveMoves([x, y]); // Standard moves switch (this.getPiece(x, y)) { - case 's': return super.getPotentialPawnMoves([x, y]); + case 's': return this.getPotentialPawnMoves([x, y]); case 'u': return super.getPotentialRookMoves([x, y]); case 'o': return super.getPotentialKnightMoves([x, y]); case 'c': return super.getPotentialBishopMoves([x, y]); @@ -180,32 +181,25 @@ export class ClorangeRules extends ChessRules { getPotentialPawnMoves(sq) { let moves = super.getPotentialPawnMoves(sq); - moves.forEach(m => { - if (m.vanish[0].p == 's' && m.appear[0].p != 's') { - // Promotion pieces should be non-violent as well: - const pIdx = ChessRules.PIECES.findIndex(p => p == m.appear[0].p) - m.appear[0].p = V.NON_VIOLENT[pIdx]; - } - }); + if (moves.length > 0 && moves[0].vanish[0].p == 's') { + // Remove captures for non-violent pawns: + moves = moves.filter(m => m.vanish.length == 1); + moves.forEach(m => { + if (m.appear[0].p != 's') { + // Promotion pieces should be non-violent as well: + const pIdx = ChessRules.PIECES.findIndex(p => p == m.appear[0].p) + m.appear[0].p = V.NON_VIOLENT[pIdx]; + } + }); + } return moves; } - getSlideNJumpMoves([x, y], steps, oneStep) { - let moves = []; - const canTake = ChessRules.PIECES.includes(this.getPiece(x, y)); - outerLoop: for (let step of steps) { - let i = x + step[0]; - let j = y + step[1]; - while (V.OnBoard(i, j) && this.board[i][j] == V.EMPTY) { - moves.push(this.getBasicMove([x, y], [i, j])); - if (oneStep) continue outerLoop; - i += step[0]; - j += step[1]; - } - if (V.OnBoard(i, j) && canTake && this.canTake([x, y], [i, j])) - moves.push(this.getBasicMove([x, y], [i, j])); - } - return moves; + canTake([x1, y1], [x2, y2]) { + return ( + this.getColor(x1, y1) !== this.getColor(x2, y2) && + ChessRules.PIECES.includes(this.getPiece(x1, y1)) + ); } getAllValidMoves() { @@ -310,4 +304,5 @@ export class ClorangeRules extends ChessRules { move.appear[0].p != V.PAWN ? move.appear[0].p.toUpperCase() : ""; return piece + "@" + V.CoordsToSquare(move.end); } + };