From: Benjamin Auder Date: Sun, 10 Jan 2021 20:47:54 +0000 (+0100) Subject: Fix Pacosako attacks detection X-Git-Url: https://git.auder.net/variants/Apocalypse/scripts/current/pieces/cq.svg?a=commitdiff_plain;h=f719757530f757dc20ef895b6b96ab2ec520b0ea;p=vchess.git Fix Pacosako attacks detection --- diff --git a/client/src/variants/Pacosako.js b/client/src/variants/Pacosako.js index b67d429b..b4ed6d5d 100644 --- a/client/src/variants/Pacosako.js +++ b/client/src/variants/Pacosako.js @@ -600,10 +600,23 @@ export class PacosakoRules extends ChessRules { // "positions" = array of FENs to detect infinite loops. Example: // r1q1k2r/p1Pb1ppp/5n2/1f1p4/AV5P/P1eDP3/3B1PP1/R3K1NR, // Bxd2 Bxc3 Bxb4 Bxc3 Bxb4 etc. - const newPos = { fen: super.getBaseFen(), piece: released }; - if (positions.some(p => p.piece == newPos.piece && p.fen == newPos.fen)) + const newPos = { + fen: super.getBaseFen(), + piece: released, + from: fromSquare + }; + if ( + positions.some(p => { + return ( + p.piece == newPos.piece && + p.fen == newPos.fen && + p.from == newPos.from + ); + }) + ) { // Start of an infinite loop: exit return false; + } positions.push(newPos); const rank = (color == 'w' ? 0 : 7); const moves = this.getPotentialMovesFrom(fromSquare);