X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FPacosako.js;h=b4ed6d5d727f2dd1c7a9d3f41a3cbabf880f4aa0;hb=2fac4d67083700a1f1e85ed8662c176c24cdea6b;hp=9f0abf88cbe1053bfbb302428c33e5b8fb02eabc;hpb=9d15c433c207a2c3bb548d095939c3e08b4038fd;p=vchess.git diff --git a/client/src/variants/Pacosako.js b/client/src/variants/Pacosako.js index 9f0abf88..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); @@ -666,6 +679,28 @@ export class PacosakoRules extends ChessRules { return res; } + isAttackedBySlideNJump([x, y], color, piece, steps, oneStep) { + for (let step of steps) { + let rx = x + step[0], + ry = y + step[1]; + while (V.OnBoard(rx, ry) && this.board[rx][ry] == V.EMPTY && !oneStep) { + rx += step[0]; + ry += step[1]; + } + if ( + V.OnBoard(rx, ry) && + this.board[rx][ry] != V.EMPTY && + this.getPiece(rx, ry) == piece && + this.getColor(rx, ry) == color && + this.canTake([rx, ry], [x, y]) //TODO: necessary line? + //If not, generic method is OK + ) { + return true; + } + } + return false; + } + // Do not consider checks, except to forbid castling getCheckSquares() { return [];