From: Benjamin Auder Date: Mon, 24 Feb 2020 16:55:53 +0000 (+0100) Subject: Fix HiddenRules X-Git-Url: https://git.auder.net/variants/Chakart/css/doc/current/git-logo.png?a=commitdiff_plain;h=1cd3e362caa05b60f01cf8b1d4f6bfeafc0be55f;p=vchess.git Fix HiddenRules --- diff --git a/client/public/images/pieces/Hidden/Question_mark_alternate.svg b/client/public/images/pieces/Hidden/Question_mark_alternate.svg deleted file mode 100644 index f88ab1e3..00000000 --- a/client/public/images/pieces/Hidden/Question_mark_alternate.svg +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - diff --git a/client/public/images/pieces/Hidden/bp.svg b/client/public/images/pieces/Hidden/bp.svg index ba3ff2ef..0c88e126 100644 --- a/client/public/images/pieces/Hidden/bp.svg +++ b/client/public/images/pieces/Hidden/bp.svg @@ -10,10 +10,10 @@ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" version="1.0" - width="679.47827" + width="881.47827" height="881.67249" id="svg11382" - sodipodi:docname="wp.svg" + sodipodi:docname="bp.svg" inkscape:version="0.92.4 5da689c313, 2019-01-14"> @@ -36,33 +36,35 @@ guidetolerance="10" inkscape:pageopacity="0" inkscape:pageshadow="2" - inkscape:window-width="1920" - inkscape:window-height="1180" + inkscape:window-width="960" + inkscape:window-height="590" id="namedview8" showgrid="false" inkscape:zoom="0.26767309" - inkscape:cx="347.21094" + inkscape:cx="354.68274" inkscape:cy="440.83624" - inkscape:window-x="0" + inkscape:window-x="960" inkscape:window-y="20" inkscape:window-maximized="0" inkscape:current-layer="svg11382" /> + d="M 474.50888,718.22841 H 303.49547 v -22.30134 c -2.4e-4,-37.95108 4.30352,-68.76211 12.9113,-92.43319 8.60728,-23.67032 23.63352,-45.28695 40.65324,-64.84996 17.01914,-19.56211 41.98734,-26.33264 101.45793,-75.63085 31.69095,-25.82203 55.2813,-77.1523 55.28175,-98.67174 2.21232,-56.92245 -13.93983,-79.3422 -34.56287,-99.96524 -22.67355,-19.67717 -60.67027,-30.06998 -90.99892,-30.06998 -27.77921,6.9e-4 -68.46735,8.08871 -87.7666,25.37047 -25.93817,17.28308 -65.23747,73.70611 -57.04687,130.54577 l -194.516943,1.70222 c 0,-157.21399 29.393699,-198.69465 99.004113,-263.03032 67.39739,-54.376643 126.53128,-73.268365 243.84757,-73.268365 89.71791,0 161.89728,17.80281 214.32552,53.405855 71.20714,48.12472 122.30105,111.18354 122.30105,230.11281 -6.9e-4,44.32081 -19.15253,90.78638 -43.0726,128.33299 -18.38947,30.90938 -60.37511,66.45236 -118.21237,104.41628 -42.83607,25.7686 -66.67196,53.11926 -77.03964,72.0946 -10.36863,18.97603 -15.55271,43.72267 -15.55225,74.23999 z" + style="font-style:normal;font-weight:normal;font-size:1201.92492676px;font-family:'Bitstream Vera Sans';text-align:center;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" + id="path11472" + inkscape:connector-curvature="0" /> + id="path11474" + inkscape:connector-curvature="0" /> diff --git a/client/public/images/pieces/Hidden/wp.svg b/client/public/images/pieces/Hidden/wp.svg index c7792aa8..e5016228 100644 --- a/client/public/images/pieces/Hidden/wp.svg +++ b/client/public/images/pieces/Hidden/wp.svg @@ -10,10 +10,10 @@ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" version="1.0" - width="679.47827" + width="881.47827" height="881.67249" id="svg11382" - sodipodi:docname="wwp.svg" + sodipodi:docname="wp.svg" inkscape:version="0.92.4 5da689c313, 2019-01-14"> @@ -36,7 +36,7 @@ guidetolerance="10" inkscape:pageopacity="0" inkscape:pageshadow="2" - inkscape:window-width="1920" + inkscape:window-width="960" inkscape:window-height="1180" id="namedview8" showgrid="false" @@ -50,39 +50,41 @@ + d="M 474.50888,718.22841 H 303.49547 v -22.30134 c -2.4e-4,-37.95108 4.30352,-68.76211 12.9113,-92.43319 8.60728,-23.67032 23.63352,-45.28695 40.65324,-64.84996 17.01914,-19.56211 41.98734,-26.33264 101.45793,-75.63085 31.69095,-25.82203 55.2813,-77.1523 55.28175,-98.67174 2.21232,-56.92245 -13.93983,-79.3422 -34.56287,-99.96524 -22.67355,-19.67717 -60.67027,-30.06998 -90.99892,-30.06998 -27.77921,6.9e-4 -68.46735,8.08871 -87.7666,25.37047 -25.93817,17.28308 -65.23747,73.70611 -57.04687,130.54577 l -194.516943,1.70222 c 0,-157.21399 29.393699,-198.69465 99.004113,-263.03032 67.39739,-54.376643 126.53128,-73.268365 243.84757,-73.268365 89.71791,0 161.89728,17.80281 214.32552,53.405855 71.20714,48.12472 122.30105,111.18354 122.30105,230.11281 -6.9e-4,44.32081 -19.15253,90.78638 -43.0726,128.33299 -18.38947,30.90938 -60.37511,66.45236 -118.21237,104.41628 -42.83607,25.7686 -66.67196,53.11926 -77.03964,72.0946 -10.36863,18.97603 -15.55271,43.72267 -15.55225,74.23999 z" + style="font-style:normal;font-weight:normal;font-size:1201.92492676px;font-family:'Bitstream Vera Sans';text-align:center;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" + id="path11472" + inkscape:connector-curvature="0" /> + id="path11474" + inkscape:connector-curvature="0" /> diff --git a/client/src/base_rules.js b/client/src/base_rules.js index a47b853f..da9fab78 100644 --- a/client/src/base_rules.js +++ b/client/src/base_rules.js @@ -1261,7 +1261,7 @@ export const ChessRules = class ChessRules { // TODO: un-ambiguous notation (switch on piece type, check directions...) getNotation(move) { if (move.appear.length == 2 && move.appear[0].p == V.KING) - //castle + // Castle return move.end.y < move.start.y ? "0-0-0" : "0-0"; // Translate final square 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 + ); + } };