Several small improvements + integrate options + first working draft of Cwda
[vchess.git] / client / src / variants / Omega.js
index 289c05b..29b58e5 100644 (file)
@@ -17,6 +17,10 @@ export class OmegaRules extends ChessRules {
     );
   }
 
+  static get DarkBottomRight() {
+    return true;
+  }
+
   // For space between corners:
   static get NOTHING() {
     return "xx";
@@ -136,8 +140,8 @@ export class OmegaRules extends ChessRules {
     );
   }
 
-  static GenRandInitFen(randomness) {
-    if (randomness == 0) {
+  static GenRandInitFen(options) {
+    if (options.randomness == 0) {
       return (
         "wxxxxxxxxxxw/xcrnbqkbnrcx/xppppppppppx/x91x/x91x/x91x/" +
         "x91x/x91x/x91x/xPPPPPPPPPPx/xCRNBQKBNRCx/WxxxxxxxxxxW " +
@@ -149,7 +153,7 @@ export class OmegaRules extends ChessRules {
     let flags = "";
     // Shuffle pieces on first (and last rank if randomness == 2)
     for (let c of ["w", "b"]) {
-      if (c == 'b' && randomness == 1) {
+      if (c == 'b' && options.randomness == 1) {
         pieces['b'] = pieces['w'];
         flags += flags;
         break;
@@ -274,12 +278,9 @@ export class OmegaRules extends ChessRules {
 
   getPotentialMovesFrom([x, y]) {
     switch (this.getPiece(x, y)) {
-      case V.CHAMPION:
-        return this.getPotentialChampionMoves([x, y]);
-      case V.WIZARD:
-        return this.getPotentialWizardMoves([x, y]);
-      default:
-        return super.getPotentialMovesFrom([x, y]);
+      case V.CHAMPION: return this.getPotentialChampionMoves([x, y]);
+      case V.WIZARD: return this.getPotentialWizardMoves([x, y]);
+      default: return super.getPotentialMovesFrom([x, y]);
     }
   }
 
@@ -308,28 +309,22 @@ export class OmegaRules extends ChessRules {
     return moves;
   }
 
-  addPawnMoves([x1, y1], [x2, y2], moves, promotions) {
-    let finalPieces = [V.PAWN];
+  addPawnMoves([x1, y1], [x2, y2], moves) {
     const color = this.turn;
     const lastRank = (color == "w" ? 1 : V.size.x - 2);
-    if (x2 == lastRank) {
-      // promotions arg: special override for Hiddenqueen variant
-      if (!!promotions) finalPieces = promotions;
-      else if (!!V.PawnSpecs.promotions) finalPieces = V.PawnSpecs.promotions;
-    }
-    let tr = null;
+    const finalPieces = (x2 == lastRank ? V.PawnSpecs.promotions : [V.PAWN]);
     for (let piece of finalPieces) {
-      tr = (piece != V.PAWN ? { c: color, p: piece } : null);
+      const tr = (piece != V.PAWN ? { c: color, p: piece } : null);
       moves.push(this.getBasicMove([x1, y1], [x2, y2], tr));
     }
   }
 
   getPotentialChampionMoves(sq) {
-    return this.getSlideNJumpMoves(sq, V.steps[V.CHAMPION], "oneStep");
+    return this.getSlideNJumpMoves(sq, V.steps[V.CHAMPION], 1);
   }
 
   getPotentialWizardMoves(sq) {
-    return this.getSlideNJumpMoves(sq, V.steps[V.WIZARD], "oneStep");
+    return this.getSlideNJumpMoves(sq, V.steps[V.WIZARD], 1);
   }
 
   getCastleMoves([x, y]) {
@@ -351,14 +346,14 @@ export class OmegaRules extends ChessRules {
   isAttackedByWizard(sq, color) {
     return (
       this.isAttackedBySlideNJump(
-        sq, color, V.WIZARD, V.steps[V.WIZARD], "oneStep")
+        sq, color, V.WIZARD, V.steps[V.WIZARD], 1)
     );
   }
 
   isAttackedByChampion(sq, color) {
     return (
       this.isAttackedBySlideNJump(
-        sq, color, V.CHAMPION, V.steps[V.CHAMPION], "oneStep")
+        sq, color, V.CHAMPION, V.steps[V.CHAMPION], 1)
     );
   }