X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FEightpieces.js;h=eaf7d33e3c03de96dc617574304c9e99bcee6478;hb=9b6405f5e6f9c808589e9bb6c525554a55164b03;hp=1fbc5d0b0ce172b86fa27538836c7c75f68c2bcf;hpb=0fb43db7c2858201e8410670b90f95ad8b138964;p=vchess.git diff --git a/client/src/variants/Eightpieces.js b/client/src/variants/Eightpieces.js index 1fbc5d0b..eaf7d33e 100644 --- a/client/src/variants/Eightpieces.js +++ b/client/src/variants/Eightpieces.js @@ -167,11 +167,11 @@ export class EightpiecesRules extends ChessRules { } } - static GenRandInitFen(randomness) { - if (randomness == 0) + static GenRandInitFen(options) { + if (options.randomness == 0) return "jfsqkbnr/pppppppp/8/8/8/8/PPPPPPPP/JDSQKBNR w 0 ahah - -"; - const baseFen = ChessRules.GenRandInitFen(randomness); + const baseFen = ChessRules.GenRandInitFen(options); const fenParts = baseFen.split(' '); const posParts = fenParts[0].split('/'); @@ -246,45 +246,6 @@ export class EightpiecesRules extends ChessRules { return null; } - // Because of the lancers, getPiece() could be wrong: - // use board[x][y][1] instead (always valid). - getBasicMove([sx, sy], [ex, ey], tr) { - const initColor = this.getColor(sx, sy); - const initPiece = this.board[sx][sy].charAt(1); - let mv = new Move({ - appear: [ - new PiPo({ - x: ex, - y: ey, - c: tr ? tr.c : initColor, - p: tr ? tr.p : initPiece - }) - ], - vanish: [ - new PiPo({ - x: sx, - y: sy, - c: initColor, - p: initPiece - }) - ] - }); - - // The opponent piece disappears if we take it - if (this.board[ex][ey] != V.EMPTY) { - mv.vanish.push( - new PiPo({ - x: ex, - y: ey, - c: this.getColor(ex, ey), - p: this.board[ex][ey].charAt(1) - }) - ); - } - - return mv; - } - canIplay(side, [x, y]) { return ( (this.subTurn == 1 && this.turn == side && this.getColor(x, y) == side) @@ -710,10 +671,7 @@ export class EightpiecesRules extends ChessRules { getPotentialKingMoves(sq) { const moves = this.getSlideNJumpMoves( - sq, - V.steps[V.ROOK].concat(V.steps[V.BISHOP]), - "oneStep" - ); + sq, V.steps[V.ROOK].concat(V.steps[V.BISHOP]), 1); return ( this.subTurn == 1 ? moves.concat(this.getCastleMoves(sq)) @@ -863,8 +821,8 @@ export class EightpiecesRules extends ChessRules { const oppCol = V.GetOppCol(color); const sliderAttack = (allowedSteps, lancer) => { const deltaX = x2 - x1, - absDeltaX = Math.abs(deltaX); - const deltaY = y2 - y1, + deltaY = y2 - y1; + const absDeltaX = Math.abs(deltaX), absDeltaY = Math.abs(deltaY); const step = [ deltaX / absDeltaX || 0, deltaY / absDeltaY || 0 ]; if ( @@ -876,12 +834,18 @@ export class EightpiecesRules extends ChessRules { } let sq = [ x1 + step[0], y1 + step[1] ]; while (sq[0] != x2 || sq[1] != y2) { - if ( - // NOTE: no need to check OnBoard in this special case - (!lancer && this.board[sq[0]][sq[1]] != V.EMPTY) || - (!!lancer && this.getColor(sq[0], sq[1]) == oppCol) - ) { - return false; + // NOTE: no need to check OnBoard in this special case + if (this.board[sq[0]][sq[1]] != V.EMPTY) { + const p = this.getPiece(sq[0], sq[1]); + const pc = this.getColor(sq[0], sq[1]); + if ( + // Enemy sentry on the way will be gone: + (p != V.SENTRY || pc != oppCol) && + // Lancer temporarily "changed color": + (!lancer || pc == color) + ) { + return false; + } } sq[0] += step[0]; sq[1] += step[1];