1 import { ChessRules
, PiPo
, Move
} from "@/base_rules";
2 import { randInt
} from "@/utils/alea";
4 export class PacosakoRules
extends ChessRules
{
6 static get IMAGE_EXTENSION() {
10 // Unions (left = white if upperCase, black otherwise)
38 // Underscore is character 95, in file w_
39 return f
.charCodeAt() <= 95 ? "w" + f
.toLowerCase() : "b" + f
;
42 static IsGoodPosition(position
) {
43 if (position
.length
== 0) return false;
44 const rows
= position
.split("/");
45 if (rows
.length
!= V
.size
.x
) return false;
46 let kingSymb
= ['k', 'g', 'm', 'u', 'x', '_'];
47 let kings
= { 'k': 0, 'K': 0 };
48 for (let row
of rows
) {
50 for (let i
= 0; i
< row
.length
; i
++) {
51 const lowR
= row
[i
].toLowerCase
52 if (!!(row
[i
].toLowerCase().match(/[a-z_]/))) {
54 if (kingSymb
.includes(row
[i
])) kings
['k']++;
55 // Not "else if", if two kings dancing together
56 if (kingSymb
.some(s
=> row
[i
] == s
.toUpperCase())) kings
['K']++;
59 const num
= parseInt(row
[i
], 10);
60 if (isNaN(num
) || num
<= 0) return false;
64 if (sumElts
!= V
.size
.y
) return false;
66 // Both kings should be on board. Exactly one per color.
67 if (Object
.values(kings
).some(v
=> v
!= 1)) return false;
72 return "Pacosako/" + b
;
76 if (ChessRules
.PIECES
.includes(m
.appear
[0].p
)) return super.getPPpath(m
);
77 // For an union, show only relevant piece:
78 // The color must be deduced from the move: reaching final rank of who?
79 const color
= (m
.appear
[0].x
== 0 ? 'w' : 'b');
80 const up
= this.getUnionPieces(m
.appear
[0].c
, m
.appear
[0].p
);
81 return "Pacosako/" + color
+ up
[color
];
84 canTake([x1
, y1
], [x2
, y2
]) {
85 const p1
= this.board
[x1
][y1
].charAt(1);
86 if (!(ChessRules
.PIECES
.includes(p1
))) return false;
87 const p2
= this.board
[x2
][y2
].charAt(1);
88 if (!(ChessRules
.PIECES
.includes(p2
))) return true;
89 const c1
= this.board
[x1
][y1
].charAt(0);
90 const c2
= this.board
[x2
][y2
].charAt(0);
94 canIplay(side
, [x
, y
]) {
98 !(ChessRules
.PIECES
.includes(this.board
[x
][y
].charAt(1))) ||
99 this.board
[x
][y
].charAt(0) == side
105 this.kingPos
= { w: [-1, -1], b: [-1, -1] };
106 const fenRows
= V
.ParseFen(fen
).position
.split("/");
107 const startRow
= { 'w': V
.size
.x
- 1, 'b': 0 };
108 const kingSymb
= ['k', 'g', 'm', 'u', 'x', '_'];
109 for (let i
= 0; i
< fenRows
.length
; i
++) {
111 for (let j
= 0; j
< fenRows
[i
].length
; j
++) {
112 const c
= fenRows
[i
].charAt(j
);
113 if (!!(c
.toLowerCase().match(/[a-z_]/))) {
114 if (kingSymb
.includes(c
))
115 this.kingPos
["b"] = [i
, k
];
116 // Not "else if", in case of two kings dancing together
117 if (kingSymb
.some(s
=> c
== s
.toUpperCase()))
118 this.kingPos
["w"] = [i
, k
];
121 const num
= parseInt(fenRows
[i
].charAt(j
), 10);
122 if (!isNaN(num
)) k
+= num
- 1;
129 setOtherVariables(fen
) {
130 super.setOtherVariables(fen
);
131 // Stack of "last move" only for intermediate chaining
132 this.lastMoveEnd
= [null];
133 // Local stack of non-capturing union moves:
135 const umove
= V
.ParseFen(fen
).umove
;
136 if (umove
== "-") this.umoves
.push(null);
139 start: ChessRules
.SquareToCoords(umove
.substr(0, 2)),
140 end: ChessRules
.SquareToCoords(umove
.substr(2))
145 static IsGoodFen(fen
) {
146 if (!ChessRules
.IsGoodFen(fen
)) return false;
147 const fenParts
= fen
.split(" ");
148 if (fenParts
.length
!= 6) return false;
149 if (fenParts
[5] != "-" && !fenParts
[5].match(/^([a-h][1-8]){2}$/))
154 static IsGoodFlags(flags
) {
155 // 4 for castle + 16 for pawns
156 return !!flags
.match(/^[a-z]{4,4}[01]{16,16}$/);
160 super.setFlags(fenflags
); //castleFlags
162 w: [...Array(8)], //pawns can move 2 squares?
165 const flags
= fenflags
.substr(4); //skip first 4 letters, for castle
166 for (let c
of ["w", "b"]) {
167 for (let i
= 0; i
< 8; i
++)
168 this.pawnFlags
[c
][i
] = flags
.charAt((c
== "w" ? 0 : 8) + i
) == "1";
173 return [this.castleFlags
, this.pawnFlags
];
176 disaggregateFlags(flags
) {
177 this.castleFlags
= flags
[0];
178 this.pawnFlags
= flags
[1];
183 move.vanish
.length
== 1 &&
184 !(ChessRules
.PIECES
.includes(move.appear
[0].p
))
187 return { start: move.start
, end: move.end
};
192 static ParseFen(fen
) {
193 const fenParts
= fen
.split(" ");
194 return Object
.assign(
195 ChessRules
.ParseFen(fen
),
196 { umove: fenParts
[5] }
200 static GenRandInitFen(randomness
) {
201 // Add 16 pawns flags + empty umove:
202 return ChessRules
.GenRandInitFen(randomness
)
203 .slice(0, -2) + "1111111111111111 - -";
207 let fen
= super.getFlagsFen();
209 for (let c
of ["w", "b"])
210 for (let i
= 0; i
< 8; i
++) fen
+= (this.pawnFlags
[c
][i
] ? "1" : "0");
215 const L
= this.umoves
.length
;
219 : ChessRules
.CoordsToSquare(this.umoves
[L
- 1].start
) +
220 ChessRules
.CoordsToSquare(this.umoves
[L
- 1].end
)
225 return super.getFen() + " " + this.getUmoveFen();
229 return super.getFenForRepeat() + "_" + this.getUmoveFen();
233 const p
= this.board
[i
][j
].charAt(1);
234 if (ChessRules
.PIECES
.includes(p
)) return super.getColor(i
, j
);
235 return this.turn
; //union: I can use it, so it's "my" color...
238 getPiece(i
, j
, color
) {
239 const p
= this.board
[i
][j
].charAt(1);
240 if (ChessRules
.PIECES
.includes(p
)) return p
;
241 const c
= this.board
[i
][j
].charAt(0);
242 // NOTE: this.turn == HACK, but should work...
243 color
= color
|| this.turn
;
244 return V
.UNIONS
[p
][c
== color
? 0 : 1];
247 getUnionPieces(color
, code
) {
248 const pieces
= V
.UNIONS
[code
];
250 w: pieces
[color
== 'w' ? 0 : 1],
251 b: pieces
[color
== 'b' ? 0 : 1]
255 // p1: white piece, p2: black piece
256 getUnionCode(p1
, p2
) {
258 Object
.values(V
.UNIONS
).findIndex(v
=> v
[0] == p1
&& v
[1] == p2
)
260 const c
= (uIdx
>= 0 ? 'w' : 'b');
263 Object
.values(V
.UNIONS
).findIndex(v
=> v
[0] == p2
&& v
[1] == p1
)
266 return { c: c
, p: Object
.keys(V
.UNIONS
)[uIdx
] };
269 getBasicMove([sx
, sy
], [ex
, ey
], tr
) {
270 const L
= this.lastMoveEnd
.length
;
271 const lm
= this.lastMoveEnd
[L
-1];
272 const piece
= (!!lm
? lm
.p : null);
273 const initColor
= (!!piece
? this.turn : this.board
[sx
][sy
].charAt(0));
274 const initPiece
= (piece
|| this.board
[sx
][sy
].charAt(1));
276 const oppCol
= V
.GetOppCol(c
);
277 if (!!tr
&& !(ChessRules
.PIECES
.includes(initPiece
))) {
278 // Transformation computed without taking union into account
279 const up
= this.getUnionPieces(initColor
, initPiece
);
280 let args
= [tr
.p
, up
[oppCol
]];
281 if (c
== 'b') args
= args
.reverse();
282 const cp
= this.getUnionCode(args
[0], args
[1]);
287 // - union to free square (other cases are illegal: return null)
288 // - normal piece to free square,
289 // to enemy normal piece, or
290 // to union (releasing our piece)
292 start: { x: sx
, y: sy
},
293 end: { x: ex
, y: ey
},
306 // Treat free square cases first:
307 if (this.board
[ex
][ey
] == V
.EMPTY
) {
312 c: !!tr
? tr
.c : initColor
,
313 p: !!tr
? tr
.p : initPiece
318 // Now the two cases with union / release:
319 const destColor
= this.board
[ex
][ey
].charAt(0);
320 const destPiece
= this.board
[ex
][ey
].charAt(1);
329 if (ChessRules
.PIECES
.includes(destPiece
)) {
330 // Normal piece: just create union
331 let args
= [!!tr
? tr
.p : initPiece
, destPiece
];
332 if (c
== 'b') args
= args
.reverse();
333 const cp
= this.getUnionCode(args
[0], args
[1]);
344 // Releasing a piece in an union: keep track of released piece
345 const up
= this.getUnionPieces(destColor
, destPiece
);
346 let args
= [!!tr
? tr
.p : initPiece
, up
[oppCol
]];
347 if (c
== 'b') args
= args
.reverse();
348 const cp
= this.getUnionCode(args
[0], args
[1]);
361 getPotentialMovesFrom([x
, y
]) {
362 const L
= this.lastMoveEnd
.length
;
363 const lm
= this.lastMoveEnd
[L
-1];
364 if (!!lm
&& (x
!= lm
.x
|| y
!= lm
.y
)) return [];
365 const piece
= (!!lm
? lm
.p : this.getPiece(x
, y
));
367 var saveSquare
= this.board
[x
][y
];
368 this.board
[x
][y
] = this.turn
+ piece
;
372 switch (piece
|| this.getPiece(x
, y
)) {
374 const firstRank
= (c
== 'w' ? 7 : 0);
375 baseMoves
= this.getPotentialPawnMoves([x
, y
]).filter(m
=> {
376 // Skip forbidden 2-squares jumps (except from first rank)
377 // Also skip unions capturing en-passant (not allowed).
380 m
.start
.x
== firstRank
||
381 Math
.abs(m
.end
.x
- m
.start
.x
) == 1 ||
382 this.pawnFlags
[c
][m
.start
.y
]
386 this.board
[x
][y
].charAt(1) == V
.PAWN
||
394 baseMoves
= this.getPotentialRookMoves([x
, y
]);
397 baseMoves
= this.getPotentialKnightMoves([x
, y
]);
400 baseMoves
= this.getPotentialBishopMoves([x
, y
]);
403 baseMoves
= this.getPotentialQueenMoves([x
, y
]);
406 baseMoves
= this.getPotentialKingMoves([x
, y
]);
409 // When a pawn in an union reaches final rank with a non-standard
410 // promotion move: apply promotion anyway
412 const oppCol
= V
.GetOppCol(c
);
413 const oppLastRank
= (c
== 'w' ? 7 : 0);
414 baseMoves
.forEach(m
=> {
416 m
.end
.x
== oppLastRank
&&
417 ['c', 'd', 'e', 'f', 'g'].includes(m
.appear
[0].p
)
419 // Move to first rank, which is last rank for opponent's pawn.
420 // => Show promotion choices.
421 // Find our piece in union (not a pawn)
422 const up
= this.getUnionPieces(m
.appear
[0].c
, m
.appear
[0].p
);
423 // merge with all potential promotion pieces + push (loop)
424 for (let promotionPiece
of [V
.ROOK
, V
.KNIGHT
, V
.BISHOP
, V
.QUEEN
]) {
425 let args
= [up
[c
], promotionPiece
];
426 if (c
== 'b') args
= args
.reverse();
427 const cp
= this.getUnionCode(args
[0], args
[1]);
428 let cpMove
= JSON
.parse(JSON
.stringify(m
));
429 cpMove
.appear
[0].c
= cp
.c
;
430 cpMove
.appear
[0].p
= cp
.p
;
436 m
.vanish
.length
> 0 &&
437 m
.vanish
[0].p
== V
.PAWN
&&
438 m
.start
.y
!= m
.end
.y
&&
439 this.board
[m
.end
.x
][m
.end
.y
] == V
.EMPTY
442 // No en-passant inside a chaining
444 // Fix en-passant capture: union type, maybe released piece too
445 const cs
= [m
.end
.x
+ (c
== 'w' ? 1 : -1), m
.end
.y
];
446 const color
= this.board
[cs
[0]][cs
[1]].charAt(0);
447 const code
= this.board
[cs
[0]][cs
[1]].charAt(1);
448 if (code
== V
.PAWN
) {
449 // Simple en-passant capture (usual: just form union)
454 // An union pawn + something juste moved two squares
455 const up
= this.getUnionPieces(color
, code
);
457 let args
= [V
.PAWN
, up
[oppCol
]];
458 if (c
== 'b') args
= args
.reverse();
459 const cp
= this.getUnionCode(args
[0], args
[1]);
460 m
.appear
[0].c
= cp
.c
;
461 m
.appear
[0].p
= cp
.p
;
467 if (!!lm
) this.board
[x
][y
] = saveSquare
;
471 getEpSquare(moveOrSquare
) {
472 if (typeof moveOrSquare
=== "string") {
473 const square
= moveOrSquare
;
474 if (square
== "-") return undefined;
475 return V
.SquareToCoords(square
);
477 const move = moveOrSquare
;
478 const s
= move.start
,
480 const oppCol
= V
.GetOppCol(this.turn
);
483 Math
.abs(s
.x
- e
.x
) == 2 &&
484 this.getPiece(s
.x
, s
.y
, oppCol
) == V
.PAWN
494 // Does m2 un-do m1 ? (to disallow undoing union moves)
495 oppositeMoves(m1
, m2
) {
498 !(ChessRules
.PIECES
.includes(m2
.appear
[0].p
)) &&
499 m2
.vanish
.length
== 1 &&
501 m1
.start
.x
== m2
.end
.x
&&
502 m1
.end
.x
== m2
.start
.x
&&
503 m1
.start
.y
== m2
.end
.y
&&
504 m1
.end
.y
== m2
.start
.y
508 getCastleMoves([x
, y
]) {
509 const c
= this.getColor(x
, y
);
510 const oppCol
= V
.GetOppCol(c
);
512 const finalSquares
= [ [2, 3], [6, 5] ];
513 castlingCheck: for (let castleSide
= 0; castleSide
< 2; castleSide
++) {
514 if (this.castleFlags
[c
][castleSide
] >= 8) continue;
515 const rookPos
= this.castleFlags
[c
][castleSide
];
516 const castlingColor
= this.board
[x
][rookPos
].charAt(0);
517 const castlingPiece
= this.board
[x
][rookPos
].charAt(1);
519 // Nothing on the path of the king ?
520 const finDist
= finalSquares
[castleSide
][0] - y
;
521 let step
= finDist
/ Math
.max(1, Math
.abs(finDist
));
523 let kingSquares
= [y
];
527 this.board
[x
][i
] != V
.EMPTY
&&
528 (this.getColor(x
, i
) != c
|| ![y
, rookPos
].includes(i
))
531 continue castlingCheck
;
535 } while (i
!= finalSquares
[castleSide
][0]);
536 // No checks on the path of the king ?
537 if (this.isAttacked(kingSquares
, oppCol
)) continue castlingCheck
;
539 // Nothing on the path to the rook?
540 step
= castleSide
== 0 ? -1 : 1;
541 for (i
= y
+ step
; i
!= rookPos
; i
+= step
) {
542 if (this.board
[x
][i
] != V
.EMPTY
) continue castlingCheck
;
545 // Nothing on final squares, except maybe king and castling rook?
546 for (i
= 0; i
< 2; i
++) {
548 finalSquares
[castleSide
][i
] != rookPos
&&
549 this.board
[x
][finalSquares
[castleSide
][i
]] != V
.EMPTY
&&
551 finalSquares
[castleSide
][i
] != y
||
552 this.getColor(x
, finalSquares
[castleSide
][i
]) != c
555 continue castlingCheck
;
564 y: finalSquares
[castleSide
][0],
570 y: finalSquares
[castleSide
][1],
576 // King might be initially disguised (Titan...)
577 new PiPo({ x: x
, y: y
, p: V
.KING
, c: c
}),
578 new PiPo({ x: x
, y: rookPos
, p: castlingPiece
, c: castlingColor
})
581 Math
.abs(y
- rookPos
) <= 2
582 ? { x: x
, y: rookPos
}
583 : { x: x
, y: y
+ 2 * (castleSide
== 0 ? -1 : 1) }
591 getEnpassantCaptures(sq
, shiftX
) {
592 // HACK: when artificially change turn, do not consider en-passant
593 const mcMod2
= this.movesCount
% 2;
595 if ((c
== 'w' && mcMod2
== 1) || (c
== 'b' && mcMod2
== 0)) return [];
596 return super.getEnpassantCaptures(sq
, shiftX
);
599 isAttacked_aux(files
, color
, positions
, fromSquare
, released
) {
600 // "positions" = array of FENs to detect infinite loops. Example:
601 // r1q1k2r/p1Pb1ppp/5n2/1f1p4/AV5P/P1eDP3/3B1PP1/R3K1NR,
602 // Bxd2 Bxc3 Bxb4 Bxc3 Bxb4 etc.
603 const newPos
= { fen: super.getBaseFen(), piece: released
};
604 if (positions
.some(p
=> p
.piece
== newPos
.piece
&& p
.fen
== newPos
.fen
))
605 // Start of an infinite loop: exit
607 positions
.push(newPos
);
608 const rank
= (color
== 'w' ? 0 : 7);
609 const moves
= this.getPotentialMovesFrom(fromSquare
);
610 if (moves
.some(m
=> m
.end
.x
== rank
&& files
.includes(m
.end
.y
)))
613 for (let m
of moves
) {
615 // Turn won't change since !!m.released
617 const res
= this.isAttacked_aux(
618 files
, color
, positions
, [m
.end
.x
, m
.end
.y
], m
.released
);
620 if (res
) return true;
626 isAttacked(files
, color
) {
627 const rank
= (color
== 'w' ? 0 : 7);
628 // Since it's too difficult (impossible?) to search from the square itself,
629 // let's adopt a suboptimal but working strategy: find all attacks.
631 // Artificial turn change is required:
634 outerLoop: for (let i
=0; i
<8; i
++) {
635 for (let j
=0; j
<8; j
++) {
636 // Attacks must start from a normal piece, not an union.
637 // Therefore, the following test is correct.
639 this.board
[i
][j
] != V
.EMPTY
&&
640 // Do not start with king (irrelevant, and lead to infinite calls)
641 [V
.PAWN
, V
.ROOK
, V
.KNIGHT
, V
.BISHOP
, V
.QUEEN
].includes(
642 this.board
[i
][j
].charAt(1)) &&
643 this.board
[i
][j
].charAt(0) == color
646 const moves
= this.getPotentialMovesFrom([i
, j
]);
647 if (moves
.some(m
=> m
.end
.x
== rank
&& files
.includes(m
.end
.y
))) {
651 for (let m
of moves
) {
653 // Turn won't change since !!m.released
656 res
= this.isAttacked_aux(
657 files
, color
, positions
, [m
.end
.x
, m
.end
.y
], m
.released
);
659 if (res
) break outerLoop
;
669 // Do not consider checks, except to forbid castling
674 if (moves
.length
== 0) return [];
675 const L
= this.umoves
.length
; //at least 1: init from FEN
676 return moves
.filter(m
=> !this.oppositeMoves(this.umoves
[L
- 1], m
));
679 updateCastleFlags(move, piece
) {
681 const firstRank
= (c
== "w" ? 7 : 0);
682 if (piece
== V
.KING
&& move.appear
.length
> 0)
683 this.castleFlags
[c
] = [V
.size
.y
, V
.size
.y
];
685 move.start
.x
== firstRank
&&
686 this.castleFlags
[c
].includes(move.start
.y
)
688 const flagIdx
= (move.start
.y
== this.castleFlags
[c
][0] ? 0 : 1);
689 this.castleFlags
[c
][flagIdx
] = V
.size
.y
;
692 move.end
.x
== firstRank
&&
693 this.castleFlags
[c
].includes(move.end
.y
)
695 // Move to our rook: necessary normal piece, to union, releasing
696 // (or the rook was moved before!)
697 const flagIdx
= (move.end
.y
== this.castleFlags
[c
][0] ? 0 : 1);
698 this.castleFlags
[c
][flagIdx
] = V
.size
.y
;
703 // Easier before move is played in this case (flags are saved)
705 const L
= this.lastMoveEnd
.length
;
706 const lm
= this.lastMoveEnd
[L
-1];
707 const piece
= (!!lm
? lm
.p : move.vanish
[0].p
);
709 this.kingPos
[c
] = [move.appear
[0].x
, move.appear
[0].y
];
710 this.updateCastleFlags(move, piece
);
711 const pawnFirstRank
= (c
== 'w' ? 6 : 1);
712 if (move.start
.x
== pawnFirstRank
)
713 // This move (potentially) turns off a 2-squares pawn flag
714 this.pawnFlags
[c
][move.start
.y
] = false;
718 move.flags
= JSON
.stringify(this.aggregateFlags());
720 this.epSquares
.push(this.getEpSquare(move));
721 // Check if the move is the last of the turn: all cases except releases
722 if (!move.released
) {
723 // No more union releases available
724 this.turn
= V
.GetOppCol(this.turn
);
726 this.lastMoveEnd
.push(null);
728 else this.lastMoveEnd
.push(Object
.assign({ p: move.released
}, move.end
));
729 V
.PlayOnBoard(this.board
, move);
730 this.umoves
.push(this.getUmove(move));
734 this.epSquares
.pop();
735 this.disaggregateFlags(JSON
.parse(move.flags
));
736 V
.UndoOnBoard(this.board
, move);
737 this.lastMoveEnd
.pop();
738 if (!move.released
) {
739 this.turn
= V
.GetOppCol(this.turn
);
747 if (this.getPiece(move.start
.x
, move.start
.y
) == V
.KING
)
748 this.kingPos
[this.turn
] = [move.start
.x
, move.start
.y
];
752 // Check kings: if one is dancing, the side lost
753 // But, if both dancing, let's say it's a draw :-)
754 const [kpW
, kpB
] = [this.kingPos
['w'], this.kingPos
['b']];
755 const atKingPlace
= [
756 this.board
[kpW
[0]][kpW
[1]].charAt(1),
757 this.board
[kpB
[0]][kpB
[1]].charAt(1)
759 if (!atKingPlace
.includes('k')) return "1/2";
760 if (atKingPlace
[0] != 'k') return "0-1";
761 if (atKingPlace
[1] != 'k') return "1-0";
766 let initMoves
= this.getAllValidMoves();
767 if (initMoves
.length
== 0) return null;
768 // Loop until valid move is found (no blocked pawn released...)
770 let moves
= JSON
.parse(JSON
.stringify(initMoves
));
773 // Just play random moves (for now at least. TODO?)
774 while (moves
.length
> 0) {
775 mv
= moves
[randInt(moves
.length
)];
779 // A piece was just released from an union
780 moves
= this.getPotentialMovesFrom([mv
.end
.x
, mv
.end
.y
]);
783 for (let i
= mvArray
.length
- 1; i
>= 0; i
--) this.undo(mvArray
[i
]);
784 if (!mv
.released
) return (mvArray
.length
> 1 ? mvArray : mvArray
[0]);
788 // NOTE: evalPosition() is wrong, but unused since bot plays at random
791 if (move.appear
.length
== 2 && move.appear
[0].p
== V
.KING
)
792 return (move.end
.y
< move.start
.y
? "0-0-0" : "0-0");
795 const L
= this.lastMoveEnd
.length
;
796 const lm
= this.lastMoveEnd
[L
-1];
798 if (!lm
&& move.vanish
.length
== 0)
799 // When importing a game, the info move.released is lost
800 piece
= move.appear
[0].p
;
801 else piece
= (!!lm
? lm
.p : move.vanish
[0].p
);
802 if (!(ChessRules
.PIECES
.includes(piece
))) {
803 // Decode (moving) union
804 const up
= this.getUnionPieces(
805 move.vanish
.length
> 0 ? move.vanish
[0].c : move.appear
[0].c
, piece
);
809 // Basic move notation:
810 let notation
= piece
.toUpperCase();
812 this.board
[move.end
.x
][move.end
.y
] != V
.EMPTY
||
813 (piece
== V
.PAWN
&& move.start
.y
!= move.end
.y
)
817 const finalSquare
= V
.CoordsToSquare(move.end
);
818 notation
+= finalSquare
;
820 // Add potential promotion indications:
821 const firstLastRank
= (c
== 'w' ? [7, 0] : [0, 7]);
822 if (move.end
.x
== firstLastRank
[1] && piece
== V
.PAWN
) {
823 const up
= this.getUnionPieces(move.appear
[0].c
, move.appear
[0].p
);
824 notation
+= "=" + up
[c
].toUpperCase();
827 move.end
.x
== firstLastRank
[0] &&
828 move.vanish
.length
> 0 &&
829 ['c', 'd', 'e', 'f', 'g'].includes(move.vanish
[0].p
)
831 // We promoted an opponent's pawn
832 const oppCol
= V
.GetOppCol(c
);
833 const up
= this.getUnionPieces(move.appear
[0].c
, move.appear
[0].p
);
834 notation
+= "=" + up
[oppCol
].toUpperCase();