X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FFullcavalry.js;h=07951f6baea06c5ebd9d748d8bed4355d75cb6dc;hb=4313762da3237b04f204e121a20cab3ba7bb5dd2;hp=98549db49de1229d6ad97bca42da561fb304f916;hpb=de0706e6db65fa857a314a8d982f006d35eebb94;p=vchess.git diff --git a/client/src/variants/Fullcavalry.js b/client/src/variants/Fullcavalry.js index 98549db4..07951f6b 100644 --- a/client/src/variants/Fullcavalry.js +++ b/client/src/variants/Fullcavalry.js @@ -88,12 +88,12 @@ export class FullcavalryRules extends ChessRules { ); } - static GenRandInitFen(randomness) { - if (randomness == 0) + static GenRandInitFen(options) { + if (options.randomness == 0) // Deterministic: - return "efbqkbnm/pppppppp/8/8/8/8/PPPPPPPP/EDBQKBNM w 0 ahah -"; + return "enbqkbnm/pppppppp/8/8/8/8/PPPPPPPP/ENBQKBNM w 0 ahah -"; - const baseFen = ChessRules.GenRandInitFen(randomness); + const baseFen = ChessRules.GenRandInitFen(options); // Replace rooks by lancers with expected orientation: const firstBlackRook = baseFen.indexOf('r'), lastBlackRook = baseFen.lastIndexOf('r'), @@ -114,46 +114,6 @@ export class FullcavalryRules extends ChessRules { ); } - // Because of the lancers, getPiece() could be wrong: - // use board[x][y][1] instead (always valid). - // TODO: base implementation now uses this too (no?) - 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; - } - getPotentialMovesFrom([x, y]) { if (this.getPiece(x, y) == V.LANCER) return this.getPotentialLancerMoves([x, y]); @@ -162,12 +122,8 @@ export class FullcavalryRules extends ChessRules { getPotentialPawnMoves([x, y]) { const color = this.getColor(x, y); - let moves = []; - const [sizeX, sizeY] = [V.size.x, V.size.y]; let shiftX = (color == "w" ? -1 : 1); - const startRank = color == "w" ? sizeX - 2 : 1; - const lastRank = color == "w" ? 0 : sizeX - 1; - + const lastRank = (color == "w" ? 0 : 7); let finalPieces = [V.PAWN]; if (x + shiftX == lastRank) { // Only allow direction facing inside board: @@ -177,46 +133,7 @@ export class FullcavalryRules extends ChessRules { : ['c', 'd', 'e', 'm', 'o']; finalPieces = allowedLancerDirs.concat([V.KNIGHT, V.BISHOP, V.QUEEN]); } - if (this.board[x + shiftX][y] == V.EMPTY) { - // One square forward - for (let piece of finalPieces) { - moves.push( - this.getBasicMove([x, y], [x + shiftX, y], { - c: color, - p: piece - }) - ); - } - if (x == startRank && this.board[x + 2 * shiftX][y] == V.EMPTY) - // Two squares jump - moves.push(this.getBasicMove([x, y], [x + 2 * shiftX, y])); - } - // Captures - for (let shiftY of [-1, 1]) { - if ( - y + shiftY >= 0 && - y + shiftY < sizeY && - this.board[x + shiftX][y + shiftY] != V.EMPTY && - this.canTake([x, y], [x + shiftX, y + shiftY]) - ) { - for (let piece of finalPieces) { - moves.push( - this.getBasicMove([x, y], [x + shiftX, y + shiftY], { - c: color, - p: piece - }) - ); - } - } - } - - // Add en-passant captures - Array.prototype.push.apply( - moves, - this.getEnpassantCaptures([x, y], shiftX) - ); - - return moves; + return super.getPotentialPawnMoves([x, y], finalPieces); } // Obtain all lancer moves in "step" direction @@ -375,12 +292,8 @@ export class FullcavalryRules extends ChessRules { this.getColor(coord.x, coord.y) == color ) ) { - if ( - this.getPiece(coord.x, coord.y) == V.LANCER && - !this.isImmobilized([coord.x, coord.y]) - ) { + if (this.getPiece(coord.x, coord.y) == V.LANCER) lancerPos.push({x: coord.x, y: coord.y}); - } coord.x += step[0]; coord.y += step[1]; } @@ -415,10 +328,14 @@ export class FullcavalryRules extends ChessRules { filterValid(moves) { // At move 1, forbid captures (in case of...): - if (this.movesCount >= 2) return moves; + if (this.movesCount >= 2) return super.filterValid(moves); return moves.filter(m => m.vanish.length == 1); } + static get SEARCH_DEPTH() { + return 2; + } + getNotation(move) { let notation = super.getNotation(move); if (Object.keys(V.LANCER_DIRNAMES).includes(move.vanish[0].p))