X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FTeleport.js;h=cbf6a786adbc59c3d2e1a01c068dd66547777ec5;hb=7c05a5f2297bea540c700ebceb0cc8b03a7f6775;hp=f5422c73e0fb8e7e199dcb19ebf2d931a8bb8410;hpb=ad030c7d24804fbfa06158e93d89a3f101d2c8b3;p=vchess.git diff --git a/client/src/variants/Teleport.js b/client/src/variants/Teleport.js index f5422c73..cbf6a786 100644 --- a/client/src/variants/Teleport.js +++ b/client/src/variants/Teleport.js @@ -2,28 +2,11 @@ import { ChessRules, Move, PiPo } from "@/base_rules"; import { randInt } from "@/utils/alea"; export class TeleportRules extends ChessRules { - hoverHighlight(x, y) { - if (this.subTurn == 1 || this.board[x][y] != V.EMPTY) - return false; - // Only highlight if the move is legal - const color = this.turn; - const tMove = new Move({ - appear: [ - new PiPo({ - x: x, - y: y, - c: color, - // The dropped piece nature has no importance: - p: V.KNIGHT - }) - ], - vanish: [], - start: { x: -1, y: -1 } - }); - this.play(tMove); - const moveOk = !this.underCheck(color); - this.undo(tMove); - return moveOk; + + hoverHighlight([x, y]) { + // Testing move validity results in an infinite update loop. + // TODO: find a way to test validity anyway. + return (this.subTurn == 2 && this.board[x][y] == V.EMPTY); } setOtherVariables(fen) { @@ -36,6 +19,11 @@ export class TeleportRules extends ChessRules { return this.subTurn == 1; } + canIplay(side, [x, y]) { + if (this.subTurn == 2) return (this.board[x][y] == V.EMPTY); + return super.canIplay(side, [x, y]); + } + getPPpath(m) { if ( m.vanish.length == 2 && @@ -153,13 +141,6 @@ export class TeleportRules extends ChessRules { return super.underCheck(color); } - getCurrentScore() { - if (this.subTurn == 2) - // Move not over - return "*"; - return super.getCurrentScore(); - } - doClick(square) { if (isNaN(square[0])) return null; // If subTurn == 2 && square is empty && !underCheck, then teleport @@ -246,28 +227,8 @@ export class TeleportRules extends ChessRules { } } } - else { - // Normal move - const firstRank = (c == "w" ? V.size.x - 1 : 0); - const oppCol = V.GetOppCol(c); - const oppFirstRank = V.size.x - 1 - firstRank; - if (move.vanish[0].p == V.KING && move.appear.length > 0) - this.castleFlags[c] = [V.size.y, V.size.y]; - else if ( - move.start.x == firstRank && - this.castleFlags[c].includes(move.start.y) - ) { - const flagIdx = (move.start.y == this.castleFlags[c][0] ? 0 : 1); - this.castleFlags[c][flagIdx] = V.size.y; - } - if ( - move.end.x == oppFirstRank && - this.castleFlags[oppCol].includes(move.end.y) - ) { - const flagIdx = (move.end.y == this.castleFlags[oppCol][0] ? 0 : 1); - this.castleFlags[oppCol][flagIdx] = V.size.y; - } - } + // Normal check: + super.updateCastleFlags(move, move.vanish[0].p, c); } undo(move) { @@ -329,8 +290,6 @@ export class TeleportRules extends ChessRules { (color == 'w' && mvEval > m.eval) || (color == 'b' && mvEval < m.eval) ) { - // TODO: if many second moves have the same eval, only the - // first is kept. Could be randomized. m.eval = mvEval; m.next = m2; } @@ -366,4 +325,5 @@ export class TeleportRules extends ChessRules { move.appear[0].p != V.PAWN ? move.appear[0].p.toUpperCase() : ""; return piece + "@" + V.CoordsToSquare(move.end); } + };