X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FTitan.js;h=427eecdb67ff13b43642668b0bc44f8d651a1b8c;hp=f8d626ebf0c86835b482d38cecd64f538ed389bc;hb=70c94aa7b7c3cb8832a728881a29feeb26118eb9;hpb=7c05a5f2297bea540c700ebceb0cc8b03a7f6775 diff --git a/client/src/variants/Titan.js b/client/src/variants/Titan.js index f8d626eb..427eecdb 100644 --- a/client/src/variants/Titan.js +++ b/client/src/variants/Titan.js @@ -120,26 +120,68 @@ export class TitanRules extends ChessRules { } } + canIplay(side, [x, y]) { + if (this.movesCount >= 4) return super.canIplay(side, [x, y]); + return ( + this.turn == side && + ( + (side == 'w' && x == 7) || + (side == 'b' && x == 0) + ) + ); + } + + hoverHighlight([x, y]) { + const c = this.turn; + return ( + this.movesCount <= 3 && + ((c == 'w' && x == 7) || (c == 'b' && x == 0)) + ); + } + + onlyClick([x, y]) { + return ( + this.movesCount <= 3 || + // TODO: next line theoretically shouldn't be required... + (this.movesCount == 4 && this.getColor(x, y) != this.turn) + ); + } + + // Special case of move 1 = choose squares, knight first, then bishop + doClick(square) { + if (this.movesCount >= 4) return null; + const color = this.turn; + const [x, y] = [square[0], square[1]]; + if ((color == 'w' && x != 7) || (color == 'b' && x != 0)) return null; + const selectedPiece = this.board[x][y][1]; + return new Move({ + appear: [ + new PiPo({ + x: x, + y: y, + c: color, + p: this.getAugmented(selectedPiece) + }) + ], + vanish: [ + new PiPo({ + x: x, + y: y, + c: color, + p: selectedPiece + }) + ], + start: { x: x, y: y }, + end: { x: x, y: y } + }); + } + // If piece not in usual list, bishop or knight appears. getPotentialMovesFrom([x, y]) { if (this.movesCount <= 3) { // Setup stage - const color = this.getColor(x, y); - const firstRank = (color == 'w' ? 7 : 0); - if (x != firstRank || V.AUGMENTED_PIECES.includes(this.board[x][y][1])) - return []; - const piece = this.getPiece(x, y); - const move = new Move({ - appear: [ - new PiPo({ x: x, y: y, c: color, p: this.getAugmented(piece) }) - ], - vanish: [ - new PiPo({ x: x, y: y, c: color, p: piece }) - ], - start: { x: x, y: y }, - end: { x: x, y: y } - }); - return [move]; + const move = this.doClick([x, y]); + return (!move ? [] : [move]); } let moves = super.getPotentialMovesFrom([x, y]); const initialPiece = this.getPiece(x, y); @@ -185,49 +227,22 @@ export class TitanRules extends ChessRules { return moves; } - hoverHighlight([x, y]) { - const c = this.turn; - return ( - this.movesCount <= 3 && - ((c == 'w' && x == 7) || (c == 'b' && x == 0)) - ); - } - - // Special case of move 1 = choose squares, knight first, then bishop - doClick(square) { - if (this.movesCount >= 4) return null; - const color = this.turn; - const [x, y] = [square[0], square[1]]; - if ((color == 'w' && x != 7) || (color == 'b' && x != 0)) return null; - const selectedPiece = this.board[x][y][1]; - return new Move({ - appear: [ - new PiPo({ - x: x, - y: y, - c: color, - p: this.getAugmented(selectedPiece) - }) - ], - vanish: [ - new PiPo({ - x: x, - y: y, - c: color, - p: selectedPiece - }) - ], - start: { x: x, y: y }, - end: { x: x, y: y } - }); - } - postPlay(move) { - if (this.movesCount > 4) super.postPlay(move); + if (this.movesCount > 4) { + let piece = move.vanish[0].p; + if (['j', 'l'].includes(piece)) piece = V.KING; + if (piece == V.KING && move.appear.length > 0) + this.kingPos[c] = [move.appear[0].x, move.appear[0].y]; + this.updateCastleFlags(move, piece); + } } postUndo(move) { - if (this.movesCount >= 4) super.postUndo(move); + if (this.movesCount >= 4) { + const c = this.getColor(move.start.x, move.start.y); + if (['j', 'k', 'l'].includes(this.getPiece(move.start.x, move.start.y))) + this.kingPos[c] = [move.start.x, move.start.y]; + } } evalPosition() { @@ -257,6 +272,7 @@ export class TitanRules extends ChessRules { if ( V.AUGMENTED_PIECES.includes(move.vanish[0].p) || ( + move.appear.length >= 2 && move.vanish.length >= 2 && V.AUGMENTED_PIECES.includes(move.vanish[1].p) )