X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FRecycle.js;h=de0ff5017b9cef5fa255a77ab757d29b1792e532;hb=4313762da3237b04f204e121a20cab3ba7bb5dd2;hp=adaceb04c9aacd3336fb0386d34b3f6d711b5c16;hpb=0d5335de5c94d780e03ac0aa3279b731c69455cc;p=vchess.git diff --git a/client/src/variants/Recycle.js b/client/src/variants/Recycle.js index adaceb04..de0ff501 100644 --- a/client/src/variants/Recycle.js +++ b/client/src/variants/Recycle.js @@ -2,6 +2,7 @@ import { ChessRules, PiPo, Move } from "@/base_rules"; import { ArrayFun } from "@/utils/array"; export class RecycleRules extends ChessRules { + static get PawnSpecs() { return Object.assign( {}, @@ -27,8 +28,8 @@ export class RecycleRules extends ChessRules { ); } - static GenRandInitFen(randomness) { - return ChessRules.GenRandInitFen(randomness) + " 0000000000"; + static GenRandInitFen(options) { + return ChessRules.GenRandInitFen(options) + " 0000000000"; } getFen() { @@ -54,22 +55,23 @@ export class RecycleRules extends ChessRules { setOtherVariables(fen) { super.setOtherVariables(fen); - const fenParsed = V.ParseFen(fen); // Also init reserves (used by the interface to show landable pieces) + const reserve = + V.ParseFen(fen).reserve.split("").map(x => parseInt(x, 10)); this.reserve = { w: { - [V.PAWN]: parseInt(fenParsed.reserve[0]), - [V.ROOK]: parseInt(fenParsed.reserve[1]), - [V.KNIGHT]: parseInt(fenParsed.reserve[2]), - [V.BISHOP]: parseInt(fenParsed.reserve[3]), - [V.QUEEN]: parseInt(fenParsed.reserve[4]) + [V.PAWN]: reserve[0], + [V.ROOK]: reserve[1], + [V.KNIGHT]: reserve[2], + [V.BISHOP]: reserve[3], + [V.QUEEN]: reserve[4] }, b: { - [V.PAWN]: parseInt(fenParsed.reserve[5]), - [V.ROOK]: parseInt(fenParsed.reserve[6]), - [V.KNIGHT]: parseInt(fenParsed.reserve[7]), - [V.BISHOP]: parseInt(fenParsed.reserve[8]), - [V.QUEEN]: parseInt(fenParsed.reserve[9]) + [V.PAWN]: reserve[5], + [V.ROOK]: reserve[6], + [V.KNIGHT]: reserve[7], + [V.BISHOP]: reserve[8], + [V.QUEEN]: reserve[9] } }; } @@ -84,6 +86,14 @@ export class RecycleRules extends ChessRules { return this.board[i][j].charAt(1); } + getPPpath(m) { + if (m.vanish.length == 2 && m.appear.length == 2) { + // Castle: show castle symbol + return "Coregal/castle"; + } + return super.getPPpath(m); + } + // Used by the interface: getReservePpath(index, color) { return color + V.RESERVE_PIECES[index]; @@ -124,10 +134,9 @@ export class RecycleRules extends ChessRules { } getPotentialMovesFrom([x, y]) { - if (x >= V.size.x) { + if (x >= V.size.x) // Reserves, outside of board: x == sizeX(+1) return this.getReserveMoves([x, y]); - } // Standard moves return super.getPotentialMovesFrom([x, y]); } @@ -144,12 +153,13 @@ export class RecycleRules extends ChessRules { } getAllValidMoves() { - let moves = super.getAllValidMoves(); + let moves = super.getAllPotentialMoves(); const color = this.turn; - for (let i = 0; i < V.RESERVE_PIECES.length; i++) + for (let i = 0; i < V.RESERVE_PIECES.length; i++) { moves = moves.concat( this.getReserveMoves([V.size.x + (color == "w" ? 0 : 1), i]) ); + } return this.filterValid(moves); } @@ -174,7 +184,8 @@ export class RecycleRules extends ChessRules { prePlay(move) { super.prePlay(move); - if (move.vanish.length == 2 && move.appear.length == 2) return; //skip castle + // Skip castle: + if (move.vanish.length == 2 && move.appear.length == 2) return; const color = this.turn; if (move.vanish.length == 0) this.reserve[color][move.appear[0].p]--; else if (move.vanish.length == 2 && move.vanish[1].c == color) @@ -225,4 +236,5 @@ export class RecycleRules extends ChessRules { move.appear[0].p != V.PAWN ? move.appear[0].p.toUpperCase() : ""; return piece + "@" + V.CoordsToSquare(move.end); } + };