X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FEightpieces.js;h=583b1c5ac5a14e609324a274136da6d39cea31ec;hb=7f1df0d95d2190fd69ef7c58f5a795aef3f92869;hp=a232890ce5e7ab47a121d81d37b3042db6d917ed;hpb=737a5dafb39740ebe304b8d0a82df85070def571;p=vchess.git diff --git a/client/src/variants/Eightpieces.js b/client/src/variants/Eightpieces.js index a232890c..583b1c5a 100644 --- a/client/src/variants/Eightpieces.js +++ b/client/src/variants/Eightpieces.js @@ -406,12 +406,18 @@ export class EightpiecesRules extends ChessRules { // Pawns might be pushed on 1st rank and attempt to move again: if (!V.OnBoard(x + shiftX, y)) return []; - const finalPieces = - // A push cannot put a pawn on last rank (it goes backward) - x + shiftX == lastRank - ? Object.keys(V.LANCER_DIRS).concat( - [V.ROOK, V.KNIGHT, V.BISHOP, V.QUEEN, V.SENTRY, V.JAILER]) - : [V.PAWN]; + // A push cannot put a pawn on last rank (it goes backward) + let finalPieces = [V.PAWN]; + if (x + shiftX == lastRank) { + // Only allow direction facing inside board: + const allowedLancerDirs = + lastRank == 0 + ? ['e', 'f', 'g', 'h', 'm'] + : ['c', 'd', 'e', 'm', 'o']; + finalPieces = + allowedLancerDirs + .concat([V.ROOK, V.KNIGHT, V.BISHOP, V.QUEEN, V.SENTRY, V.JAILER]); + } if (this.board[x + shiftX][y] == V.EMPTY) { // One square forward for (let piece of finalPieces) { @@ -622,13 +628,18 @@ export class EightpiecesRules extends ChessRules { let chooseMoves = []; dirMoves.forEach(m => { Object.keys(V.LANCER_DIRS).forEach(k => { - let mk = JSON.parse(JSON.stringify(m)); - mk.appear[0].p = k; - moves.push(mk); + const newDir = V.LANCER_DIRS[k]; + // Prevent orientations toward outer board: + if (V.OnBoard(m.end.x + newDir[0], m.end.y + newDir[1])) { + let mk = JSON.parse(JSON.stringify(m)); + mk.appear[0].p = k; + chooseMoves.push(mk); + } }); }); Array.prototype.push.apply(moves, chooseMoves); - } else Array.prototype.push.apply(moves, dirMoves); + } + else Array.prototype.push.apply(moves, dirMoves); }); return moves; } @@ -640,13 +651,18 @@ export class EightpiecesRules extends ChessRules { if (this.subTurn == 1) { monodirMoves.forEach(m => { Object.keys(V.LANCER_DIRS).forEach(k => { - let mk = JSON.parse(JSON.stringify(m)); - mk.appear[0].p = k; - moves.push(mk); + const newDir = V.LANCER_DIRS[k]; + // Prevent orientations toward outer board: + if (V.OnBoard(m.end.x + newDir[0], m.end.y + newDir[1])) { + let mk = JSON.parse(JSON.stringify(m)); + mk.appear[0].p = k; + moves.push(mk); + } }); }); return moves; - } else { + } + else { // I'm pushed: add potential nudges, except for current orientation let potentialNudges = []; for (let step of V.steps[V.ROOK].concat(V.steps[V.BISHOP])) {