Merge branch 'main' of auder.net:xogo
authorBenjamin Auder <benjamin.auder@somewhere>
Sat, 2 Jul 2022 13:32:00 +0000 (15:32 +0200)
committerBenjamin Auder <benjamin.auder@somewhere>
Sat, 2 Jul 2022 13:32:00 +0000 (15:32 +0200)
1  2 
base_rules.js

diff --combined base_rules.js
@@@ -1629,7 -1629,7 +1629,7 @@@ export default class ChessRules 
          m.appear.shift();
          return;
        }
 -      let finalPieces = ["p"];
 +      let finalPieces;
        if (
          this.options["cannibal"] &&
          this.board[x2][y2] != "" &&
        if (initPiece == "!") //cannibal king-pawn
          m.appear[0].p = C.CannibalKingCode[finalPieces[0]];
        for (let i=1; i<finalPieces.length; i++) {
 +        let newMove = JSON.parse(JSON.stringify(m));
          const piece = finalPieces[i];
 -        const tr = {
 -          c: color,
 -          p: (initPiece != "!" ? piece : C.CannibalKingCode[piece])
 -        };
 -        let newMove = this.getBasicMove([x1, y1], [x2, y2], tr);
 +        m.appear[0].p = (initPiece != "!" ? piece : C.CannibalKingCode[piece]);
          moreMoves.push(newMove);
        }
      });
          this.animateFading(arr, () => targetObj.increment());
        }
      }
+     targetObj.target +=
+       this.tryAnimateCastle(move, () => targetObj.increment());
      targetObj.target +=
        this.customAnimate(move, segments, () => targetObj.increment());
      if (targetObj.target == 0)
        callback();
    }
  
+   tryAnimateCastle(move, cb) {
+     if (
+       this.hasCastle &&
+       move.vanish.length == 2 &&
+       move.appear.length == 2 &&
+       this.isKing(0, 0, move.vanish[0].p) &&
+       this.isKing(0, 0, move.appear[0].p)
+     ) {
+       const start = {x: move.vanish[1].x, y: move.vanish[1].y},
+             end = {x: move.appear[1].x, y: move.appear[1].y};
+       const segments = [ [[start.x, start.y], [end.x, end.y]] ];
+       this.animateMoving(start, end, null, segments, cb);
+       return 1;
+     }
+     return 0;
+   }
    // Potential other animations (e.g. for Suction variant)
    customAnimate(move, segments, cb) {
      return 0; //nb of targets