From f57232cdb4ea7c7b5fab1c7ef23c26714d26501e Mon Sep 17 00:00:00 2001 From: Benjamin Auder Date: Sat, 11 Mar 2023 08:23:03 +0100 Subject: [PATCH] Fix Checkless and trackKingWrap() --- base_rules.js | 4 ++++ nodemon.json | 2 +- variants/Checkless/class.js | 4 ++-- variants/Checkless/rules.html | 1 + variants/Checkless/style.css | 1 + 5 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 variants/Checkless/rules.html create mode 100644 variants/Checkless/style.css 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 @@ +

Checks are forbidden, unless it is checkmate.

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") -- 2.44.0