From: Benjamin Auder Date: Fri, 5 Jun 2020 20:28:57 +0000 (+0200) Subject: Monochrome: remove duplicate capturing moves X-Git-Url: https://git.auder.net/variants/current/doc/css/assets/pieces/cb.svg?a=commitdiff_plain;h=aaa0d7d5e1342d85f758b55deb5a8599eb19f35d;p=vchess.git Monochrome: remove duplicate capturing moves --- diff --git a/client/src/variants/Monochrome.js b/client/src/variants/Monochrome.js index ba56c69a..50ca04b1 100644 --- a/client/src/variants/Monochrome.js +++ b/client/src/variants/Monochrome.js @@ -105,7 +105,21 @@ export class MonochromeRules extends ChessRules { } getPotentialMovesFrom(sq) { - return super.getPotentialMovesFrom(sq).concat(this.findCaptures(sq)); + const moves = super.getPotentialMovesFrom(sq); + const zenCaptures = this.findCaptures(sq); + // Remove duplicate captures in a lazy way (TODO: more efficient...) + let hashMoves = {}; + moves.forEach(m => { + if (m.vanish.length == 2) { + const hash = + m.start.x + "." + m.start.y + "." + m.end.x + "." + m.end.y; + hashMoves[hash] = true; + } + } + return moves.concat(zenCaptures.filter(m => { + const hash = m.start.x + "." + m.start.y + "." + m.end.x + "." + m.end.y; + return !hashMoves[hash]; + }); } getAllPotentialMoves() {