Position
Class to represent a position on the chessboard. It is immutable.
This class provides all the necessary information to perform conventional logical operations based on a position, primarily through bitboard representations. This class cannot be instantiated directly but must be accessed via the factory function positionOf, which ensures the provided FEN string (if any) is well-formed and valid.
This is a facade created to enable exporting the code to JS, though it can also be used directly within the JS modules of any KMP project.
Properties
Array of Bitboards. The index in the array is equal to the ordinal value minus one of the corresponding piece (e.g., Black Knight distribution is at index BN.ordinal - 1).
True if Black can castle kingside (short castling). False otherwise.
True if Black can castle queenside (long castling). False otherwise.
A list of tuples, where each tuple represents a legal move from this position and the resulting new position (Tuple
The square exposed to an en passant capture, if one exists. Returns null if no en passant capture is possible in the current position.
True if the position has reached or exceeded 50 half-moves without a pawn move or capture.
The number of half-moves since the last pawn move or capture. This is used for the 50-move rule.
True if the position is a draw due to insufficient mating material (e.g., King vs. King). False otherwise.
The full move number in the game (starts at 1 and is incremented after Black's move).
The side (WHITE or BLACK) whose turn it is to move.
True if White can castle kingside (short castling). False otherwise.
True if White can castle queenside (long castling). False otherwise.
Functions
Determines if Black has insufficient material to win the game. Returns true if the current pieces for Black cannot potentially lead to a checkmate.
Retrieves the new Position that results from executing the move specified in the given notation. Throws a MoveException if the move is not legal. If no notation is provided, UCI notation is assumed.
Determines if White has insufficient material to win the game. Returns true if the current pieces for White cannot potentially lead to a checkmate.