Position

class 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.

Since

1.0.0-beta.1

Author

lunalobos

Properties

Link copied to clipboard

Array of Long integers used as 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 Piece.BN.ordinal - 1).

Link copied to clipboard

True if Black can castle kingside (short castling). False otherwise.

Link copied to clipboard

True if Black can castle queenside (long castling). False otherwise.

Link copied to clipboard

True if the current side to move is in check. False otherwise.

Link copied to clipboard

True if the position is a checkmate (the current side is in check and has no legal moves). False otherwise.

Link copied to clipboard

A list of tuples, where each tuple represents a legal move from this position and the resulting new position (Tuple). This list effectively defines the legal branches of the game tree from the current position.

Link copied to clipboard

True if the position is a forced draw. This is true if the position results in a stalemate or lackOfMaterial. False otherwise.

Link copied to clipboard

The square index (0-63) where a pawn can be captured en passant. Returns -1 if no en passant capture is possible.

Link copied to clipboard

The square exposed to an en passant capture, if one exists. Returns null if no en passant capture is possible in the current position.

Link copied to clipboard
val fen: String

The FEN (Forsyth-Edwards Notation) string representation of the position.

Link copied to clipboard

True if the position has reached or exceeded 50 half-moves without a pawn move or capture.

Link copied to clipboard

True if the game state is concluded (terminal position), either due to a forced draw or checkmate. False otherwise.

Link copied to clipboard

The number of half-moves since the last pawn move or capture. This is used for the 50-move rule.

Link copied to clipboard

True if the position is a draw due to insufficient mating material (e.g., King vs. King). False otherwise.

Link copied to clipboard

The full move number in the game (starts at 1 and is incremented after Black's move).

Link copied to clipboard

The side (Side.WHITE or Side.BLACK) whose turn it is to move.

Link copied to clipboard

A 64-element array where the index corresponds to the square order defined in Square (A1=0, H8=63). The value of each element is the ordinal of the Piece occupying that square (0 for Piece.EMPTY, 1 for Piece.WP, and so on).

Link copied to clipboard

True if the position is a stalemate (the current side is not in check but has no legal moves). False otherwise.

Link copied to clipboard

True if White can castle kingside (short castling). False otherwise.

Link copied to clipboard

True if White can castle queenside (long castling). False otherwise.

Link copied to clipboard

True if it is White's turn to move. False if it is Black's turn.

Link copied to clipboard

The Zobrist hash key of the position. This is used for efficient position lookup and repetition detection.

Functions

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard

Returns true if the evaluated Move is legal in the current position, and false otherwise.

fun Position.isLegal(move: String, notation: Notation = Notation.UCI): Boolean

Returns true if the move specified in the given notation is legal in the current position. If no notation is specified, Notation.UCI is assumed.

Link copied to clipboard

Retrieves the new Position that results from executing the provided legal Move. Throws a MoveException if the provided move is not legal in the current position.

fun Position.move(move: String, notation: Notation = Notation.UCI): Position

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, Notation.UCI is assumed.

Link copied to clipboard
open override fun toString(): String