After refactoring. Seems more or less ok
[xogo.git] / variants / Alice / class.js
index e755b56..d1e389d 100644 (file)
@@ -1,5 +1,5 @@
 import ChessRules from "/base_rules.js";
-import { ArrayFun } from "/utils/array.js";
+import {ArrayFun} from "/utils/array.js";
 
 export default class AliceRules extends ChessRules {
 
@@ -105,7 +105,7 @@ export default class AliceRules extends ChessRules {
   filterValid(moves) {
     const color = this.turn;
     const oppCol = C.GetOppCol(color);
-    const kingPos = this.searchKingPos(color);
+    const kingPos = this.searchKingPos(color)[0];
     const kingPiece = this.getPiece(kingPos[0], kingPos[1]);
     return super.filterValid(moves).filter(m => {
       // A move must also be legal on the board it is played:
@@ -119,7 +119,7 @@ export default class AliceRules extends ChessRules {
       this.playOnBoard(m);
       m.appear.forEach(a => this.toggleWorld(a.x, a.y));
       const kingAppear = m.appear.find(a => this.isKing(0, 0, a.p));
-      const target = kingAppear ? [kingAppear.x, kingAppear.y] : kingPos;
+      const target = [kingAppear ? [kingAppear.x, kingAppear.y] : kingPos];
       const res = this.underCheck(target, oppCol);
       m.appear.forEach(a => this.toggleWorld(a.x, a.y));
       this.undoOnBoard(m);