Add Knightrelay1. Some fixes. Move odd 'isAttackedBy_multiple_colors' to Checkered...
[vchess.git] / client / src / variants / Shatranj.js
index b45d915..969b819 100644 (file)
@@ -19,7 +19,8 @@ export const VariantRules = class ShatranjRules extends ChessRules {
   }
 
   static GenRandInitFen(randomness) {
-    return ChessRules.GenRandInitFen(randomness).replace("w 1111 -", "w");
+    // Remove castle flags and en-passant indication
+    return ChessRules.GenRandInitFen(randomness).slice(0, -7);
   }
 
   getPotentialPawnMoves([x, y]) {
@@ -97,20 +98,20 @@ export const VariantRules = class ShatranjRules extends ChessRules {
     );
   }
 
-  isAttackedByBishop(sq, colors) {
+  isAttackedByBishop(sq, color) {
     return this.isAttackedBySlideNJump(
       sq,
-      colors,
+      color,
       V.BISHOP,
       V.ElephantSteps,
       "oneStep"
     );
   }
 
-  isAttackedByQueen(sq, colors) {
+  isAttackedByQueen(sq, color) {
     return this.isAttackedBySlideNJump(
       sq,
-      colors,
+      color,
       V.QUEEN,
       V.steps[V.BISHOP],
       "oneStep"
@@ -156,7 +157,7 @@ export const VariantRules = class ShatranjRules extends ChessRules {
       // 2 enemy units or more: I lose
       return getScoreLost();
     // I don't have any piece, my opponent have one: can I take it?
-    if (this.isAttacked(piecesLeft[oppCol].square, [color]))
+    if (this.isAttacked(piecesLeft[oppCol].square, color))
       // Yes! But I still need to take it
       return "*";
     // No :(