X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FHidden.js;h=c8d98eb694b90784efbb16d58a5d10bb82ce6790;hb=1cd3e362caa05b60f01cf8b1d4f6bfeafc0be55f;hp=99b4a7a6783494f9a44d559dcfa7f2262ec374bd;hpb=933fd1f90a080c1a3e477cc36adebb5e8db8a9d3;p=vchess.git diff --git a/client/src/variants/Hidden.js b/client/src/variants/Hidden.js index 99b4a7a6..c8d98eb6 100644 --- a/client/src/variants/Hidden.js +++ b/client/src/variants/Hidden.js @@ -42,6 +42,13 @@ export const VariantRules = class HiddenRules extends ChessRules { }; } + // Turn a hidden piece or revealed piece into revealed piece: + static Decode(p) { + if (Object.keys(V.HIDDEN_DECODE).includes(p)) + return V.HIDDEN_DECODE[p]; + return p; + } + static get PIECES() { return ChessRules.PIECES.concat(Object.values(V.HIDDEN_CODE)); } @@ -93,6 +100,13 @@ export const VariantRules = class HiddenRules extends ChessRules { } getBasicMove([sx, sy], [ex, ey], tr) { + if ( + tr && + Object.keys(V.HIDDEN_DECODE).includes(this.board[sx][sy].charAt(1)) + ) { + // The transformed piece is a priori hidden + tr.p = V.HIDDEN_CODE[tr.p]; + } let mv = new Move({ appear: [ new PiPo({ @@ -123,9 +137,9 @@ export const VariantRules = class HiddenRules extends ChessRules { }) ); // Pieces are revealed when they capture - if (Object.keys(V.HIDDEN_DECODE).includes(mv.appear[0].p)) - mv.appear[0].p = V.HIDDEN_DECODE[mv.appear[0].p]; + mv.appear[0].p = V.Decode(mv.appear[0].p); } + return mv; } @@ -139,6 +153,10 @@ export const VariantRules = class HiddenRules extends ChessRules { ); } + filterValid(moves) { + return moves; + } + static GenRandInitFen() { let pieces = { w: new Array(8), b: new Array(8) }; // Shuffle pieces + pawns on two first ranks @@ -176,7 +194,7 @@ export const VariantRules = class HiddenRules extends ChessRules { const queenPos = positions[randIndex]; positions.splice(randIndex, 1); - // Get random square for queen + // Get random square for king randIndex = randInt(9); const kingPos = positions[randIndex]; positions.splice(randIndex, 1); @@ -241,4 +259,33 @@ export const VariantRules = class HiddenRules extends ChessRules { const moves = this.getAllValidMoves(); return moves[randInt(moves.length)]; } + + getNotation(move) { + // Translate final square + const finalSquare = V.CoordsToSquare(move.end); + + const piece = this.getPiece(move.start.x, move.start.y); + if (piece == V.PAWN) { + // Pawn move + let notation = ""; + if (move.vanish.length > move.appear.length) { + // Capture + const startColumn = V.CoordToColumn(move.start.y); + notation = startColumn + "x" + finalSquare; + } + else notation = finalSquare; + if (move.appear.length > 0 && !["p","s"].includes(move.appear[0].p)) { + // Promotion + const appearPiece = V.Decode(move.appear[0].p); + notation += "=" + appearPiece.toUpperCase(); + } + return notation; + } + // Piece movement + return ( + piece.toUpperCase() + + (move.vanish.length > move.appear.length ? "x" : "") + + finalSquare + ); + } };