From b91392511d5df54b0e3cd5fcf439471cc6767804 Mon Sep 17 00:00:00 2001 From: Benjamin Auder <benjamin.auder@somewhere> Date: Mon, 24 Feb 2020 15:52:36 +0100 Subject: [PATCH] HiddenRules almost OK (need to ignore checks. Position kings on first rank?). window.V reactive in BaseGame? --- .../pieces/Hidden/Question_mark_alternate.svg | 28 +++++ client/public/images/pieces/Hidden/bp.svg | 68 +++++++++++ client/public/images/pieces/Hidden/wp.svg | 88 ++++++++++++++ client/src/components/BaseGame.vue | 7 +- client/src/variants/Hidden.js | 109 ++++++++++++++---- client/src/views/Rules.vue | 7 +- 6 files changed, 278 insertions(+), 29 deletions(-) create mode 100644 client/public/images/pieces/Hidden/Question_mark_alternate.svg create mode 100644 client/public/images/pieces/Hidden/bp.svg create mode 100644 client/public/images/pieces/Hidden/wp.svg diff --git a/client/public/images/pieces/Hidden/Question_mark_alternate.svg b/client/public/images/pieces/Hidden/Question_mark_alternate.svg new file mode 100644 index 00000000..f88ab1e3 --- /dev/null +++ b/client/public/images/pieces/Hidden/Question_mark_alternate.svg @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> +<svg + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + version="1.0" + width="679.47827" + height="881.67249" + id="svg11382"> + <defs + id="defs11384" /> + <g + transform="translate(-48.907487,-55.625885)" + id="layer1"> + <g + id="g11476"> + <path + d="M 474.50888,718.22841 L 303.49547,718.22841 L 303.49547,695.92707 C 303.49523,657.97599 307.79899,627.16496 316.40677,603.49388 C 325.01405,579.82356 340.04029,558.20693 357.06001,538.64392 C 374.07915,519.08181 399.04735,512.31128 458.51794,463.01307 C 490.20889,437.19104 513.79924,385.86077 513.79969,364.34133 C 516.01201,307.41888 499.85986,284.99913 479.23682,264.37609 C 456.56327,244.69892 418.56655,234.30611 388.2379,234.30611 C 360.45869,234.3068 319.77055,242.39482 300.4713,259.67658 C 274.53313,276.95966 235.23383,333.38269 243.42443,390.22235 L 48.907487,391.92457 C 48.907487,234.71058 78.301186,193.22992 147.9116,128.89425 C 215.30899,74.517607 274.44288,55.625885 391.75917,55.625885 C 481.47708,55.625885 553.65645,73.428695 606.08469,109.03174 C 677.29183,157.15646 728.38574,220.21528 728.38574,339.14455 C 728.38505,383.46536 709.23321,429.93093 685.31314,467.47754 C 666.92367,498.38692 624.93803,533.9299 567.10077,571.89382 C 524.2647,597.66242 500.42881,625.01308 490.06113,643.98842 C 479.6925,662.96445 474.50842,687.71109 474.50888,718.22841 L 474.50888,718.22841 z " + style="font-size:1201.92492676px;font-style:normal;font-weight:normal;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;font-family:Bitstream Vera Sans" + id="path11472" /> + <path + d="M 482.38298 869.80902 A 94.042557 73.021278 0 1 1 294.29787,869.80902 A 94.042557 73.021278 0 1 1 482.38298 869.80902 z" + transform="translate(1.106383,-5.5319149)" + style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" + id="path11474" /> + </g> + </g> +</svg> diff --git a/client/public/images/pieces/Hidden/bp.svg b/client/public/images/pieces/Hidden/bp.svg new file mode 100644 index 00000000..ba3ff2ef --- /dev/null +++ b/client/public/images/pieces/Hidden/bp.svg @@ -0,0 +1,68 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + version="1.0" + width="679.47827" + height="881.67249" + id="svg11382" + sodipodi:docname="wp.svg" + inkscape:version="0.92.4 5da689c313, 2019-01-14"> + <metadata + id="metadata10"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <sodipodi:namedview + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1" + objecttolerance="10" + gridtolerance="10" + guidetolerance="10" + inkscape:pageopacity="0" + inkscape:pageshadow="2" + inkscape:window-width="1920" + inkscape:window-height="1180" + id="namedview8" + showgrid="false" + inkscape:zoom="0.26767309" + inkscape:cx="347.21094" + inkscape:cy="440.83624" + inkscape:window-x="0" + inkscape:window-y="20" + inkscape:window-maximized="0" + inkscape:current-layer="svg11382" /> + <defs + id="defs11384" /> + <g + transform="translate(-48.907487,-55.625885)" + id="layer1"> + <g + id="g11476"> + <path + d="M 474.50888,718.22841 L 303.49547,718.22841 L 303.49547,695.92707 C 303.49523,657.97599 307.79899,627.16496 316.40677,603.49388 C 325.01405,579.82356 340.04029,558.20693 357.06001,538.64392 C 374.07915,519.08181 399.04735,512.31128 458.51794,463.01307 C 490.20889,437.19104 513.79924,385.86077 513.79969,364.34133 C 516.01201,307.41888 499.85986,284.99913 479.23682,264.37609 C 456.56327,244.69892 418.56655,234.30611 388.2379,234.30611 C 360.45869,234.3068 319.77055,242.39482 300.4713,259.67658 C 274.53313,276.95966 235.23383,333.38269 243.42443,390.22235 L 48.907487,391.92457 C 48.907487,234.71058 78.301186,193.22992 147.9116,128.89425 C 215.30899,74.517607 274.44288,55.625885 391.75917,55.625885 C 481.47708,55.625885 553.65645,73.428695 606.08469,109.03174 C 677.29183,157.15646 728.38574,220.21528 728.38574,339.14455 C 728.38505,383.46536 709.23321,429.93093 685.31314,467.47754 C 666.92367,498.38692 624.93803,533.9299 567.10077,571.89382 C 524.2647,597.66242 500.42881,625.01308 490.06113,643.98842 C 479.6925,662.96445 474.50842,687.71109 474.50888,718.22841 L 474.50888,718.22841 z " + style="font-size:1201.92492676px;font-style:normal;font-weight:normal;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;font-family:Bitstream Vera Sans" + id="path11472" /> + <path + d="M 482.38298 869.80902 A 94.042557 73.021278 0 1 1 294.29787,869.80902 A 94.042557 73.021278 0 1 1 482.38298 869.80902 z" + transform="translate(1.106383,-5.5319149)" + style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" + id="path11474" /> + </g> + </g> +</svg> diff --git a/client/public/images/pieces/Hidden/wp.svg b/client/public/images/pieces/Hidden/wp.svg new file mode 100644 index 00000000..c7792aa8 --- /dev/null +++ b/client/public/images/pieces/Hidden/wp.svg @@ -0,0 +1,88 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + version="1.0" + width="679.47827" + height="881.67249" + id="svg11382" + sodipodi:docname="wwp.svg" + inkscape:version="0.92.4 5da689c313, 2019-01-14"> + <metadata + id="metadata10"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <sodipodi:namedview + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1" + objecttolerance="10" + gridtolerance="10" + guidetolerance="10" + inkscape:pageopacity="0" + inkscape:pageshadow="2" + inkscape:window-width="1920" + inkscape:window-height="1180" + id="namedview8" + showgrid="false" + inkscape:zoom="0.26767309" + inkscape:cx="347.21094" + inkscape:cy="440.83624" + inkscape:window-x="0" + inkscape:window-y="20" + inkscape:window-maximized="0" + inkscape:current-layer="svg11382" /> + <defs + id="defs11384" /> + <g + transform="translate(-48.907487,-55.625885)" + id="layer1"> + <g + id="g11476"> + <path + d="M 474.50888,718.22841 L 303.49547,718.22841 L 303.49547,695.92707 C 303.49523,657.97599 307.79899,627.16496 316.40677,603.49388 C 325.01405,579.82356 340.04029,558.20693 357.06001,538.64392 C 374.07915,519.08181 399.04735,512.31128 458.51794,463.01307 C 490.20889,437.19104 513.79924,385.86077 513.79969,364.34133 C 516.01201,307.41888 499.85986,284.99913 479.23682,264.37609 C 456.56327,244.69892 418.56655,234.30611 388.2379,234.30611 C 360.45869,234.3068 319.77055,242.39482 300.4713,259.67658 C 274.53313,276.95966 235.23383,333.38269 243.42443,390.22235 L 48.907487,391.92457 C 48.907487,234.71058 78.301186,193.22992 147.9116,128.89425 C 215.30899,74.517607 274.44288,55.625885 391.75917,55.625885 C 481.47708,55.625885 553.65645,73.428695 606.08469,109.03174 C 677.29183,157.15646 728.38574,220.21528 728.38574,339.14455 C 728.38505,383.46536 709.23321,429.93093 685.31314,467.47754 C 666.92367,498.38692 624.93803,533.9299 567.10077,571.89382 C 524.2647,597.66242 500.42881,625.01308 490.06113,643.98842 C 479.6925,662.96445 474.50842,687.71109 474.50888,718.22841 L 474.50888,718.22841 z " + style="font-size:1201.92492676px;font-style:normal;font-weight:normal;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;font-family:Bitstream Vera Sans" + id="path11472" /> + <path + d="M 482.38298 869.80902 A 94.042557 73.021278 0 1 1 294.29787,869.80902 A 94.042557 73.021278 0 1 1 482.38298 869.80902 z" + transform="translate(1.106383,-5.5319149)" + style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" + id="path11474" /> + </g> + </g> + <path + style="fill:#e6e6e6;stroke-width:3.7359004" + d="m 257.60455,627.07088 c 0.13081,-77.44018 25.92758,-127.32449 87.73844,-169.66364 36.10448,-24.7308 69.51363,-51.56596 82.9554,-66.63206 4.58302,-5.13687 14.69139,-21.10784 22.46307,-35.49106 13.57063,-25.11543 14.12488,-27.55712 13.99245,-61.64235 -0.12067,-31.03639 -1.39133,-37.90025 -10.12433,-54.68556 -12.41589,-23.86391 -33.47102,-42.23034 -59.45872,-51.86591 -27.08357,-10.04189 -86.25805,-10.32199 -114.31527,-0.5411 -26.73994,9.32167 -56.16229,36.87598 -71.19845,66.67801 -12.64031,25.0534 -21.32123,61.95414 -17.44663,74.16193 2.2776,7.17608 0.0903,7.34753 -93.739582,7.34753 H 2.3993279 L 4.5888517,283.36804 C 6.9945044,226.9288 14.180975,193.63076 31.8012,157.28141 46.031888,127.92444 107.84181,64.930251 141.55337,45.4264 198.61102,12.415645 264.97592,-0.2328682 361.98916,3.4134533 476.57112,7.7201096 543.42976,33.528998 607.54842,98.204671 c 46.39163,46.794659 68.22289,103.293679 68.35689,176.906659 0.0803,44.05439 -6.37819,69.76065 -28.08594,111.79091 -23.51177,45.52307 -54.94907,76.31018 -129.2165,126.54395 -65.24529,44.1313 -88.21689,74.75462 -92.06838,122.7358 L 424.64188,659.76 H 341.0956 257.54933 Z" + id="path3734" + inkscape:connector-curvature="0" /> + <path + style="fill:#999999;stroke-width:3.7359004" + d="m 306.00164,874.67946 c -20.46793,-6.59916 -45.68973,-27.37932 -52.14398,-42.96126 -6.73547,-16.26085 -3.07431,-44.87763 7.58628,-59.29685 13.86628,-18.75515 48.4476,-34.20744 76.55425,-34.20744 91.51118,0 128.89948,87.78629 54.60914,128.22016 -23.77959,12.94247 -61.03582,16.48949 -86.60569,8.24539 z" + id="path3736" + inkscape:connector-curvature="0" /> + <path + style="fill:#e6e6e6;stroke-width:3.7359004" + d="m 259.4734,621.46703 c 6.28129,-88.10442 21.9745,-113.88938 108.80992,-178.78152 55.66017,-41.59491 67.14414,-53.85442 86.0333,-91.84351 13.00568,-26.15646 13.31169,-27.76551 11.72229,-61.64236 -1.86444,-39.7398 -8.47288,-56.12889 -31.65175,-78.49729 -25.62469,-24.72873 -45.10255,-30.98099 -96.51597,-30.98099 -38.83136,0 -47.33058,1.14717 -63.51031,8.57223 -20.63074,9.46769 -46.44195,32.55392 -60.02226,53.6855 -12.01718,18.69928 -24.0355,55.68115 -24.0355,73.96023 v 15.06145 l -23.34938,0.3724 c -17.42475,0.27791 -20.97953,1.13647 -14.00962,3.38367 5.13686,1.65621 -25.96451,2.09575 -69.114159,0.97677 C 40.680312,334.61463 4.887522,333.30392 4.290428,332.82093 3.693334,332.33794 4.9572298,307.77436 7.0990857,278.23519 13.95262,183.71542 26.403798,154.76712 85.716239,95.454679 119.27418,61.896737 130.81407,52.933841 157.09072,40.018961 213.43774,12.324601 235.64753,8.3160163 334.13529,8.0646743 426.84247,7.8280835 451.53707,11.036886 501.37436,29.795589 565.77034,54.034165 629.35924,112.05034 653.663,168.73814 c 12.78989,29.83208 18.97602,63.64202 19.0192,103.94882 0.0512,47.62706 -4.31896,67.19256 -23.87214,106.88052 -20.71912,42.05458 -55.31064,78.01535 -118.70203,123.40071 -76.01239,54.42142 -104.27787,89.69019 -104.49418,130.3846 -0.0299,5.27763 -1.06473,13.37826 -2.30371,18.00144 -2.24949,8.39401 -2.36785,8.40577 -84.40972,8.40577 h -82.15707 z" + id="path3743" + inkscape:connector-curvature="0" /> + <path + style="fill:#e6e6e6;stroke-width:3.7359004" + d="m 296.74909,867.65796 c -10.28868,-4.79119 -24.15821,-14.9202 -30.82118,-22.5089 -10.52965,-11.9926 -12.11448,-16.49295 -12.11448,-34.40061 0,-11.33164 2.49636,-25.43042 5.54748,-31.33063 17.25166,-33.36104 81.11165,-48.61019 124.82232,-29.80636 46.96314,20.203 59.64314,67.57433 26.86232,100.35515 -26.79593,26.79593 -77.79406,34.68967 -114.29646,17.69135 z" + id="path3745" + inkscape:connector-curvature="0" /> +</svg> diff --git a/client/src/components/BaseGame.vue b/client/src/components/BaseGame.vue index 42fe1897..07f6bba6 100644 --- a/client/src/components/BaseGame.vue +++ b/client/src/components/BaseGame.vue @@ -104,11 +104,16 @@ export default { cursor: -1, //index of the move just played lastMove: null, firstMoveNumber: 0, //for printing - incheck: [] //for Board + incheck: [], //for Board + V: null // TODO: need "local" V to trigger re-computation of computed properties ? + // --> le passer depuis CompGame ou Game comme une property ?! }; }, watch: { // game initial FEN changes when a new game starts + + // TODO: this watcher is obsolete ? + "game.fenStart": function() { this.re_setVariables(); }, diff --git a/client/src/variants/Hidden.js b/client/src/variants/Hidden.js index 1836352a..99b4a7a6 100644 --- a/client/src/variants/Hidden.js +++ b/client/src/variants/Hidden.js @@ -1,4 +1,4 @@ -import { ChessRules } from "@/base_rules"; +import { ChessRules, PiPo, Move } from "@/base_rules"; import { ArrayFun } from "@/utils/array"; import { randInt } from "@/utils/alea"; @@ -46,6 +46,14 @@ export const VariantRules = class HiddenRules extends ChessRules { return ChessRules.PIECES.concat(Object.values(V.HIDDEN_CODE)); } + // Pieces can be hidden :) + getPiece(i, j) { + const piece = this.board[i][j].charAt(1); + if (Object.keys(V.HIDDEN_DECODE).includes(piece)) + return V.HIDDEN_DECODE[piece]; + return piece; + } + // Scan board for kings positions (no castling) scanKingsRooks(fen) { this.kingPos = { w: [-1, -1], b: [-1, -1] }; @@ -84,9 +92,53 @@ export const VariantRules = class HiddenRules extends ChessRules { return b; } - //getPotentialMovesFrom: TODO: write + getBasicMove([sx, sy], [ex, ey], tr) { + let mv = new Move({ + appear: [ + new PiPo({ + x: ex, + y: ey, + c: tr ? tr.c : this.getColor(sx, sy), + p: tr ? tr.p : this.board[sx][sy].charAt(1) + }) + ], + vanish: [ + new PiPo({ + x: sx, + y: sy, + c: this.getColor(sx, sy), + p: this.board[sx][sy].charAt(1) + }) + ] + }); + + // The opponent piece disappears if we take it + if (this.board[ex][ey] != V.EMPTY) { + mv.vanish.push( + new PiPo({ + x: ex, + y: ey, + c: this.getColor(ex, ey), + p: this.board[ex][ey].charAt(1) + }) + ); + // 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]; + } + return mv; + } + + // What are the king moves from square x,y ? + getPotentialKingMoves(sq) { + // No castling: + return this.getSlideNJumpMoves( + sq, + V.steps[V.ROOK].concat(V.steps[V.BISHOP]), + "oneStep" + ); + } - // TODO: bishops on different colors, a1 --> h1, h2 --> a2 ? static GenRandInitFen() { let pieces = { w: new Array(8), b: new Array(8) }; // Shuffle pieces + pawns on two first ranks @@ -111,36 +163,43 @@ export const VariantRules = class HiddenRules extends ChessRules { const knight2Pos = positions[randIndex]; positions.splice(randIndex, 1); - // Get random square for queen + // Get random squares for rooks randIndex = randInt(12); + const rook1Pos = positions[randIndex]; + positions.splice(randIndex, 1); + randIndex = randInt(11); + const rook2Pos = positions[randIndex]; + positions.splice(randIndex, 1); + + // Get random square for queen + randIndex = randInt(10); const queenPos = positions[randIndex]; positions.splice(randIndex, 1); - // Get random squares for pawns - // TODO... + // Get random square for queen + randIndex = randInt(9); + const kingPos = positions[randIndex]; + positions.splice(randIndex, 1); - // Rooks and king positions are now fixed, - // because of the ordering rook-king-rook - const rook1Pos = positions[0]; - const kingPos = positions[1]; - const rook2Pos = positions[2]; + // Pawns position are all remaining slots: + for (let p of positions) + pieces[c][p] = "s"; // Finally put the shuffled pieces in the board array - pieces[c][rook1Pos] = "r"; - pieces[c][knight1Pos] = "n"; - pieces[c][bishop1Pos] = "b"; - pieces[c][queenPos] = "q"; - pieces[c][kingPos] = "k"; - pieces[c][bishop2Pos] = "b"; - pieces[c][knight2Pos] = "n"; - pieces[c][rook2Pos] = "r"; + pieces[c][rook1Pos] = "u"; + pieces[c][knight1Pos] = "o"; + pieces[c][bishop1Pos] = "c"; + pieces[c][queenPos] = "t"; + pieces[c][kingPos] = "l"; + pieces[c][bishop2Pos] = "c"; + pieces[c][knight2Pos] = "o"; + pieces[c][rook2Pos] = "u"; } - return ( - pieces["b"].join("") + - "/pppppppp/8/8/8/8/PPPPPPPP/" + - pieces["w"].join("").toUpperCase() + - " w 0" - ); + let upFen = pieces["b"].join(""); + upFen = upFen.substr(0,8) + "/" + upFen.substr(8); + let downFen = pieces["b"].join("").toUpperCase(); + downFen = downFen.substr(0,8) + "/" + downFen.substr(8); + return upFen + "/8/8/8/8/" + downFen + " w 0"; } getCheckSquares() { diff --git a/client/src/views/Rules.vue b/client/src/views/Rules.vue index 015df7b3..a8edf8f5 100644 --- a/client/src/views/Rules.vue +++ b/client/src/views/Rules.vue @@ -57,7 +57,8 @@ export default { gameInfo: { vname: "", mode: "versus", - } + }, + V: null, }; }, watch: { @@ -71,7 +72,7 @@ export default { }, computed: { showAnalyzeBtn: function() { - return (this.display=='rules' && (!window.V || V.CanAnalyze)); + return (this.display=='rules' && (!this.V || this.V.CanAnalyze)); }, content: function() { if (!this.gameInfo.vname) return ""; //variant not set yet @@ -112,7 +113,7 @@ export default { }, re_setVariant: async function(vname) { const vModule = await import("@/variants/" + vname + ".js"); - window.V = vModule.VariantRules; + this.V = window.V = vModule.VariantRules; this.gameInfo.vname = vname; }, startGame: function(mode) { -- 2.44.0