};
}
+ // Turn a hidden piece or revealed piece into revealed piece:
+ static Decode(p) {
+ if (Object.keys(V.HIDDEN_DECODE).includes(p))
+ return V.HIDDEN_DECODE[p];
+ return p;
+ }
+
static get PIECES() {
return ChessRules.PIECES.concat(Object.values(V.HIDDEN_CODE));
}
}
getBasicMove([sx, sy], [ex, ey], tr) {
+ if (
+ tr &&
+ Object.keys(V.HIDDEN_DECODE).includes(this.board[sx][sy].charAt(1))
+ ) {
+ // The transformed piece is a priori hidden
+ tr.p = V.HIDDEN_CODE[tr.p];
+ }
let mv = new Move({
appear: [
new PiPo({
})
);
// Pieces are revealed when they capture
- if (Object.keys(V.HIDDEN_DECODE).includes(mv.appear[0].p))
- mv.appear[0].p = V.HIDDEN_DECODE[mv.appear[0].p];
+ mv.appear[0].p = V.Decode(mv.appear[0].p);
}
+
return mv;
}
);
}
+ filterValid(moves) {
+ return moves;
+ }
+
static GenRandInitFen() {
let pieces = { w: new Array(8), b: new Array(8) };
// Shuffle pieces + pawns on two first ranks
const queenPos = positions[randIndex];
positions.splice(randIndex, 1);
- // Get random square for queen
+ // Get random square for king
randIndex = randInt(9);
const kingPos = positions[randIndex];
positions.splice(randIndex, 1);
const moves = this.getAllValidMoves();
return moves[randInt(moves.length)];
}
+
+ getNotation(move) {
+ // Translate final square
+ const finalSquare = V.CoordsToSquare(move.end);
+
+ const piece = this.getPiece(move.start.x, move.start.y);
+ if (piece == V.PAWN) {
+ // Pawn move
+ let notation = "";
+ if (move.vanish.length > move.appear.length) {
+ // Capture
+ const startColumn = V.CoordToColumn(move.start.y);
+ notation = startColumn + "x" + finalSquare;
+ }
+ else notation = finalSquare;
+ if (move.appear.length > 0 && !["p","s"].includes(move.appear[0].p)) {
+ // Promotion
+ const appearPiece = V.Decode(move.appear[0].p);
+ notation += "=" + appearPiece.toUpperCase();
+ }
+ return notation;
+ }
+ // Piece movement
+ return (
+ piece.toUpperCase() +
+ (move.vanish.length > move.appear.length ? "x" : "") +
+ finalSquare
+ );
+ }
};