Several small improvements + integrate options + first working draft of Cwda
[vchess.git] / client / src / variants / Sittuyin.js
index f37eabf..a18c2f0 100644 (file)
@@ -2,6 +2,11 @@ import { ChessRules, Move, PiPo } from "@/base_rules";
 import { randInt } from "@/utils/alea";
 
 export class SittuyinRules extends ChessRules {
+
+  static get Options() {
+    return null;
+  }
+
   static get HasFlags() {
     return false;
   }
@@ -10,12 +15,26 @@ export class SittuyinRules extends ChessRules {
     return false;
   }
 
+  static get Monochrome() {
+    return true;
+  }
+
+  static get Notoodark() {
+    return true;
+  }
+
+  static get Lines() {
+    return ChessRules.Lines.concat([
+      [[0, 0], [8, 8]],
+      [[0, 8], [8, 0]]
+    ]);
+  }
+
   static get PawnSpecs() {
     return Object.assign(
       {},
       ChessRules.PawnSpecs,
       {
-        twoSquares: false,
         // Promotions are handled differently here
         promotions: [V.QUEEN]
       }
@@ -119,29 +138,20 @@ export class SittuyinRules extends ChessRules {
 
   getPotentialPawnMoves([x, y]) {
     const color = this.turn;
-    const [sizeX, sizeY] = [V.size.x, V.size.y];
     const shiftX = V.PawnSpecs.directions[color];
     let moves = [];
-    // NOTE: next condition is generally true (no pawn on last rank)
-    if (x + shiftX >= 0 && x + shiftX < sizeX) {
-      if (this.board[x + shiftX][y] == V.EMPTY) {
+    if (x + shiftX >= 0 && x + shiftX < 8) {
+      if (this.board[x + shiftX][y] == V.EMPTY)
         // One square forward
         moves.push(this.getBasicMove([x, y], [x + shiftX, y]));
-      }
       // Captures
-      if (V.PawnSpecs.canCapture) {
-        for (let shiftY of [-1, 1]) {
-          if (
-            y + shiftY >= 0 &&
-            y + shiftY < sizeY
-          ) {
-            if (
-              this.board[x + shiftX][y + shiftY] != V.EMPTY &&
-              this.canTake([x, y], [x + shiftX, y + shiftY])
-            ) {
-              moves.push(this.getBasicMove([x, y], [x + shiftX, y + shiftY]));
-            }
-          }
+      for (let shiftY of [-1, 1]) {
+        if (
+          y + shiftY >= 0 && y + shiftY < 8 &&
+          this.board[x + shiftX][y + shiftY] != V.EMPTY &&
+          this.canTake([x, y], [x + shiftX, y + shiftY])
+        ) {
+          moves.push(this.getBasicMove([x, y], [x + shiftX, y + shiftY]));
         }
       }
     }
@@ -254,18 +264,11 @@ export class SittuyinRules extends ChessRules {
   getPotentialBishopMoves(sq) {
     const forward = (this.turn == 'w' ? -1 : 1);
     return this.getSlideNJumpMoves(
-      sq,
-      V.steps[V.BISHOP].concat([ [forward, 0] ]),
-      "oneStep"
-    );
+      sq, V.steps[V.BISHOP].concat([ [forward, 0] ]), 1);
   }
 
   getPotentialQueenMoves(sq) {
-    return this.getSlideNJumpMoves(
-      sq,
-      V.steps[V.BISHOP],
-      "oneStep"
-    );
+    return this.getSlideNJumpMoves(sq, V.steps[V.BISHOP], 1);
   }
 
   getAllValidMoves() {
@@ -283,22 +286,12 @@ export class SittuyinRules extends ChessRules {
   isAttackedByBishop(sq, color) {
     const forward = (this.turn == 'w' ? 1 : -1);
     return this.isAttackedBySlideNJump(
-      sq,
-      color,
-      V.BISHOP,
-      V.steps[V.BISHOP].concat([ [forward, 0] ]),
-      "oneStep"
-    );
+      sq, color, V.BISHOP, V.steps[V.BISHOP].concat([ [forward, 0] ]), 1);
   }
 
   isAttackedByQueen(sq, color) {
     return this.isAttackedBySlideNJump(
-      sq,
-      color,
-      V.QUEEN,
-      V.steps[V.BISHOP],
-      "oneStep"
-    );
+      sq, color, V.QUEEN, V.steps[V.BISHOP], 1);
   }
 
   underCheck(color) {
@@ -397,4 +390,5 @@ export class SittuyinRules extends ChessRules {
     }
     return super.getNotation(move);
   }
+
 };