X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FMonochrome.js;h=954a050f34f9e82cb34394478bc91b4b2d5d237e;hb=715c0ae4af465988f4e50e8c8ac3192399639f06;hp=ba56c69a9a2dca61b103ef523d45a527546ab7f8;hpb=8ca6042e7b8cffd4131e81493141ab6261300ff6;p=vchess.git diff --git a/client/src/variants/Monochrome.js b/client/src/variants/Monochrome.js index ba56c69a..954a050f 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() {