From: Benjamin Auder Date: Fri, 27 Mar 2020 02:58:39 +0000 (+0100) Subject: Fix Apocalypse example games X-Git-Url: https://git.auder.net/variants/Chakart/doc/scripts/img/css/rpsls.css?a=commitdiff_plain;h=54f51146ad1f5cb2e3a09ac31cb6c017af80dd37;p=vchess.git Fix Apocalypse example games --- diff --git a/client/src/variants/Apocalypse.js b/client/src/variants/Apocalypse.js index 5774d373..1eb482ec 100644 --- a/client/src/variants/Apocalypse.js +++ b/client/src/variants/Apocalypse.js @@ -322,7 +322,7 @@ export class ApocalypseRules extends ChessRules { vanish: [] }; if (!m1 && !m2) return smove; - // Both move are now legal: + // Both moves are now legal or at least possible: smove.vanish.push(m1.vanish[0]); smove.vanish.push(m2.vanish[0]); if ((m1.end.x != m2.end.x) || (m1.end.y != m2.end.y)) { @@ -467,11 +467,18 @@ export class ApocalypseRules extends ChessRules { return moves[randInt(moves.length)]; // Rank moves at depth 1: - // try to capture something (not re-capturing) moves.forEach(m => { - V.PlayOnBoard(this.board, m); + // Warning: m.vanish[0] might refer to an empty square! Or self + const skipPlayUndo = ( + m.vanish.length == 2 && + ( + m.vanish[1].c == m.vanish[0].c || + this.board[m.vanish[1].x][m.vanish[1].y] == V.EMPTY + ) + ); + if (!skipPlayUndo) V.PlayOnBoard(this.board, m); m.eval = this.evalPosition(); - V.UndoOnBoard(this.board, m); + if (!skipPlayUndo) V.UndoOnBoard(this.board, m); }); moves.sort((a, b) => { return (color == "w" ? 1 : -1) * (b.eval - a.eval); @@ -485,7 +492,7 @@ export class ApocalypseRules extends ChessRules { getNotation(move) { // Basic system: piece + init + dest square return ( - move.vanish[0].p.toUpperCase() + + (move.vanish[0].p == V.KNIGHT ? "N" : "") + V.CoordsToSquare(move.start) + V.CoordsToSquare(move.end) );