Draft Ball variant + some fixes, enhancements and code cleaning
[vchess.git] / client / src / variants / Hidden.js
index c79267a..ef5b0bb 100644 (file)
@@ -2,11 +2,15 @@ import { ChessRules, PiPo, Move } from "@/base_rules";
 import { ArrayFun } from "@/utils/array";
 import { randInt } from "@/utils/alea";
 
-export const VariantRules = class HiddenRules extends ChessRules {
+export class HiddenRules extends ChessRules {
   static get HasFlags() {
     return false;
   }
 
+  static get HasCastle() {
+    return false;
+  }
+
   static get HasEnpassant() {
     return false;
   }
@@ -16,9 +20,9 @@ export const VariantRules = class HiddenRules extends ChessRules {
     return false;
   }
 
-  // Moves are revealed only when game ends
+  // Moves are revealed only when game ends, but are highlighted on board
   static get ShowMoves() {
-    return "none";
+    return "highlight";
   }
 
   static get HIDDEN_DECODE() {
@@ -50,7 +54,7 @@ export const VariantRules = class HiddenRules extends ChessRules {
   }
 
   static get PIECES() {
-    return ChessRules.PIECES.concat(Object.values(V.HIDDEN_CODE));
+    return ChessRules.PIECES.concat(Object.keys(V.HIDDEN_DECODE));
   }
 
   // Pieces can be hidden :)
@@ -74,7 +78,7 @@ export const VariantRules = class HiddenRules extends ChessRules {
   }
 
   // Scan board for kings positions (no castling)
-  scanKingsRooks(fen) {
+  scanKings(fen) {
     this.kingPos = { w: [-1, -1], b: [-1, -1] };
     const fenRows = V.ParseFen(fen).position.split("/");
     for (let i = 0; i < fenRows.length; i++) {
@@ -143,20 +147,11 @@ export const VariantRules = class HiddenRules extends ChessRules {
     return mv;
   }
 
-  // What are the king moves from square x,y ?
-  getPotentialKingMoves(sq) {
-    // No castling:
-    return this.getSlideNJumpMoves(
-      sq,
-      V.steps[V.ROOK].concat(V.steps[V.BISHOP]),
-      "oneStep"
-    );
-  }
-
   filterValid(moves) {
     return moves;
   }
 
+  // Ignore randomness here: placement is always random asymmetric
   static GenRandInitFen() {
     let pieces = { w: new Array(8), b: new Array(8) };
     // Shuffle pieces + pawns on two first ranks
@@ -224,8 +219,8 @@ export const VariantRules = class HiddenRules extends ChessRules {
     return [];
   }
 
-  updateVariables(move) {
-    super.updateVariables(move);
+  postPlay(move) {
+    super.postPlay(move);
     if (
       move.vanish.length >= 2 &&
       [V.KING,V.HIDDEN_CODE[V.KING]].includes(move.vanish[1].p)
@@ -235,8 +230,8 @@ export const VariantRules = class HiddenRules extends ChessRules {
     }
   }
 
-  unupdateVariables(move) {
-    super.unupdateVariables(move);
+  postUndo(move) {
+    super.postUndo(move);
     const c = move.vanish[0].c;
     const oppCol = V.GetOppCol(c);
     if (this.kingPos[oppCol][0] < 0)