From: Benjamin Auder <benjamin.auder@somewhere>
Date: Sat, 11 Mar 2023 07:23:03 +0000 (+0100)
Subject: Fix Checkless and trackKingWrap()
X-Git-Url: https://git.auder.net/js/img/%7B%7B%20asset('mixstore/css/%7B%7B?a=commitdiff_plain;h=f57232cdb4ea7c7b5fab1c7ef23c26714d26501e;p=xogo.git

Fix Checkless and trackKingWrap()
---

diff --git a/base_rules.js b/base_rules.js
index 0c316eb..e8cf4f4 100644
--- a/base_rules.js
+++ b/base_rules.js
@@ -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
diff --git a/nodemon.json b/nodemon.json
index d9ffb96..be05234 100644
--- a/nodemon.json
+++ b/nodemon.json
@@ -2,7 +2,7 @@
   "ignore": [
     "app.js",
     "assets/",
-    "assets.zip","
+    "assets.zip",
     "base_pieces.css",
     "base_rules.js",
     "common.css",
diff --git a/variants/Checkless/class.js b/variants/Checkless/class.js
index bc85184..0e24b77 100644
--- a/variants/Checkless/class.js
+++ b/variants/Checkless/class.js
@@ -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
index 0000000..f39b381
--- /dev/null
+++ b/variants/Checkless/rules.html
@@ -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
index 0000000..290a6f4
--- /dev/null
+++ b/variants/Checkless/style.css
@@ -0,0 +1 @@
+@import url("/base_pieces.css")