+ setOtherVariables(fen) {
+ super.setOtherVariables(fen);
+ this.subTurn = 1;
+ // Local stack of "action moves"
+ this.amoves = [];
+ const amove = V.ParseFen(fen).amove;
+ if (amove != "-") {
+ const amoveParts = amove.split("/");
+ let amove = {
+ // No need for start & end
+ appear: [],
+ vanish: []
+ };
+ [0, 1].map(i => {
+ amoveParts[i].split(".").forEach(av => {
+ // Format is "bpe3"
+ const xy = V.SquareToCoords(av.substr(2));
+ move[i == 0 ? "appear" : "vanish"].push(
+ new PiPo({
+ x: xy.x,
+ y: xy.y,
+ c: av[0],
+ p: av[1]
+ })
+ );
+ });
+ });
+ this.amoves.push(move);
+ }
+ // Stack "first moves" (on subTurn 1) to merge and check opposite moves
+ this.firstMove = [];
+ }
+
+ static ParseFen(fen) {
+ return Object.assign(
+ ChessRules.ParseFen(fen),
+ { amove: fen.split(" ")[4] }
+ );
+ }
+
+ static IsGoodFen(fen) {
+ if (!ChessRules.IsGoodFen(fen)) return false;
+ const fenParts = fen.split(" ");
+ if (fenParts.length != 6) return false;
+ if (fenParts[5] != "-" && !fenParts[5].match(/^([a-h][1-8]){2}$/))
+ return false;
+ return true;
+ }
+
+ getFen() {
+ return super.getFen() + " " + this.getAmoveFen();
+ }
+
+ getFenForRepeat() {
+ return super.getFenForRepeat() + "_" + this.getAmoveFen();
+ }
+
+ getAmoveFen() {
+ const L = this.amoves.length;
+ return (
+ ["appear","vanish"].map(
+ mpart => {
+ return (
+ this.amoves[L-1][mpart].map(
+ av => {
+ const square = V.CoordsToSquare({ x: av.x, y: av.y });
+ return av.c + av.p + square;
+ }
+ ).join(".")
+ );
+ }
+ ).join("/")
+ );
+ }
+
+ canTake() {
+ // Captures don't occur (only pulls & pushes)
+ return false;
+ }
+
+ // "pa": piece (as a square) doing this push/pull action
+ getActionMoves([sx, sy], [ex, ey], pa) {
+ const color = this.getColor(sx, sy);
+ const lastRank = (color == 'w' ? 0 : 7);
+ const piece = this.getPiece(sx, sy);
+ let moves = [];
+ if (ex == lastRank && piece == V.PAWN) {
+ // Promotion by push or pull
+ V.PawnSpecs.promotions.forEach(p => {
+ let move = super.getBasicMove([sx, sy], [ex, ey], { c: color, p: p });
+ moves.push(move);
+ });
+ } else moves.push(super.getBasicMove([sx, sy], [ex, ey]));
+ return moves;
+ }
+
+ // Actions on piece on square "sq", by color "color"