Generalize pawn movements: cleaner and smaller code
[vchess.git] / client / src / variants / Grand.js
index e6333cc..5523244 100644 (file)
@@ -4,7 +4,7 @@ import { randInt } from "@/utils/alea";
 
 // NOTE: initial setup differs from the original; see
 // https://www.chessvariants.com/large.dir/freeling.html
-export const VariantRules = class GrandRules extends ChessRules {
+export class GrandRules extends ChessRules {
   static IsGoodFen(fen) {
     if (!ChessRules.IsGoodFen(fen)) return false;
     const fenParsed = V.ParseFen(fen);
@@ -223,7 +223,7 @@ export const VariantRules = class GrandRules extends ChessRules {
       for (let epsq of epSquare) {
         // TODO: some redundant checks
         if (epsq.x == x + shiftX && Math.abs(epsq.y - y) == 1) {
-          var enpassantMove = this.getBasicMove([x, y], [epsq.x, epsq.y]);
+          let enpassantMove = this.getBasicMove([x, y], [epsq.x, epsq.y]);
           // WARNING: the captured pawn may be diagonally behind us,
           // if it's a 3-squares jump and we take on 1st passing square
           const px = this.board[x][epsq.y] != V.EMPTY ? x : x - shiftX;
@@ -255,20 +255,20 @@ export const VariantRules = class GrandRules extends ChessRules {
     );
   }
 
-  isAttacked(sq, colors) {
+  isAttacked(sq, color) {
     return (
-      super.isAttacked(sq, colors) ||
-      this.isAttackedByMarshall(sq, colors) ||
-      this.isAttackedByCardinal(sq, colors)
+      super.isAttacked(sq, color) ||
+      this.isAttackedByMarshall(sq, color) ||
+      this.isAttackedByCardinal(sq, color)
     );
   }
 
-  isAttackedByMarshall(sq, colors) {
+  isAttackedByMarshall(sq, color) {
     return (
-      this.isAttackedBySlideNJump(sq, colors, V.MARSHALL, V.steps[V.ROOK]) ||
+      this.isAttackedBySlideNJump(sq, color, V.MARSHALL, V.steps[V.ROOK]) ||
       this.isAttackedBySlideNJump(
         sq,
-        colors,
+        color,
         V.MARSHALL,
         V.steps[V.KNIGHT],
         "oneStep"
@@ -276,12 +276,12 @@ export const VariantRules = class GrandRules extends ChessRules {
     );
   }
 
-  isAttackedByCardinal(sq, colors) {
+  isAttackedByCardinal(sq, color) {
     return (
-      this.isAttackedBySlideNJump(sq, colors, V.CARDINAL, V.steps[V.BISHOP]) ||
+      this.isAttackedBySlideNJump(sq, color, V.CARDINAL, V.steps[V.BISHOP]) ||
       this.isAttackedBySlideNJump(
         sq,
-        colors,
+        color,
         V.CARDINAL,
         V.steps[V.KNIGHT],
         "oneStep"