libscid snapshot+e944e108ed8b
Chess applications made easy.
Source on GitHub License GPL v2
Loading...
Searching...
No Matches
scid::core::move_predicates Namespace Reference

Stateless helpers used by Position move validation. More...

Functions

bool valid_king (squareT sqFrom, squareT sqTo)
 Returns true when the two squares are a king move apart.
 
bool valid_knight (squareT sqFrom, squareT sqTo)
 Returns true when the two squares form a knight move.
 
int valid_slider (squareT sqFrom, squareT sqTo, pieceT pieceType)
 Returns the slider step from sqFrom to sqTo.
 
bool attack_pawn (squareT sqFrom, squareT sqTo, colorT pieceCol)
 Returns true when a pawn of pieceCol attacks sqTo from sqFrom.
 
template<typename TFunc >
bool attack_slider (squareT sqFrom, squareT sqTo, pieceT pieceType, TFunc isOccupied)
 Returns true when a slider attacks along an unobstructed ray.
 
template<typename TFunc >
bool attack (squareT sqFrom, squareT sqTo, pieceT pieceCol, pieceT pieceType, TFunc isOccupied)
 Validates an attack move.
 
template<typename TFunc >
bool pseudo_advance_pawn (squareT sqFrom, squareT sqTo, colorT pieceCol, TFunc isOccupied)
 Validates a non-capturing pawn advance.
 
template<typename TFunc >
bool pseudo (squareT sqFrom, squareT sqTo, colorT pieceCol, pieceT pieceType, TFunc isOccupied)
 Validates pseudo-legal movement using piece geometry and occupancy.
 
template<typename TFunc >
std::pair< pieceT, squareTopens_ray (squareT sqFrom, squareT sqTo, squareT sqRay, TFunc isOccupied)
 Finds a possible discovered pin caused by moving from a ray.
 
bool blocks_ray (squareT sqFrom, squareT sqTo, squareT sqBlock)
 Tests whether sqBlock lies between two ray-aligned squares.
 

Variables

constexpr int NSQUARES = 8
 
constexpr int kWPHomeRank = 1
 
constexpr int kBPHomeRank = NSQUARES - 2
 

Detailed Description

Stateless helpers used by Position move validation.

These helpers separate chess movement into four levels:

  • A valid move follows piece geometry alone, such as a bishop moving diagonally. Validity does not require a position.
  • An attack move is valid capture geometry plus blocker checks for sliders and pawn capture direction. It needs only an occupancy predicate.
  • A pseudo-legal move is an attack move, a non-capture pawn advance, or a castle candidate.
  • A legal move is pseudo-legal, does not land on a friendly piece, and does not leave the mover's king in check. Legal move validation belongs to Position because it needs full board state.

Function Documentation

◆ attack()

template<typename TFunc >
bool scid::core::move_predicates::attack ( squareT  sqFrom,
squareT  sqTo,
pieceT  pieceCol,
pieceT  pieceType,
TFunc  isOccupied 
)

Validates an attack move.

Parameters
sqFromsquare of the attacking piece.
sqTosquare being attacked.
pieceColcolour of the attacking piece.
pieceTypetype of the attacking piece.
isOccupiedcallable returning true when an intermediate square is occupied. It is not called for sqFrom or sqTo, so it can describe either the pre-move or post-move occupancy of those endpoint squares.
Returns
true when the piece attacks sqTo from sqFrom.

◆ attack_slider()

template<typename TFunc >
bool scid::core::move_predicates::attack_slider ( squareT  sqFrom,
squareT  sqTo,
pieceT  pieceType,
TFunc  isOccupied 
)

Returns true when a slider attacks along an unobstructed ray.

isOccupied is called only for squares strictly between sqFrom and sqTo.

◆ blocks_ray()

bool scid::core::move_predicates::blocks_ray ( squareT  sqFrom,
squareT  sqTo,
squareT  sqBlock 
)
inline

Tests whether sqBlock lies between two ray-aligned squares.

Returns
true when a piece on sqBlock would block a queen ray from sqFrom to sqTo.

◆ opens_ray()

template<typename TFunc >
std::pair< pieceT, squareT > scid::core::move_predicates::opens_ray ( squareT  sqFrom,
squareT  sqTo,
squareT  sqRay,
TFunc  isOccupied 
)
inline

Finds a possible discovered pin caused by moving from a ray.

Given a pseudo-legal move, this returns the kind and square of the first piece that may pin the mover to sqRay, usually the mover's king square.

Parameters
sqFromorigin square of the pseudo-legal move.
sqTodestination square of the pseudo-legal move.
sqRaysquare through which the projected ray passes.
isOccupiedcallable returning true when a square is occupied.
Returns
a pair of candidate attacker type and square. INVALID_PIECE means no ray was opened. Otherwise, the caller must inspect the returned square: an enemy queen or an enemy piece matching the returned type makes the move illegal.

◆ pseudo()

template<typename TFunc >
bool scid::core::move_predicates::pseudo ( squareT  sqFrom,
squareT  sqTo,
colorT  pieceCol,
pieceT  pieceType,
TFunc  isOccupied 
)

Validates pseudo-legal movement using piece geometry and occupancy.

This covers attacks and non-capturing pawn advances. Castling is handled by Position because castling rights, rook identity, and attacked transit squares require full position state.

◆ pseudo_advance_pawn()

template<typename TFunc >
bool scid::core::move_predicates::pseudo_advance_pawn ( squareT  sqFrom,
squareT  sqTo,
colorT  pieceCol,
TFunc  isOccupied 
)
inline

Validates a non-capturing pawn advance.

Single and home-rank double advances are accepted when every traversed square is empty according to isOccupied.

◆ valid_slider()

int scid::core::move_predicates::valid_slider ( squareT  sqFrom,
squareT  sqTo,
pieceT  pieceType 
)
inline

Returns the slider step from sqFrom to sqTo.

Returns
the signed-independent board step for a queen, rook, or bishop ray, or 0 when pieceType cannot move along that ray.