X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FOtage.js;h=742c6ee19e02c0cf6217be9fa9ac48e17da2bb55;hb=d2af3400944331ffd0c770f83857257c2f48e487;hp=98b340e43bb7027d2345a8d936af7f71c185899c;hpb=8ec71052706a106ea3d04316d7f76a48aff98bec;p=vchess.git diff --git a/client/src/variants/Otage.js b/client/src/variants/Otage.js index 98b340e4..742c6ee1 100644 --- a/client/src/variants/Otage.js +++ b/client/src/variants/Otage.js @@ -167,6 +167,7 @@ export class OtageRules extends ChessRules { super.setOtherVariables(fen); // Stack of "last move" only for intermediate chaining this.lastMoveEnd = [null]; + this.repetitions = []; } static IsGoodFlags(flags) { @@ -638,8 +639,32 @@ export class OtageRules extends ChessRules { getCheckSquares() { return []; } + filterValid(moves) { - return moves; + if (moves.length == 0) return []; + return moves.filter(m => { + if (!m.end.released) return true; + // Check for repetitions: + V.PlayOnBoard(this.board, m); + const newState = { + piece: m.end.released, + square: { x: m.end.x, y: m.end.y }, + position: this.getBaseFen() + }; + const repet = + this.repetitions.some(r => { + return ( + r.piece == newState.piece && + ( + r.square.x == newState.square.x && + r.square.y == newState.square.y && + ) && + r.position == newState.position + ); + }); + V.UndoOnBoard(this.board, m); + return !repet; + }); } updateCastleFlags(move, piece) { @@ -702,6 +727,16 @@ export class OtageRules extends ChessRules { else this.lastMoveEnd.push(Object.assign({ p: move.end.released }, move.end)); V.PlayOnBoard(this.board, move); + if (!move.end.released) this.repetitions = []; + else { + this.repetitions.push( + { + piece: move.end.released, + square: { x: move.end.x, y: move.end.y }, + position: this.getBaseFen() + } + ); + } } undo(move) { @@ -713,6 +748,7 @@ export class OtageRules extends ChessRules { this.turn = V.GetOppCol(this.turn); this.movesCount--; } + if (!!move.end.released) this.repetitions.pop(); this.postUndo(move); } @@ -761,6 +797,7 @@ export class OtageRules extends ChessRules { for (let i = mvArray.length - 1; i >= 0; i--) this.undo(mvArray[i]); if (!mv.end.released) return (mvArray.length > 1 ? mvArray : mvArray[0]); } + return null; //never reached } // NOTE: evalPosition() is wrong, but unused since bot plays at random @@ -798,8 +835,13 @@ export class OtageRules extends ChessRules { // Add potential promotion indications: const firstLastRank = (c == 'w' ? [7, 0] : [0, 7]); if (move.end.x == firstLastRank[1] && piece == V.PAWN) { - const up = this.getUnionPieces(move.appear[0].c, move.appear[0].p); - notation += "=" + up[c].toUpperCase(); + notation += "="; + if (ChessRules.PIECES.includes(move.appear[0].p)) + notation += move.appear[0].p.toUpperCase(); + else { + const up = this.getUnionPieces(move.appear[0].c, move.appear[0].p); + notation += up[c].toUpperCase(); + } } else if ( move.end.x == firstLastRank[0] &&