Add Gomoku + Atarigo
[vchess.git] / client / src / variants / Teleport.js
index 6cf14a8..cbf6a78 100644 (file)
@@ -2,7 +2,8 @@ import { ChessRules, Move, PiPo } from "@/base_rules";
 import { randInt } from "@/utils/alea";
 
 export class TeleportRules extends ChessRules {
-  hoverHighlight(x, y) {
+
+  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);
@@ -18,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 &&
@@ -135,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
@@ -228,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) {
@@ -346,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);
   }
+
 };