X-Git-Url: https://git.auder.net/variants/Chakart/style.css?a=blobdiff_plain;ds=sidebyside;f=client%2Fsrc%2Fvariants%2FEightpieces.js;h=ded8757980f94871cd94adef9b90e4741c089105;hb=17cc3d8d61d6d3aa9fdf043647741dae6a79fd5e;hp=927530c0fae857cbe3d18693488f6027aebe101f;hpb=4313762da3237b04f204e121a20cab3ba7bb5dd2;p=vchess.git diff --git a/client/src/variants/Eightpieces.js b/client/src/variants/Eightpieces.js index 927530c0..ded87579 100644 --- a/client/src/variants/Eightpieces.js +++ b/client/src/variants/Eightpieces.js @@ -183,8 +183,10 @@ export class EightpiecesRules extends ChessRules { // or (eventually) the index of replacement: let newPos = { 0: "", 7: "" }; let sentryOddity = -1; + let replaced = {}; + if (options.randomness == 1) replaced = { 'b': -2, 'n': -2, 'r': -2 }; for (let rank of [0, 7]) { - let replaced = { 'b': -2, 'n': -2, 'r': -2 }; + if (options.randomness == 2) replaced = { 'b': -2, 'n': -2, 'r': -2 }; for (let i = 0; i < 8; i++) { const curChar = posParts[rank].charAt(i).toLowerCase(); if (['b', 'n', 'r'].includes(curChar)) { @@ -821,8 +823,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 ( @@ -834,12 +836,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];