Fix Checkless and trackKingWrap()
authorBenjamin Auder <benjamin.auder@somewhere>
Sat, 11 Mar 2023 07:23:03 +0000 (08:23 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Sat, 11 Mar 2023 07:23:03 +0000 (08:23 +0100)
base_rules.js
nodemon.json
variants/Checkless/class.js
variants/Checkless/rules.html [new file with mode: 0644]
variants/Checkless/style.css [new file with mode: 0644]

index 0c316eb..e8cf4f4 100644 (file)
@@ -2171,6 +2171,10 @@ export default class ChessRules {
 
   // cb: callback returning a boolean (false if king missing)
   trackKingWrap(move, kingPos, cb) {
+    if (move.appear.length == 0 && move.vanish.length == 0)
+      return true;
+    const color =
+      (move.vanish.length > 0 ? move.vanish[0].c : move.appear[0].c);
     let newKingPP = null,
         sqIdx = 0,
         res = true; //a priori valid
index d9ffb96..be05234 100644 (file)
@@ -2,7 +2,7 @@
   "ignore": [
     "app.js",
     "assets/",
-    "assets.zip","
+    "assets.zip",
     "base_pieces.css",
     "base_rules.js",
     "common.css",
index bc85184..0e24b77 100644 (file)
@@ -24,7 +24,7 @@ export default class ChecklessRules extends ChessRules {
   }
 
   filterValid(moves) {
-    fmoves = super.filterValid(moves);
+    const fmoves = super.filterValid(moves);
     // Filter out moves giving check but not checkmate
     const color = this.turn;
     const oppCol = C.GetOppTurn(color);
@@ -35,7 +35,7 @@ export default class ChecklessRules extends ChessRules {
       const res = this.trackKingWrap(m, oppKingPos, (oppKp) => {
         return (
           !this.underCheck(oppKp, [color]) ||
-          this.atLeastOneMove_aux(oppKp, kingPos, oppCol, color)
+          !this.atLeastOneMove_aux(oppKp, kingPos, oppCol, color)
         );
       });
       this.undoOnBoard(m);
diff --git a/variants/Checkless/rules.html b/variants/Checkless/rules.html
new file mode 100644 (file)
index 0000000..f39b381
--- /dev/null
@@ -0,0 +1 @@
+<p>Checks are forbidden, unless it is checkmate.</p>
diff --git a/variants/Checkless/style.css b/variants/Checkless/style.css
new file mode 100644 (file)
index 0000000..290a6f4
--- /dev/null
@@ -0,0 +1 @@
+@import url("/base_pieces.css")