From: Benjamin Auder <benjamin.auder@somewhere> Date: Thu, 30 Jun 2022 17:13:19 +0000 (+0200) Subject: Fix Antiking X-Git-Url: https://git.auder.net/doc/html/pieces/img/vendor/%24%7BgetWhatsApp%28link%29%7D?a=commitdiff_plain;h=f3e90e30b6e7ff416afe288bc9dd865e5daf9860;p=xogo.git Fix Antiking --- diff --git a/base_rules.js b/base_rules.js index e3a34fb..b98c724 100644 --- a/base_rules.js +++ b/base_rules.js @@ -2162,10 +2162,11 @@ export default class ChessRules { ); } + // Argument is (very generally) an array of squares (= arrays) underCheck(square_s, oppCol) { if (this.options["taking"] || this.options["dark"]) return false; - if (!Array.isArray(square_s)) + if (!Array.isArray(square_s[0])) square_s = [square_s]; return square_s.some(sq => this.underAttack(sq, oppCol)); } @@ -2196,19 +2197,21 @@ export default class ChessRules { let newKingPP = null, sqIdx = 0, res = true; //a priori valid - const oldKingPP = m.vanish.find(v => this.isKing(0, 0, v.p) && v.c == color); + const oldKingPP = + m.vanish.find(v => this.isKing(0, 0, v.p) && v.c == color); if (oldKingPP) { // Search king in appear array: newKingPP = m.appear.find(a => this.isKing(0, 0, a.p) && a.c == color); if (newKingPP) { - sqIdx = kingPos.findIndex(kp => kp[0] == oldKingPP.x && kp[1] == oldKingPP[.y); + sqIdx = kingPos.findIndex(kp => + kp[0] == oldKingPP.x && kp[1] == oldKingPP.y); kingPos[sqIdx] = [newKingPP.x, newKingPP.y]; } else res = false; //king vanished } - res &&= !this.underCheck(square_s, oppCol); + res &&= !this.underCheck(kingPos, oppCol); if (oldKingPP && newKingPP) kingPos[sqIdx] = [oldKingPP.x, oldKingPP.y]; this.undoOnBoard(m); diff --git a/pieces/Antiking/black_antiking.svg b/pieces/Antiking/black_antiking.svg new file mode 100644 index 0000000..27fc9b3 --- /dev/null +++ b/pieces/Antiking/black_antiking.svg @@ -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/pieces/Antiking/white_antiking.svg b/pieces/Antiking/white_antiking.svg new file mode 100644 index 0000000..cb86a77 --- /dev/null +++ b/pieces/Antiking/white_antiking.svg @@ -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> diff --git a/pieces/Berolina/CREDITS b/pieces/Berolina/CREDITS new file mode 100644 index 0000000..5067a58 --- /dev/null +++ b/pieces/Berolina/CREDITS @@ -0,0 +1 @@ +https://greenchess.net/info.php?item=downloads diff --git a/pieces/Berolina/black_pawn.svg b/pieces/Berolina/black_pawn.svg new file mode 100644 index 0000000..7b2df98 --- /dev/null +++ b/pieces/Berolina/black_pawn.svg @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- + Berolina-gyalog (fekete) + Készült: a pawn-b.svg felhasználásával + Felhasználási feltételek: Nevezd meg! - Ãgy add tovább! (Creative Commons) + Uray M. János + 2014-2018 +--> +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> +<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="0 0 45 45"> + <g stroke="#000" stroke-width="2.0" stroke-linecap="round"> + <path d="M 22.5,11 L 22.5,8"/> + </g> + <g fill="#000" stroke="#000" stroke-width="1.5" stroke-linejoin="miter"> + <path d="M 22.5,11.41 + A 4,4,0 1,0 16.83,16.09 + C 15.88,17.27 15.35,18.71 15.35,20.3 C 15.35,22.53 16.38,24.52 18,25.83 + C 15.41,27.09 11,31.58 11,39.5 + L 34,39.5 + C 34,31.58 29.59,27.09 27,25.83 + C 28.62,24.52 29.65,22.53 29.65,20.3 C 29.65,18.71 29.12,17.27 28.17,16.09 + A 4,4,0 1,0 22.5,11.41 + "/> + </g> +</svg> diff --git a/pieces/Berolina/white_pawn.svg b/pieces/Berolina/white_pawn.svg new file mode 100644 index 0000000..e25862f --- /dev/null +++ b/pieces/Berolina/white_pawn.svg @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- + Berolina-gyalog (fehér) + Készült: a pawn-w.svg felhasználásával + Felhasználási feltételek: Nevezd meg! - Ãgy add tovább! (Creative Commons) + Uray M. János + 2014-2018 +--> +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> +<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="0 0 45 45"> + <g stroke="#000" stroke-width="2.0" stroke-linecap="round"> + <path d="M 22.5,11 L 22.5,8"/> + </g> + <g fill="#FFF" stroke="#000" stroke-width="1.5" stroke-linejoin="miter"> + <path d="M 22.5,11.41 + A 4,4,0 1,0 16.83,16.09 + C 15.88,17.27 15.35,18.71 15.35,20.3 C 15.35,22.53 16.38,24.52 18,25.83 + C 15.41,27.09 11,31.58 11,39.5 + L 34,39.5 + C 34,31.58 29.59,27.09 27,25.83 + C 28.62,24.52 29.65,22.53 29.65,20.3 C 29.65,18.71 29.12,17.27 28.17,16.09 + A 4,4,0 1,0 22.5,11.41 + "/> + </g> +</svg> diff --git a/variants.js b/variants.js index 18d5891..3705c59 100644 --- a/variants.js +++ b/variants.js @@ -5,7 +5,8 @@ const variants = [ {name: 'Align4', desc: 'Align four pawns'}, {name: 'Allmate', desc: 'Mate any piece'}, {name: 'Ambiguous', desc: "Play opponent's pieces"}, -// {name: 'Antiking1', desc: 'Keep antiking in check', disp: 'Anti-King'}, + {name: 'Antiking1', desc: 'Keep antiking in check', disp: 'Anti-King I'}, + {name: 'Antiking2', desc: 'Keep antiking in check', disp: 'Anti-King II'}, // {name: 'Antimatter', desc: 'Dangerous collisions'}, // {name: 'Apocalypse', desc: 'The end of the world'}, // {name: 'Arena', desc: 'Middle battle'}, diff --git a/variants/AbstractAntiking.js b/variants/AbstractAntiking.js deleted file mode 100644 index 7846add..0000000 --- a/variants/AbstractAntiking.js +++ /dev/null @@ -1,69 +0,0 @@ -import ChessRules from "/base_rules.js"; - -export class AbstractAntikingRules extends ChessRules { - - static get Options() { - return { - styles: [ - "atomic", - "balance", - "cannibal", - "capture", - "crazyhouse", - "doublemove", - "madrasi", - "progressive", - "recycle", - "rifle", - "teleport", - "zen" - ] - }; - } - - pieces(color, x, y) { - "a": { - // Move like a king, no attacks - "class": "antiking", - moves: super.pieces(color, x, y)['k'].moves, - attack: [] - } - } - - isKing(x, y, p) { - if (!p) - p = this.getPiece(x, y); - return ['k', 'a'].includes(p); - } - - canTake([x1, y1], [x2, y2]) { - const piece1 = this.getPiece(x1, y1); - const piece2 = this.getPiece(x2, y2); - const color1 = this.getColor(x1, y1); - const color2 = this.getColor(x2, y2); - return ( - piece2 != 'a' && - ( - (piece1 != 'a' && color1 != color2) || - (piece1 == 'a' && color1 == color2) - ) - ); - } - - underCheck(squares, color) { - const oppCol = C.GetOppCol(color); - let res = false; - squares.forEach(sq => { - switch (this.getPiece(sq[0], sq[1])) { - case 'k': - res ||= super.underAttack(sq, oppCol); - break; - case 'a': - res ||= !super.underAttack(sq, oppCol); - break; - } - }); - return res; - } - -}; diff --git a/variants/Alapo/class.js b/variants/Alapo/class.js index 881671f..4836413 100644 --- a/variants/Alapo/class.js +++ b/variants/Alapo/class.js @@ -1,6 +1,6 @@ import ChessRules from "/base_rules.js"; -import { ArrayFun } from "/utils/array.js"; -import { Random } from "/utils/alea.js"; +import {ArrayFun} from "/utils/array.js"; +import {Random} from "/utils/alea.js"; export default class AlapoRules extends ChessRules { diff --git a/variants/Alice/class.js b/variants/Alice/class.js index e755b56..e6d37b2 100644 --- a/variants/Alice/class.js +++ b/variants/Alice/class.js @@ -1,5 +1,5 @@ import ChessRules from "/base_rules.js"; -import { ArrayFun } from "/utils/array.js"; +import {ArrayFun} from "/utils/array.js"; export default class AliceRules extends ChessRules { @@ -105,7 +105,7 @@ export default class AliceRules extends ChessRules { filterValid(moves) { const color = this.turn; const oppCol = C.GetOppCol(color); - const kingPos = this.searchKingPos(color); + const kingPos = this.searchKingPos(color)[0]; const kingPiece = this.getPiece(kingPos[0], kingPos[1]); return super.filterValid(moves).filter(m => { // A move must also be legal on the board it is played: diff --git a/variants/Allmate/class.js b/variants/Allmate/class.js index 8d31649..5b237c0 100644 --- a/variants/Allmate/class.js +++ b/variants/Allmate/class.js @@ -82,7 +82,7 @@ export default class AllmateRules extends ChessRules { return true; } - underCheck([x, y], oppCol) { + underCheck() { return false; //not relevant here } diff --git a/variants/Ambiguous/class.js b/variants/Ambiguous/class.js index 58458b6..db24d0e 100644 --- a/variants/Ambiguous/class.js +++ b/variants/Ambiguous/class.js @@ -149,15 +149,14 @@ export default class AmbiguousRules extends ChessRules { getCurrentScore() { // This function is only called at subTurn 1 const color = C.GetOppCol(this.turn); - const kingPos = this.searchKingPos(color); - if (kingPos[0] < 0) + if (this.searchKingPos(color).length == 0) return (color == 'w' ? "0-1" : "1-0"); return "*"; } postPlay(move) { const color = this.turn; - if (this.subTurn == 2 || this.searchKingPos(color)[0] < 0) { + if (this.subTurn == 2 || this.searchKingPos(color).length == 0) { this.turn = C.GetOppCol(color); this.movesCount++; } diff --git a/variants/Antiking1/class.js b/variants/Antiking1/class.js index f8406b7..9b8af78 100644 --- a/variants/Antiking1/class.js +++ b/variants/Antiking1/class.js @@ -1,30 +1,14 @@ import ChessRules from "/base_rules.js"; -import AbstractAntikingRules from "/variants/AbstractAntiking.js"; +import AbstractAntikingRules from "/variants/_Antiking/class.js"; -export class Antiking1Rules extends AbstractAntikingRules { - - static get Options() { - return { - styles: [ - "atomic", - "balance", - "cannibal", - "capture", - "crazyhouse", - "doublemove", - "madrasi", - "progressive", - "recycle", - "rifle", - "teleport", - "zen" - ] - }; - } +export default class Antiking1Rules extends AbstractAntikingRules { get hasCastle() { return false; } + get hasEnpassant() { + return false; + } pieces(color, x, y) { const pawnShift = (color == "w" ? -1 : 1); @@ -53,11 +37,11 @@ export class Antiking1Rules extends AbstractAntikingRules { } // (Anti)King flags at 1 (true) if they can knight-jump - setFlags(fenflags) { + setFlags(fenFlags) { this.kingFlags = { w: {}, b: {} }; for (let i=0; i<fenFlags.length; i++) { const white = fenFlags.charCodeAt(i) <= 90; - const curChar = fenFlags.charCodeAt(i).toLowerCase(); + const curChar = fenFlags.charAt(i).toLowerCase(); this.kingFlags[white ? 'w' : 'b'][curChar] = true; } } @@ -73,11 +57,11 @@ export class Antiking1Rules extends AbstractAntikingRules { getPotentialMovesFrom([x, y]) { const color = this.turn; let moves = super.getPotentialMovesFrom([x, y]); - if (this.kingFlags[color][piece]) { + if (this.kingFlags[color][this.getPiece(x, y)]) { // Allow knight jump (king or antiking) const knightMoves = super.getPotentialMovesOf('n', [x, y]); // Remove captures (TODO: could be done more efficiently...) - moves = moves.concat(knightJumps.filter(m => m.vanish.length == 1)); + moves = moves.concat(knightMoves.filter(m => m.vanish.length == 1)); } return moves; } diff --git a/variants/Antiking1/rules.html b/variants/Antiking1/rules.html deleted file mode 100644 index fee723a..0000000 --- a/variants/Antiking1/rules.html +++ /dev/null @@ -1 +0,0 @@ -https://www.chessvariants.com/diffobjective.dir/anti-king-chess.html diff --git a/variants/Antiking1/rules.html b/variants/Antiking1/rules.html new file mode 120000 index 0000000..68d15a4 --- /dev/null +++ b/variants/Antiking1/rules.html @@ -0,0 +1 @@ +../_Antiking/rules.html \ No newline at end of file diff --git a/variants/Antiking1/style.css b/variants/Antiking1/style.css new file mode 100644 index 0000000..a6ffda1 --- /dev/null +++ b/variants/Antiking1/style.css @@ -0,0 +1,8 @@ +@import url("/variants/_Antiking/style.css"); + +piece.black.pawn { + background-image: url('/pieces/Berolina/black_pawn.svg'); +} +piece.white.pawn { + background-image: url('/pieces/Berolina/white_pawn.svg'); +} diff --git a/variants/Antiking2/class.js b/variants/Antiking2/class.js index 0e6a3e5..ee1030a 100644 --- a/variants/Antiking2/class.js +++ b/variants/Antiking2/class.js @@ -1,15 +1,12 @@ import ChessRules from "/base_rules.js"; -import AbstractAntikingRules from "/variants/AbstractAntiking.js"; -import { Random } from "/utils/alea.js"; +import AbstractAntikingRules from "/variants/_Antiking/class.js"; +import {Random} from "/utils/alea.js"; -export class Antiking2Rules extends AbstractAntikingRules { - - static get Aliases() { - return Object.assign({'A': AbstractAntikingRules}, ChessRules.Aliases); - } +export default class Antiking2Rules extends AbstractAntikingRules { static get Options() { return { + select: C.Options.select, styles: A.Options.styles.concat("cylinder") }; } @@ -25,9 +22,19 @@ export class Antiking2Rules extends AbstractAntikingRules { else akPos[1] = akPos[0]; } - const whiteLine = (akPos[0] > 0 ? akPos[0] : "") + 'A' + (akPos < this.size.y - 1 ? ...); - const blackLine = ... - return baseFen.replace(...) + const antikingLine = (color) => { + const [idx, symbol] = (color == 'w' ? [0, 'a'] : [1, 'A']); + return ( + (akPos[idx] > 0 ? akPos[idx] : "") + symbol + + (akPos[idx] < this.size.y - 1 + ? C.FenEmptySquares(this.size.y - 1 - akPos[idx]) + : "") + ); + }; + return ( + baseFen.replace("p/8", "p/" + antikingLine('b')) + .replace("8/P", antikingLine('w') + "/P") + ); } }; diff --git a/variants/Antiking2/rules.html b/variants/Antiking2/rules.html deleted file mode 100644 index fee723a..0000000 --- a/variants/Antiking2/rules.html +++ /dev/null @@ -1 +0,0 @@ -https://www.chessvariants.com/diffobjective.dir/anti-king-chess.html diff --git a/variants/Antiking2/rules.html b/variants/Antiking2/rules.html new file mode 120000 index 0000000..68d15a4 --- /dev/null +++ b/variants/Antiking2/rules.html @@ -0,0 +1 @@ +../_Antiking/rules.html \ No newline at end of file diff --git a/variants/Antiking2/style.css b/variants/Antiking2/style.css new file mode 120000 index 0000000..aee569a --- /dev/null +++ b/variants/Antiking2/style.css @@ -0,0 +1 @@ +../_Antiking/style.css \ No newline at end of file diff --git a/variants/Chakart/class.js b/variants/Chakart/class.js index 9a1cc6d..02dd16e 100644 --- a/variants/Chakart/class.js +++ b/variants/Chakart/class.js @@ -1,7 +1,7 @@ import ChessRules from "/base_rules.js"; import GiveawayRules from "/variants/Giveaway/class.js"; -import { ArrayFun } from "/utils/array.js"; -import { Random } from "/utils/alea.js"; +import {ArrayFun} from "/utils/array.js"; +import {Random} from "/utils/alea.js"; import PiPo from "/utils/PiPo.js"; import Move from "/utils/Move.js"; diff --git a/variants/Giveaway/class.js b/variants/Giveaway/class.js index 71f70be..69addf2 100644 --- a/variants/Giveaway/class.js +++ b/variants/Giveaway/class.js @@ -1,6 +1,6 @@ import ChessRules from "/base_rules.js"; -import { ArrayFun } from "/utils/array.js"; -import { Random } from "/utils/alea.js"; +import {ArrayFun} from "/utils/array.js"; +import {Random} from "/utils/alea.js"; export default class GiveawayRules extends ChessRules { @@ -84,10 +84,10 @@ export default class GiveawayRules extends ChessRules { super(o); } - underCheck([x, y], oppCol) { + underCheck(square, oppCol) { if (this.options["mode"] == "suicide") return false; - return super.underCheck([x, y], oppCol); + return super.underCheck(square, oppCol); } getCurrentScore() { diff --git a/variants/Madrasi/class.js b/variants/Madrasi/class.js index bbec80a..ac5ccff 100644 --- a/variants/Madrasi/class.js +++ b/variants/Madrasi/class.js @@ -22,18 +22,16 @@ export default class MadrasiRules extends ChessRules { super(o); } - underCheck([x, y], color) { - if (this.options["rexincl"]) { - // If Rex Inclusive, kings do not check each other: - // we just replace it very temporarily. - const [ox, oy] = this.searchKingPos(color); - const saveOppKing = this.board[ox][oy]; - this.board[ox][oy] = C.GetOppCol(color) + "q"; //arbitrary - const res = super.underCheck([x, y], color); - this.board[ox][oy] = saveOppKing; - return res; - } - return super.underCheck([x, y], color); + canTake([x1, y1], [x2, y2]) { + return ( + ( + !this.options["rexincl"] || + this.getPiece(x1, y1) != 'k' || + this.getPiece(x2, y2) != 'k' + ) + && + super.canTake([x1, y1], [x2, y2]) + ); } }; diff --git a/variants/Suction/class.js b/variants/Suction/class.js index a66855d..cf5ae16 100644 --- a/variants/Suction/class.js +++ b/variants/Suction/class.js @@ -107,8 +107,8 @@ export default class SuctionRules extends ChessRules { getCurrentScore() { const color = this.turn; const kingPos = super.searchKingPos(color); - if (color == "w" && kingPos[0] == 0) return "0-1"; - if (color == "b" && kingPos[0] == this.size.x - 1) return "1-0"; + if (color == "w" && kingPos[0][0] == 0) return "0-1"; + if (color == "b" && kingPos[0][0] == this.size.x - 1) return "1-0"; // King is not on the opposite edge: game not over return "*"; } diff --git a/variants/_Antiking/class.js b/variants/_Antiking/class.js new file mode 100644 index 0000000..e92edab --- /dev/null +++ b/variants/_Antiking/class.js @@ -0,0 +1,81 @@ +import ChessRules from "/base_rules.js"; + +export default class AbstractAntikingRules extends ChessRules { + + static get Aliases() { + return Object.assign({'A': AbstractAntikingRules}, ChessRules.Aliases); + } + + static get Options() { + return { + styles: [ + "atomic", + "balance", + "cannibal", + "capture", + "crazyhouse", + "doublemove", + "madrasi", + "progressive", + "recycle", + "rifle", + "teleport", + "zen" + ] + }; + } + + pieces(color, x, y) { + return Object.assign( + { + 'a': { + // Move like a king, no attacks + "class": "antiking", + moves: super.pieces(color, x, y)['k'].moves, + attack: [] + } + }, + super.pieces(color, x, y) + ); + } + + isKing(x, y, p) { + if (!p) + p = this.getPiece(x, y); + return ['k', 'a'].includes(p); + } + + // NOTE: canTake includes (wrong) captures of antiking, + // to not go to low-level using findDestSquares() + canTake([x1, y1], [x2, y2]) { + const piece1 = this.getPiece(x1, y1); + const color1 = this.getColor(x1, y1); + const color2 = this.getColor(x2, y2); + return ( + (piece1 != 'a' && color1 != color2) || + (piece1 == 'a' && color1 == color2) + ); + } + + // Remove captures of antiking (see above) + getPotentialMovesFrom([x, y]) { + return super.getPotentialMovesFrom([x, y]).filter(m => + m.vanish.length == 1 || m.vanish[1].p != 'a'); + } + + underCheck(squares, color) { + let res = false; + squares.forEach(sq => { + switch (this.getPiece(sq[0], sq[1])) { + case 'k': + res ||= super.underAttack(sq, color); + break; + case 'a': + res ||= !super.underAttack(sq, color); + break; + } + }); + return res; + } + +}; diff --git a/variants/_Antiking/rules.html b/variants/_Antiking/rules.html new file mode 100644 index 0000000..fee723a --- /dev/null +++ b/variants/_Antiking/rules.html @@ -0,0 +1 @@ +https://www.chessvariants.com/diffobjective.dir/anti-king-chess.html diff --git a/variants/_Antiking/style.css b/variants/_Antiking/style.css new file mode 100644 index 0000000..3dfe37e --- /dev/null +++ b/variants/_Antiking/style.css @@ -0,0 +1,8 @@ +@import url("/base_pieces.css"); + +piece.black.antiking { + background-image: url('/pieces/Antiking/black_antiking.svg'); +} +piece.white.antiking { + background-image: url('/pieces/Antiking/white_antiking.svg'); +}