X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FTeleport.js;h=f5422c73e0fb8e7e199dcb19ebf2d931a8bb8410;hb=ad030c7d24804fbfa06158e93d89a3f101d2c8b3;hp=b4e6d7faa5a575d2092e3ebd40ee138780b06793;hpb=107dc1bd5361e2538b1551bdcc37c1e90a444b83;p=vchess.git diff --git a/client/src/variants/Teleport.js b/client/src/variants/Teleport.js index b4e6d7fa..f5422c73 100644 --- a/client/src/variants/Teleport.js +++ b/client/src/variants/Teleport.js @@ -2,6 +2,30 @@ 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; + } + setOtherVariables(fen) { super.setOtherVariables(fen); this.subTurn = 1; @@ -294,10 +318,13 @@ export class TeleportRules extends ChessRules { moves2.forEach(m2 => { this.play(m2); const score = this.getCurrentScore(); - const mvEval = - ["1-0", "0-1"].includes(score) - ? (score == "1-0" ? 1 : -1) * maxeval - : (score == "1/2" ? 0 : initEval); + let mvEval = 0; + if (["1-0", "0-1"].includes(score)) + mvEval = (score == "1-0" ? 1 : -1) * maxeval; + else if (score == "*") + // Add small fluctuations to avoid dropping pieces always on the + // first square available. + mvEval = initEval + 0.05 - Math.random() / 10; if ( (color == 'w' && mvEval > m.eval) || (color == 'b' && mvEval < m.eval)