Attempt to clarify installation instructions a little
[vchess.git] / client / src / variants / Wildebeest.js
index a2fc614..647a234 100644 (file)
@@ -83,7 +83,7 @@ export class WildebeestRules extends ChessRules {
         }
       ];
       if (sx + 2 * step != ex) {
-        //3-squares move
+        // 3-squares move
         res.push({
           x: sx + 2 * step,
           y: sy
@@ -112,10 +112,12 @@ export class WildebeestRules extends ChessRules {
     const [sizeX, sizeY] = [V.size.x, V.size.y];
     const shiftX = color == "w" ? -1 : 1;
     const startRanks = color == "w" ? [sizeX - 2, sizeX - 3] : [1, 2];
-    const lastRank = color == "w" ? 0 : sizeX - 1;
-    const finalPieces = x + shiftX == lastRank
-      ? [V.WILDEBEEST, V.QUEEN]
-      : [V.PAWN];
+    const lastRanks = color == "w" ? [0, 1] : [sizeX - 1, sizeX  -2];
+    let finalPieces = [V.PAWN];
+    if (x + shiftX == lastRanks[1])
+      Array.prototype.push.apply(finalPieces, [V.WILDEBEEST, V.QUEEN]);
+    else if (x + shiftX == lastRanks[0])
+      finalPieces = [V.WILDEBEEST, V.QUEEN];
 
     if (this.board[x + shiftX][y] == V.EMPTY) {
       // One square forward
@@ -179,15 +181,12 @@ export class WildebeestRules extends ChessRules {
   }
 
   getPotentialCamelMoves(sq) {
-    return this.getSlideNJumpMoves(sq, V.steps[V.CAMEL], "oneStep");
+    return this.getSlideNJumpMoves(sq, V.steps[V.CAMEL], 1);
   }
 
   getPotentialWildebeestMoves(sq) {
     return this.getSlideNJumpMoves(
-      sq,
-      V.steps[V.KNIGHT].concat(V.steps[V.CAMEL]),
-      "oneStep"
-    );
+      sq, V.steps[V.KNIGHT].concat(V.steps[V.CAMEL]), 1);
   }
 
   getPPpath(m) {
@@ -228,7 +227,12 @@ export class WildebeestRules extends ChessRules {
       for (let i = range[0]; i <= range[1]; i++) {
         if (i != rookPos && this.isAttacked([x, i], oppCol))
           continue castlingCheck;
-        if (i != y) {
+        if (
+          i != y &&
+          // Do not end in the corner, except if starting square is too near
+          (i > 0 || y == 1) &&
+          (i < V.size.y - 1 || y == V.size.y - 2)
+        ) {
           // Found a possible castle move:
           moves.push(
             new Move({
@@ -269,22 +273,12 @@ export class WildebeestRules extends ChessRules {
 
   isAttackedByCamel(sq, color) {
     return this.isAttackedBySlideNJump(
-      sq,
-      color,
-      V.CAMEL,
-      V.steps[V.CAMEL],
-      "oneStep"
-    );
+      sq, color, V.CAMEL, V.steps[V.CAMEL], 1);
   }
 
   isAttackedByWildebeest(sq, color) {
     return this.isAttackedBySlideNJump(
-      sq,
-      color,
-      V.WILDEBEEST,
-      V.steps[V.KNIGHT].concat(V.steps[V.CAMEL]),
-      "oneStep"
-    );
+      sq, color, V.WILDEBEEST, V.steps[V.KNIGHT].concat(V.steps[V.CAMEL]), 1);
   }
 
   getCurrentScore() {
@@ -304,9 +298,8 @@ export class WildebeestRules extends ChessRules {
     return 2;
   }
 
-  static GenRandInitFen(randomness) {
-    if (!randomness) randomness = 2;
-    if (randomness == 0) {
+  static GenRandInitFen(options) {
+    if (options.randomness == 0) {
       return (
         "rnccwkqbbnr/ppppppppppp/92/92/92/92/92/92/PPPPPPPPPPP/RNBBQKWCCNR " +
         "w 0 akak -"
@@ -316,7 +309,7 @@ export class WildebeestRules extends ChessRules {
     let pieces = { w: new Array(11), b: new Array(11) };
     let flags = "";
     for (let c of ["w", "b"]) {
-      if (c == 'b' && randomness == 1) {
+      if (c == 'b' && options.randomness == 1) {
         pieces['b'] = pieces['w'];
         flags += flags;
         break;