Forbid capturing wall in Omega chess...
[vchess.git] / client / src / variants / Omega.js
index fa95f5e..5431198 100644 (file)
@@ -36,6 +36,28 @@ export class OmegaRules extends ChessRules {
     return ([V.CHAMPION, V.WIZARD].includes(b[1]) ? "Omega/" : "") + b;
   }
 
+  static IsGoodPosition(position) {
+    if (position.length == 0) return false;
+    const rows = position.split("/");
+    if (rows.length != V.size.x) return false;
+    let kings = { "k": 0, "K": 0 };
+    for (let row of rows) {
+      let sumElts = 0;
+      for (let i = 0; i < row.length; i++) {
+        if (['K','k'].includes(row[i])) kings[row[i]]++;
+        if (['x'].concat(V.PIECES).includes(row[i].toLowerCase())) sumElts++;
+        else {
+          const num = parseInt(row[i]);
+          if (isNaN(num)) return false;
+          sumElts += num;
+        }
+      }
+      if (sumElts != V.size.y) return false;
+    }
+    if (Object.values(kings).some(v => v != 1)) return false;
+    return true;
+  }
+
   // NOTE: keep this extensive check because the board has holes
   static IsGoodEnpassant(enpassant) {
     if (enpassant != "-") {
@@ -206,6 +228,14 @@ export class OmegaRules extends ChessRules {
     return res.slice(0, -1); //remove last comma
   }
 
+  canTake([x1, y1], [x2, y2]) {
+    return (
+      // Cannot take wall :)
+      this.board[x2][y2] != V.NOTHING &&
+      this.getColor(x1, y1) !== this.getColor(x2, y2)
+    );
+  }
+
   // En-passant after 2-sq or 3-sq jumps
   getEpSquare(moveOrSquare) {
     if (!moveOrSquare) return undefined;
@@ -252,7 +282,7 @@ export class OmegaRules extends ChessRules {
     }
   }
 
-  getEnpassanCaptures([x, y], shiftX) {
+  getEnpassantCaptures([x, y], shiftX) {
     const Lep = this.epSquares.length;
     const epSquare = this.epSquares[Lep - 1];
     let moves = [];
@@ -447,4 +477,17 @@ export class OmegaRules extends ChessRules {
       k: 1000
     };
   }
+
+  evalPosition() {
+    let evaluation = 0;
+    for (let i = 0; i < V.size.x; i++) {
+      for (let j = 0; j < V.size.y; j++) {
+        if (![V.EMPTY,V.NOTHING].includes(this.board[i][j])) {
+          const sign = this.getColor(i, j) == "w" ? 1 : -1;
+          evaluation += sign * V.VALUES[this.getPiece(i, j)];
+        }
+      }
+    }
+    return evaluation;
+  }
 };