X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FColorbound.js;h=b806184cfe5fa577b91e31527bd8c5539c802e7f;hb=7e8a7ea1cb66adb4a987badfb0a3c2f99a21bd0a;hp=034f9575b1578b25314845db0086cf2d9fe69872;hpb=801e28709e778bd3a93b014d1f9cb2fb7906e303;p=vchess.git diff --git a/client/src/variants/Colorbound.js b/client/src/variants/Colorbound.js index 034f9575..b806184c 100644 --- a/client/src/variants/Colorbound.js +++ b/client/src/variants/Colorbound.js @@ -3,11 +3,16 @@ import { ArrayFun } from "@/utils/array"; import { randInt } from "@/utils/alea"; export class ColorboundRules extends ChessRules { + static get PawnSpecs() { return Object.assign( {}, ChessRules.PawnSpecs, - { promotions: V.PIECES } + { + promotions: + ChessRules.PawnSpecs.promotions.concat( + [V.C_ROOK, V.C_KNIGHT, V.C_BISHOP, V.C_QUEEN]) + } ); } @@ -80,7 +85,7 @@ export class ColorboundRules extends ChessRules { // Add turn + flags + enpassant return ( pieces["b"].join("") + - "/8/pppppppp/8/8/8/PPPPPPPP/" + + "/pppppppp/8/8/8/8/PPPPPPPP/" + pieces["w"].join("").toUpperCase() + " w 0 " + flags + " -" ); @@ -101,7 +106,7 @@ export class ColorboundRules extends ChessRules { static get PIECES() { return ( - ChessRules.PIECES.concat([V.C_ROOK, V.C_KINGHT, V.C_BISHOP, V.C_QUEEN]) + ChessRules.PIECES.concat([V.C_ROOK, V.C_KNIGHT, V.C_BISHOP, V.C_QUEEN]) ); } @@ -180,93 +185,14 @@ export class ColorboundRules extends ChessRules { ); } - // TODO: really find a way to avoid duolicating most of the castling code - // each time: here just the queenside castling squares change for black. getCastleMoves([x, y]) { - const c = this.getColor(x, y); - if (x != (c == "w" ? V.size.x - 1 : 0) || y != this.INIT_COL_KING[c]) - return []; - - const oppCol = V.GetOppCol(c); - let moves = []; - let i = 0; - // King, then rook: + const color = this.getColor(x, y); const finalSquares = [ // Black castle long in an unusual way: - (c == 'w' ? [2, 3] : [1, 2]), + (color == 'w' ? [2, 3] : [1, 2]), [V.size.y - 2, V.size.y - 3] ]; - castlingCheck: for ( - let castleSide = 0; - castleSide < 2; - castleSide++ //large, then small - ) { - if (this.castleFlags[c][castleSide] >= V.size.y) continue; - - const rookPos = this.castleFlags[c][castleSide]; - const castlingPiece = this.getPiece(x, rookPos); - const finDist = finalSquares[castleSide][0] - y; - let step = finDist / Math.max(1, Math.abs(finDist)); - i = y; - do { - if ( - this.isAttacked([x, i], oppCol) || - (this.board[x][i] != V.EMPTY && - (this.getColor(x, i) != c || - ![V.KING, castlingPiece].includes(this.getPiece(x, i)))) - ) { - continue castlingCheck; - } - i += step; - } while (i != finalSquares[castleSide][0]); - - step = castleSide == 0 ? -1 : 1; - for (i = y + step; i != rookPos; i += step) { - if (this.board[x][i] != V.EMPTY) continue castlingCheck; - } - - for (i = 0; i < 2; i++) { - if ( - finalSquares[castleSide][i] != rookPos && - this.board[x][finalSquares[castleSide][i]] != V.EMPTY && - ( - this.getPiece(x, finalSquares[castleSide][i]) != V.KING || - this.getColor(x, finalSquares[castleSide][i]) != c - ) - ) { - continue castlingCheck; - } - } - - moves.push( - new Move({ - appear: [ - new PiPo({ - x: x, - y: finalSquares[castleSide][0], - p: V.KING, - c: c - }), - new PiPo({ - x: x, - y: finalSquares[castleSide][1], - p: castlingPiece, - c: c - }) - ], - vanish: [ - new PiPo({ x: x, y: y, p: V.KING, c: c }), - new PiPo({ x: x, y: rookPos, p: castlingPiece, c: c }) - ], - end: - Math.abs(y - rookPos) <= 2 - ? { x: x, y: rookPos } - : { x: x, y: y + 2 * (castleSide == 0 ? -1 : 1) } - }) - ); - } - - return moves; + return super.getCastleMoves([x, y], finalSquares); } isAttacked(sq, color) { @@ -311,7 +237,7 @@ export class ColorboundRules extends ChessRules { return ( this.isAttackedBySlideNJump(sq, color, V.C_QUEEN, V.steps[V.BISHOP]) || this.isAttackedBySlideNJump( - sq, color, V.C_ROOK, V.steps[V.KNIGHT], "oneStep") + sq, color, V.C_QUEEN, V.steps[V.KNIGHT], "oneStep") ); } @@ -327,4 +253,9 @@ export class ColorboundRules extends ChessRules { } ); } + + static get SEARCH_DEPTH() { + return 2; + } + };