Several small improvements + integrate options + first working draft of Cwda
[vchess.git] / client / src / variants / Hamilton.js
index 08994e3..8738b28 100644 (file)
@@ -2,6 +2,11 @@ import { ChessRules, Move, PiPo } from "@/base_rules";
 import { randInt } from "@/utils/alea";
 
 export class HamiltonRules extends ChessRules {
+
+  static get Options() {
+    return null;
+  }
+
   static get HasFlags() {
     return false;
   }
@@ -10,12 +15,12 @@ export class HamiltonRules extends ChessRules {
     return false;
   }
 
-  static get HOLE() {
-    return "xx";
+  get showFirstTurn() {
+    return true;
   }
 
-  hoverHighlight(x, y) {
-    return this.movesCount == 0;
+  static get HOLE() {
+    return "xx";
   }
 
   static board2fen(b) {
@@ -46,7 +51,7 @@ export class HamiltonRules extends ChessRules {
       for (let i = 0; i < row.length; i++) {
         if (['x'].concat(V.PIECES).includes(row[i].toLowerCase())) sumElts++;
         else {
-          const num = parseInt(row[i]);
+          const num = parseInt(row[i], 10);
           if (isNaN(num)) return false;
           sumElts += num;
         }
@@ -64,6 +69,10 @@ export class HamiltonRules extends ChessRules {
     return side == this.turn;
   }
 
+  hoverHighlight() {
+    return this.movesCount == 0;
+  }
+
   // Initiate the game by choosing a square for the knight:
   doClick(square) {
     if (this.movesCount > 0) return null;
@@ -81,13 +90,7 @@ export class HamiltonRules extends ChessRules {
       return [...Array(64).keys()].map(k => {
         const i = k % 8;
         const j = (k - i) / 8;
-        return new Move({
-          appear: [
-            new PiPo({ x: i, y: j, c: 'w', p: V.KNIGHT })
-          ],
-          vanish: [],
-          start: { x: -1, y: -1 }
-        });
+        return this.doClick([i, j]);
       });
     }
     for (let i=0; i<8; i++) {
@@ -133,6 +136,9 @@ export class HamiltonRules extends ChessRules {
     for (let psq of move.appear) board[psq.x][psq.y] = psq.c + psq.p;
   }
 
+  postPlay() {}
+  postUndo() {}
+
   getCheckSquares() {
     return [];
   }
@@ -154,4 +160,5 @@ export class HamiltonRules extends ChessRules {
     // First game move:
     return "N@" + V.CoordsToSquare(move.end);
   }
+
 };