Several small improvements + integrate options + first working draft of Cwda
[vchess.git] / client / src / variants / Yote.js
index 0b96786..6863026 100644 (file)
@@ -3,6 +3,10 @@ import { randInt } from "@/utils/alea";
 
 export class YoteRules extends ChessRules {
 
+  static get Options() {
+    return null;
+  }
+
   static get HasFlags() {
     return false;
   }
@@ -23,6 +27,25 @@ export class YoteRules extends ChessRules {
     return true;
   }
 
+  static IsGoodPosition(position) {
+    if (position.length == 0) return false;
+    const rows = position.split("/");
+    if (rows.length != V.size.x) return false;
+    for (let row of rows) {
+      let sumElts = 0;
+      for (let i = 0; i < row.length; i++) {
+        if (row[i].toLowerCase() == V.PAWN) sumElts++;
+        else {
+          const num = parseInt(row[i], 10);
+          if (isNaN(num) || num <= 0) return false;
+          sumElts += num;
+        }
+      }
+      if (sumElts != V.size.y) return false;
+    }
+    return true;
+  }
+
   static IsGoodFen(fen) {
     if (!ChessRules.IsGoodFen(fen)) return false;
     const fenParsed = V.ParseFen(fen);
@@ -53,7 +76,7 @@ export class YoteRules extends ChessRules {
     );
   }
 
-  static GenRandInitFen(randomness) {
+  static GenRandInitFen() {
     return "6/6/6/6/6 w 0 12,12 -,-";
   }
 
@@ -120,10 +143,6 @@ export class YoteRules extends ChessRules {
     return { x: 5, y: 6 };
   }
 
-  static get PIECES() {
-    return [V.PAWN];
-  }
-
   getColor(i, j) {
     if (i >= V.size.x) return i == V.size.x ? "w" : "b";
     return this.board[i][j].charAt(0);
@@ -152,8 +171,8 @@ export class YoteRules extends ChessRules {
     return (x < V.size.x && this.getColor(x, y) != side);
   }
 
-  // TODO: hoverHighlight() would well take an arg "side"...
-  hoverHighlight(x, y) {
+  hoverHighlight([x, y], side) {
+    if (!!side && side != this.turn) return false;
     const L = this.captures.length;
     if (!this.captures[L-1]) return false;
     const oppCol = V.GetOppCol(this.turn);
@@ -227,7 +246,7 @@ export class YoteRules extends ChessRules {
       const mv = this.doClick([x, y]);
       return (!!mv ? [mv] : []);
     }
-    if (x >= V.size.x) return this.getReserveMoves([x, y]);
+    if (x >= V.size.x) return this.getReserveMoves(x);
     return this.getPotentialPawnMoves([x, y]);
   }
 
@@ -435,14 +454,6 @@ export class YoteRules extends ChessRules {
     return moves[randInt(moves.length)];
   }
 
-  evalPosition() {
-    let evaluation = super.evalPosition();
-    // Add reserves:
-    evaluation += this.reserve["w"][V.PAWN];
-    evaluation -= this.reserve["b"][V.PAWN];
-    return evaluation;
-  }
-
   getNotation(move) {
     if (move.vanish.length == 0)
       // Placement: