Draft of Antiking variant
authorBenjamin Auder <benjamin.auder@somewhere>
Mon, 19 Nov 2018 17:20:27 +0000 (18:20 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Mon, 19 Nov 2018 17:20:27 +0000 (18:20 +0100)
public/images/pieces/Antiking/ba.svg [new file with mode: 0644]
public/images/pieces/Antiking/wa.svg [new file with mode: 0644]
public/javascripts/components/game.js
public/javascripts/variants/Antiking.js [new file with mode: 0644]

diff --git a/public/images/pieces/Antiking/ba.svg b/public/images/pieces/Antiking/ba.svg
new file mode 100644 (file)
index 0000000..27fc9b3
--- /dev/null
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<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"
+   height="100%"
+   width="100%"
+   version="1.1"
+   viewBox="0 0 2048 2048"
+   id="svg18"
+   sodipodi:docname="ba.svg"
+   inkscape:version="0.92.2 2405546, 2018-03-11">
+  <metadata
+     id="metadata24">
+    <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>
+  <defs
+     id="defs22" />
+  <sodipodi:namedview
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1"
+     objecttolerance="10"
+     gridtolerance="10"
+     guidetolerance="10"
+     inkscape:pageopacity="0"
+     inkscape:pageshadow="2"
+     inkscape:window-width="960"
+     inkscape:window-height="1180"
+     id="namedview20"
+     showgrid="false"
+     inkscape:zoom="0.11523438"
+     inkscape:cx="1041.3559"
+     inkscape:cy="1024"
+     inkscape:window-x="0"
+     inkscape:window-y="20"
+     inkscape:window-maximized="0"
+     inkscape:current-layer="svg18" />
+  <g
+     id="g8"
+     transform="matrix(1,0,0,-1,0,2048)"
+     style="fill:#ffffff;fill-rule:nonzero">
+    <path
+       style="color:#000000;display:block"
+       d="m 1060,1261 q 172,3 282,17 110,14 198,33 55,-54 122,-103 67,-49 94,-84 48,-65 48,-162 0,-89 -43,-149 -77,-113 -235,-113 -92,0 -192,40 -91,36 -132,78 -85,82 -124,216 -15,46 -16,117 -1,71 -2,110 z"
+       display="block"
+       id="path2"
+       inkscape:connector-curvature="0" />
+    <path
+       style="color:#000000;display:block"
+       d="m 988,1260 q 0,-40 -2,-110 -2,-70 -15,-118 Q 930,898 847,816 804,774 715,738 613,698 522,698 q -158,0 -234,113 -43,60 -43,150 0,98 48,161 25,36 96,89 71,53 120,98 87,-19 196,-33 109,-14 283,-16 z"
+       display="block"
+       id="path4"
+       inkscape:connector-curvature="0" />
+    <path
+       style="color:#000000;display:block"
+       d="m 1024,1009 q 7,-28 12,-39 10,-39 23,-66 6,-17 17,-39 11,-22 25,-52 8,-17 17,-41 9,-24 18,-49 8,-20 8,-43 0,-49 -35,-83 -35,-34 -85,-35 -119,0 -119,119 0,23 8,43 22,65 34,90 13,29 24,51 11,22 19,40 13,33 22,66 2,6 12,38 z"
+       display="block"
+       id="path6"
+       inkscape:connector-curvature="0" />
+  </g>
+  <g
+     id="g16"
+     transform="matrix(1,0,0,-1,0,2048)"
+     style="fill-rule:nonzero">
+    <path
+       style="color:#000000;display:block;fill:#000000"
+       d="m 1133,865 q 0,29 6,82 6,53 21,84 37,81 106,150 20,20 86,54 65,32 139,32 56,0 111,-19 55,-19 84,-60 25,-34 25,-110 0,-60 -49,-112 -32,-33 -69,-66 -37,-33 -71,-79 -58,20 -161,31 -103,11 -228,13 z m -73,-78 q 172,-3 282,-17 110,-14 198,-33 55,54 122,103 67,49 94,84 48,65 48,162 0,89 -43,149 -77,113 -235,113 -92,0 -192,-40 -91,-36 -132,-78 -85,-82 -124,-216 -15,-46 -16,-117 -1,-71 -2,-110 z m 458,-173 q -184,51 -490,51 -308,0 -496,-52 l 15,-101 q 189,49 481,49 291,0 474,-48 z m 26,-299 -30,118 q -195,45 -490,45 -292,0 -488,-45 L 504,314 q 190,58 521,58 159,0 295,-16 136,-16 224,-41 z M 463,522 430,709 q -1,0 -3,4 -5,7 -28,18 -23,11 -55,40 -44,37 -68,60 -24,23 -45,50 -61,84 -68,203 -10,115 93,229 104,114 281,107 66,-4 155,-32 29,-12 59,-23 30,-11 61,-24 16,-8 28,-16 -5,21 -5,42 0,78 55,133 55,55 134,56 78,0 133,-55 55,-55 55,-133 0,-16 -4,-42 14,9 27,15 46,20 121,47 86,29 155,33 177,8 280,-107 101,-114 94,-229 -8,-119 -69,-203 -20,-27 -45,-50 -25,-23 -67,-60 -33,-28 -56,-39 -23,-11 -27,-19 -1,-2 -2,-3 -1,-1 -1,-2 l -32,-188 66,-247 q -50,-45 -224,-74 -174,-29 -402,-29 -232,0 -408,30 -176,30 -221,77 z m 525,266 q 0,40 -2,110 -2,70 -15,118 -41,134 -124,216 -43,42 -132,78 -102,40 -193,40 -158,0 -234,-113 -43,-60 -43,-150 0,-98 48,-161 25,-36 96,-89 71,-53 120,-98 87,19 196,33 109,14 283,16 z m 36,251 q 7,28 12,39 10,39 23,66 6,17 17,39 11,22 25,52 8,17 17,41 9,24 18,49 8,20 8,43 0,49 -35,83 -35,34 -85,35 -119,0 -119,-119 0,-23 8,-43 22,-65 34,-90 13,-29 24,-51 11,-22 19,-40 13,-33 22,-66 2,-6 12,-38 z m 35,520 h -71 v 131 h -83 q -34,0 -34,33 v 1 q 0,33 34,33 h 83 v 85 q 0,35 36,35 35,0 35,-35 v -85 h 86 q 33,0 33,-33 v -1 q 0,-33 -33,-33 l -85,-1 z M 912,865 Q 787,863 684,852 581,841 523,821 q -30,37 -69,74 -39,37 -70,71 -50,51 -50,112 0,75 25,110 27,40 83,59 56,19 113,20 72,0 138,-32 65,-34 86,-54 68,-69 106,-150 13,-30 19,-83 6,-53 8,-83 z m 112,345 q -2,10 -5,17 -6,20 -10,29 -3,7 -8,17 -5,10 -10,23 -3,7 -7,18 -4,11 -8,22 -3,9 -3,19 0,53 51,53 53,0 53,-52 0,-13 -4,-19 -14,-38 -15,-41 -15,-30 -19,-39 -7,-16 -9,-29 -3,-6 -4,-10 -1,-4 -2,-8 z"
+       transform="matrix(1,0,0,-1,0,2048)"
+       display="block"
+       id="path10"
+       inkscape:connector-curvature="0" />
+    <path
+       style="color:#000000;display:block;fill:#ffffff"
+       d="m 1518,1434 q -184,-51 -490,-51 -308,0 -496,52 l 15,101 q 189,-49 481,-49 291,0 474,48 z"
+       display="block"
+       id="path12"
+       inkscape:connector-curvature="0" />
+    <path
+       style="color:#000000;display:block;fill:#ffffff"
+       d="m 1544,1733 -30,-118 q -195,-45 -490,-45 -292,0 -488,45 l -32,119 q 190,-58 521,-58 159,0 295,16 136,16 224,41 z"
+       display="block"
+       id="path14"
+       inkscape:connector-curvature="0" />
+  </g>
+</svg>
diff --git a/public/images/pieces/Antiking/wa.svg b/public/images/pieces/Antiking/wa.svg
new file mode 100644 (file)
index 0000000..cb86a77
--- /dev/null
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<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"
+   height="100%"
+   width="100%"
+   version="1.1"
+   viewBox="0 0 2048 2048"
+   id="svg18"
+   sodipodi:docname="wa.svg"
+   inkscape:version="0.92.2 2405546, 2018-03-11">
+  <metadata
+     id="metadata24">
+    <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>
+  <defs
+     id="defs22" />
+  <sodipodi:namedview
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1"
+     objecttolerance="10"
+     gridtolerance="10"
+     guidetolerance="10"
+     inkscape:pageopacity="0"
+     inkscape:pageshadow="2"
+     inkscape:window-width="960"
+     inkscape:window-height="1180"
+     id="namedview20"
+     showgrid="false"
+     inkscape:zoom="0.11523438"
+     inkscape:cx="1041.3559"
+     inkscape:cy="1024"
+     inkscape:window-x="0"
+     inkscape:window-y="20"
+     inkscape:window-maximized="0"
+     inkscape:current-layer="svg18" />
+  <path
+     style="color:#000000;display:block;fill:#000000;fill-rule:nonzero"
+     d="m 524,583 q 190,48 504,48 308,0 497,-46 l 25,147 q -201,53 -526,53 -327,0 -525,-54 z m -61,-61 -33,187 q -1,0 -3,4 -5,7 -28,18 -23,11 -55,40 -44,37 -68,60 -24,23 -45,50 -61,84 -68,203 -10,115 93,229 104,114 281,107 66,-4 155,-32 29,-12 59,-23 30,-11 61,-24 16,-8 28,-16 -5,21 -5,42 0,78 55,133 55,55 134,56 78,0 133,-55 55,-55 55,-133 0,-16 -4,-42 14,9 27,15 46,20 121,47 86,29 155,33 177,8 280,-107 101,-114 94,-229 -8,-119 -69,-203 -20,-27 -45,-50 -25,-23 -67,-60 -33,-28 -56,-39 -23,-11 -27,-19 -1,-2 -2,-3 -1,-1 -1,-2 l -32,-188 66,-247 q -50,-45 -224,-74 -174,-29 -402,-29 -232,0 -408,30 -176,30 -221,77 z m 1081,-117 -30,115 q -198,44 -490,44 -291,0 -489,-44 L 503,404 q 191,56 522,56 329,0 519,-55 z m 26,-94 q -193,78 -542,78 -362,0 -548,-80 176,-70 545,-70 176,0 321,19 145,19 224,53 z M 989,853 q -1,39 -3,77 -2,38 -15,86 -41,134 -124,216 -43,42 -132,78 -102,40 -193,40 -158,0 -234,-113 -43,-60 -43,-150 0,-98 48,-161 29,-37 74,-74 45,-37 84,-67 175,63 538,68 z m 35,186 q 7,28 12,39 10,39 23,66 6,17 17,39 11,22 25,52 8,17 17,41 9,24 18,49 8,20 8,43 0,49 -35,83 -35,34 -85,35 -119,0 -119,-119 0,-23 8,-43 22,-65 34,-90 13,-29 24,-51 11,-22 19,-40 13,-33 22,-66 2,-6 12,-38 z m 34,-186 q 172,-2 315,-20 143,-18 224,-47 38,30 83,66 45,36 75,75 48,61 48,161 0,90 -43,150 -77,112 -234,112 -94,0 -193,-39 -87,-35 -132,-78 -84,-84 -124,-216 -14,-47 -16,-85 -2,-38 -3,-79 z m 1,706 h -71 v 131 h -83 q -34,0 -34,33 v 1 q 0,33 34,33 h 83 v 85 q 0,35 36,35 35,0 35,-35 v -85 h 86 q 33,0 33,-33 v -1 q 0,-33 -33,-33 l -85,-1 z"
+     display="block"
+     id="path2"
+     inkscape:connector-curvature="0" />
+  <g
+     id="g16"
+     transform="matrix(1,0,0,-1,0,2048)"
+     style="fill:#ffffff;fill-rule:nonzero">
+    <path
+       style="color:#000000;display:block"
+       d="m 524,1465 q 190,-48 504,-48 308,0 497,46 l 25,-147 q -201,-53 -526,-53 -327,0 -525,54 z"
+       display="block"
+       id="path4"
+       inkscape:connector-curvature="0" />
+    <path
+       style="color:#000000;display:block"
+       d="m 1544,1643 -30,-115 q -198,-44 -490,-44 -291,0 -489,44 l -32,116 q 191,-56 522,-56 329,0 519,55 z"
+       display="block"
+       id="path6"
+       inkscape:connector-curvature="0" />
+    <path
+       style="color:#000000;display:block"
+       d="m 1570,1737 q -193,-78 -542,-78 -362,0 -548,80 176,70 545,70 176,0 321,-19 145,-19 224,-53 z"
+       display="block"
+       id="path8"
+       inkscape:connector-curvature="0" />
+    <path
+       style="color:#000000;display:block"
+       d="m 989,1195 q -1,-39 -3,-77 -2,-38 -15,-86 Q 930,898 847,816 804,774 715,738 613,698 522,698 q -158,0 -234,113 -43,60 -43,150 0,98 48,161 29,37 74,74 45,37 84,67 175,-63 538,-68 z"
+       display="block"
+       id="path10"
+       inkscape:connector-curvature="0" />
+    <path
+       style="color:#000000;display:block"
+       d="m 1024,1009 q 7,-28 12,-39 10,-39 23,-66 6,-17 17,-39 11,-22 25,-52 8,-17 17,-41 9,-24 18,-49 8,-20 8,-43 0,-49 -35,-83 -35,-34 -85,-35 -119,0 -119,119 0,23 8,43 22,65 34,90 13,29 24,51 11,22 19,40 13,33 22,66 2,6 12,38 z"
+       display="block"
+       id="path12"
+       inkscape:connector-curvature="0" />
+    <path
+       style="color:#000000;display:block"
+       d="m 1058,1195 q 172,2 315,20 143,18 224,47 38,-30 83,-66 45,-36 75,-75 48,-61 48,-161 0,-90 -43,-150 -77,-112 -234,-112 -94,0 -193,39 -87,35 -132,78 -84,84 -124,216 -14,47 -16,85 -2,38 -3,79 z"
+       display="block"
+       id="path14"
+       inkscape:connector-curvature="0" />
+  </g>
+</svg>
index 3eb27f2..147aeaf 100644 (file)
@@ -668,7 +668,7 @@ Vue.component('my-game', {
                                this.selectedPiece.style.display = "inline-block";
                                this.selectedPiece.style.zIndex = 3000;
                                let startSquare = this.getSquareFromId(e.target.parentNode.id);
-                               this.possibleMoves = this.vr.canIplay(this.mycolor,startSquare)
+                               this.possibleMoves = this.mode!="idle" && this.vr.canIplay(this.mycolor,startSquare)
                                        ? this.vr.getPossibleMovesFrom(startSquare)
                                        : [];
                                e.target.parentNode.appendChild(this.selectedPiece);
diff --git a/public/javascripts/variants/Antiking.js b/public/javascripts/variants/Antiking.js
new file mode 100644 (file)
index 0000000..ddfd967
--- /dev/null
@@ -0,0 +1,173 @@
+class AntikingRules
+{
+       // Path to pieces
+       static getPpath(b)
+       {
+               return b[1]=='a' ? "Antiking/"+b : b;
+       }
+
+       static get ANTIKING() { return 'a'; }
+
+       // TODO: more subtle than that, require changing args: wp, bk and not just colors
+       canTake(color1, color2)
+       {
+               return color1 != color2;
+       }
+
+       getPotentialMovesFrom([x,y])
+       {
+               let c = this.getColor(x,y);
+               switch (this.getPiece(x,y))
+               {
+                       case VariantRules.ANTIKING:
+                               return this.getPotentialAntikingMoves(x,y,c);
+                       default:
+                               return super.getPotentielMovesFrom([x,y]);
+               }
+       }
+
+       getPotentialAntikingMoves(x, y, c)
+       {
+               // TODO
+       }
+
+// TODO: need to re-think some logic, since antikings capture same color
+
+       isAttacked(sq, color)
+       {
+               return (this.isAttackedByPawn(sq, color)
+                       || this.isAttackedByRook(sq, color)
+                       || this.isAttackedByKnight(sq, color)
+                       || this.isAttackedByBishop(sq, color)
+                       || this.isAttackedByQueen(sq, color)
+                       || this.isAttackedByKing(sq, color)); //...
+       }
+
+       isAttackedByAntiking(sq, color)
+       {
+               // TODO
+       }
+
+       underCheck(move, c)
+       {
+               this.play(move);
+               let res = this.isAttacked(this.kingPos[c], this.getOppCol(c));
+               // TODO: also check that antiking is still in check
+               this.undo(move);
+               return res;
+       }
+
+       getCheckSquares(move, c)
+       {
+               this.play(move);
+               // TODO
+               let res = this.isAttacked(this.kingPos[c], this.getOppCol(c))
+                       ? [ JSON.parse(JSON.stringify(this.kingPos[c])) ] //need to duplicate!
+                       : [ ];
+               this.undo(move);
+               return res;
+       }
+
+       // Apply a move on board
+       static PlayOnBoard(board, move)
+       {
+               for (let psq of move.vanish)
+                       board[psq.x][psq.y] = VariantRules.EMPTY;
+               for (let psq of move.appear)
+                       board[psq.x][psq.y] = psq.c + psq.p;
+       }
+       // Un-apply the played move
+       static UndoOnBoard(board, move)
+       {
+               for (let psq of move.appear)
+                       board[psq.x][psq.y] = VariantRules.EMPTY;
+               for (let psq of move.vanish)
+                       board[psq.x][psq.y] = psq.c + psq.p;
+       }
+
+       // TODO: need antikingPos as well
+       updateVariables(move)
+       {
+               // ...
+       }
+
+       unupdateVariables(move)
+       {
+               // TODO
+       }
+
+       checkGameEnd(color)
+       {
+               // TODO
+               if (!this.isAttacked(this.kingPos[color], this.getOppCol(color)))
+                       return "1/2";
+               return color == "w" ? "0-1" : "1-0";
+       }
+
+       // Pieces values
+       static get VALUES() {
+               return {
+                       'p': 1,
+                       'r': 5,
+                       'n': 3,
+                       'b': 3,
+                       'q': 9,
+                       'k': 1000,
+                       'a': 1000
+               };
+       }
+
+       static GenRandInitFen()
+       {
+               // TODO: no need all code, just add an antiking at rondom on 3rd ranks
+               let pieces = [new Array(8), new Array(8)];
+               // Shuffle pieces on first and last rank
+               for (let c = 0; c <= 1; c++)
+               {
+                       let positions = _.range(8);
+
+                       // Get random squares for bishops
+                       let randIndex = 2 * _.random(3);
+                       let bishop1Pos = positions[randIndex];
+                       // The second bishop must be on a square of different color
+                       let randIndex_tmp = 2 * _.random(3) + 1;
+                       let bishop2Pos = positions[randIndex_tmp];
+                       // Remove chosen squares
+                       positions.splice(Math.max(randIndex,randIndex_tmp), 1);
+                       positions.splice(Math.min(randIndex,randIndex_tmp), 1);
+
+                       // Get random squares for knights
+                       randIndex = _.random(5);
+                       let knight1Pos = positions[randIndex];
+                       positions.splice(randIndex, 1);
+                       randIndex = _.random(4);
+                       let knight2Pos = positions[randIndex];
+                       positions.splice(randIndex, 1);
+
+                       // Get random square for queen
+                       randIndex = _.random(3);
+                       let queenPos = positions[randIndex];
+                       positions.splice(randIndex, 1);
+
+                       // Rooks and king positions are now fixed, because of the ordering rook-king-rook
+                       let rook1Pos = positions[0];
+                       let kingPos = positions[1];
+                       let rook2Pos = positions[2];
+
+                       // 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';
+               }
+               let fen = pieces[0].join("") +
+                       "/pppppppp/8/8/8/8/PPPPPPPP/" +
+                       pieces[1].join("").toUpperCase() +
+                       " 1111"; //add flags
+               return fen;
+       }
+}