Draft Ball variant + some fixes, enhancements and code cleaning
[vchess.git] / client / src / variants / Antiking2.js
index 3be41af..2dad5e4 100644 (file)
@@ -2,7 +2,7 @@ import { ChessRules } from "@/base_rules";
 import { ArrayFun } from "@/utils/array";
 import { randInt } from "@/utils/alea";
 
-export const VariantRules = class Antiking2Rules extends ChessRules {
+export class Antiking2Rules extends ChessRules {
   static get ANTIKING() {
     return "a";
   }
@@ -15,6 +15,19 @@ export const VariantRules = class Antiking2Rules extends ChessRules {
     return b[1] == "a" ? "Antiking/" + b : b;
   }
 
+  static IsGoodPosition(position) {
+    if (!ChessRules.IsGoodPosition(position)) return false;
+    const rows = position.split("/");
+    // Check that exactly one antiking of each color is there:
+    let antikings = { 'a': 0, 'A': 0 };
+    for (let row of rows) {
+      for (let i = 0; i < row.length; i++)
+        if (['A','a'].includes(row[i])) antikings[row[i]]++;
+    }
+    if (Object.values(antikings).some(v => v != 1)) return false;
+    return true;
+  }
+
   setOtherVariables(fen) {
     super.setOtherVariables(fen);
     this.antikingPos = { w: [-1, -1], b: [-1, -1] };
@@ -132,21 +145,6 @@ export const VariantRules = class Antiking2Rules extends ChessRules {
       this.antikingPos[c] = [move.start.x, move.start.y];
   }
 
-  getCurrentScore() {
-    if (this.atLeastOneMove())
-      return "*";
-
-    const color = this.turn;
-    const oppCol = V.GetOppCol(color);
-    if (
-      !this.isAttacked(this.kingPos[color], oppCol) &&
-      this.isAttacked(this.antikingPos[color], oppCol)
-    ) {
-      return "1/2";
-    }
-    return color == "w" ? "0-1" : "1-0";
-  }
-
   static get VALUES() {
     return Object.assign(
       { a: 1000 },