const move = moveOrSquare;
const s = move.start,
e = move.end;
- // NOTE: next conditions are first for Atomic, and last for Checkered
if (
- move.appear.length > 0 &&
Math.abs(s.x - e.x) == 2 &&
s.y == e.y &&
- move.appear[0].p == V.PAWN &&
- ["w", "b"].includes(move.appear[0].c)
+ move.appear[0].p == V.PAWN
) {
return {
x: (s.x + e.x) / 2,
// Return current fen (game state)
getFen() {
return (
- this.getBaseFen() +
- " " +
- this.getTurnFen() +
- " " +
+ this.getBaseFen() + " " +
+ this.getTurnFen() + " " +
this.movesCount +
(V.HasFlags ? " " + this.getFlagsFen() : "") +
(V.HasEnpassant ? " " + this.getEnpassantFen() : "")
);
}
+ getFenForRepeat() {
+ // Omit movesCount, only variable allowed to differ
+ return (
+ this.getBaseFen() + "_" +
+ this.getTurnFen() +
+ (V.HasFlags ? "_" + this.getFlagsFen() : "") +
+ (V.HasEnpassant ? "_" + this.getEnpassantFen() : "")
+ );
+ }
+
// Position part of the FEN string
getBaseFen() {
let position = "";
const firstRank = color == "w" ? sizeX - 1 : 0;
const startRank = color == "w" ? sizeX - 2 : 1;
const lastRank = color == "w" ? 0 : sizeX - 1;
- const pawnColor = this.getColor(x, y); //can be different for checkered
// NOTE: next condition is generally true (no pawn on last rank)
if (x + shiftX >= 0 && x + shiftX < sizeX) {
for (let piece of finalPieces) {
moves.push(
this.getBasicMove([x, y], [x + shiftX, y], {
- c: pawnColor,
+ c: color,
p: piece
})
);
for (let piece of finalPieces) {
moves.push(
this.getBasicMove([x, y], [x + shiftX, y + shiftY], {
- c: pawnColor,
+ c: color,
p: piece
})
);
// After move is played, update variables + flags
updateVariables(move) {
let piece = undefined;
- // TODO: update variables before move is played, and just use this.turn ?
+ // TODO: update variables before move is played, and just use this.turn?
// (doesn't work in general, think MarseilleChess)
let c = undefined;
if (move.vanish.length >= 1) {