Simplify Monster + Doublemove2. Smoother example games
[vchess.git] / client / src / variants / Teleport.js
index 2379692..6cf14a8 100644 (file)
@@ -3,7 +3,8 @@ import { randInt } from "@/utils/alea";
 
 export class TeleportRules extends ChessRules {
   hoverHighlight(x, y) {
-    // TODO: only highlight if the move is legal
+    // 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);
   }
 
@@ -299,16 +300,17 @@ 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)
           ) {
-            // TODO: if many second moves have the same eval, only the
-            // first is kept. Could be randomized.
             m.eval = mvEval;
             m.next = m2;
           }