Fix Makruk/Makpong
[vchess.git] / client / src / variants / Makruk.js
index 2da534f..75fb1da 100644 (file)
@@ -3,6 +3,7 @@ import { ArrayFun } from "@/utils/array";
 import { randInt, shuffle } from "@/utils/alea";
 
 export class MakrukRules extends ChessRules {
+
   static get HasFlags() {
     return false;
   }
@@ -11,14 +12,19 @@ export class MakrukRules extends ChessRules {
     return false;
   }
 
+  static get Monochrome() {
+    return true;
+  }
+
+  static get Notoodark() {
+    return true;
+  }
+
   static get PawnSpecs() {
     return Object.assign(
       {},
       ChessRules.PawnSpecs,
-      {
-        twoSquares: false,
-        promotions: [V.QUEEN]
-      }
+      { promotions: [V.QUEEN] }
     );
   }
 
@@ -103,8 +109,14 @@ export class MakrukRules extends ChessRules {
     );
   }
 
+  isAttacked(sq, color) {
+    return (
+      super.isAttacked(sq, color) || this.isAttackedByPromoted(sq, color)
+    );
+  }
+
   isAttackedByBishop(sq, color) {
-    const forward = (this.turn == 'w' ? 1 : -1);
+    const forward = (color == 'w' ? 1 : -1);
     return this.isAttackedBySlideNJump(
       sq,
       color,
@@ -124,6 +136,16 @@ export class MakrukRules extends ChessRules {
     );
   }
 
+  isAttackedByPromoted(sq, color) {
+    return super.isAttackedBySlideNJump(
+      sq,
+      color,
+      V.PROMOTED,
+      V.steps[V.BISHOP],
+      "oneStep"
+    );
+  }
+
   static get VALUES() {
     return {
       p: 1,
@@ -135,4 +157,5 @@ export class MakrukRules extends ChessRules {
       k: 1000
     };
   }
+
 };