Fix FenUtil.setupPieces and Antiking variants
[xogo.git] / variants / _Antiking / class.js
index e92edab..5838ed6 100644 (file)
@@ -26,17 +26,9 @@ export default class AbstractAntikingRules extends ChessRules {
   }
 
   pieces(color, x, y) {
-    return Object.assign(
-      {
-        'a': {
-          // Move like a king, no attacks
-          "class": "antiking",
-          moves: super.pieces(color, x, y)['k'].moves,
-          attack: []
-        }
-      },
-      super.pieces(color, x, y)
-    );
+    let antikingSpec = super.pieces(color, x, y)['k'];
+    antikingSpec["class"] = "antiking";
+    return Object.assign({'a': antikingSpec}, super.pieces(color, x, y));
   }
 
   isKing(x, y, p) {
@@ -45,8 +37,8 @@ export default class AbstractAntikingRules extends ChessRules {
     return ['k', 'a'].includes(p);
   }
 
-  // NOTE: canTake includes (wrong) captures of antiking,
-  // to not go to low-level using findDestSquares()
+  // NOTE: canTake includes (wrong) captures of (anti)king,
+  // to detect attacks on (anti)kings.
   canTake([x1, y1], [x2, y2]) {
     const piece1 = this.getPiece(x1, y1);
     const color1 = this.getColor(x1, y1);
@@ -57,15 +49,15 @@ export default class AbstractAntikingRules extends ChessRules {
     );
   }
 
-  // Remove captures of antiking (see above)
+  // Remove captures of (anti)king (see above)
   getPotentialMovesFrom([x, y]) {
     return super.getPotentialMovesFrom([x, y]).filter(m =>
-      m.vanish.length == 1 || m.vanish[1].p != 'a');
+      m.vanish.length == 1 || !['k', 'a'].includes(m.vanish[1].p));
   }
 
-  underCheck(squares, color) {
+  underCheck(square_s, color) {
     let res = false;
-    squares.forEach(sq => {
+    square_s.forEach(sq => {
       switch (this.getPiece(sq[0], sq[1])) {
         case 'k':
           res ||= super.underAttack(sq, color);