libscid 0.1.0
Chess applications made easy.
Loading...
Searching...
No Matches
move_predicates.h File Reference

Move validation predicates. More...

#include "scid/core/board.h"
#include <cassert>
#include <utility>
+ Include dependency graph for move_predicates.h:

Go to the source code of this file.

Functions

bool scid::core::move_predicates::valid_king (squareT sqFrom, squareT sqTo)
 
bool scid::core::move_predicates::valid_knight (squareT sqFrom, squareT sqTo)
 
int scid::core::move_predicates::valid_slider (squareT sqFrom, squareT sqTo, pieceT pieceType)
 
bool scid::core::move_predicates::attack_pawn (squareT sqFrom, squareT sqTo, colorT pieceCol)
 
template<typename TFunc >
bool scid::core::move_predicates::attack_slider (squareT sqFrom, squareT sqTo, pieceT pieceType, TFunc isOccupied)
 
template<typename TFunc >
bool scid::core::move_predicates::attack (squareT sqFrom, squareT sqTo, pieceT pieceCol, pieceT pieceType, TFunc isOccupied)
 Validate an ATTACK move, that is if a piece placed at sqFrom can capture an enemy piece at sqTo.
 
template<typename TFunc >
bool scid::core::move_predicates::pseudo_advance_pawn (squareT sqFrom, squareT sqTo, colorT pieceCol, TFunc isOccupied)
 
template<typename TFunc >
bool scid::core::move_predicates::pseudo (squareT sqFrom, squareT sqTo, colorT pieceCol, pieceT pieceType, TFunc isOccupied)
 
template<typename TFunc >
std::pair< pieceT, squareT > scid::core::move_predicates::opens_ray (squareT sqFrom, squareT sqTo, squareT sqRay, TFunc isOccupied)
 Given a pseudo-legal move, this functions return the type and the location of the piece that can possibly pin the moving piece, making the move not legal.
 
bool scid::core::move_predicates::blocks_ray (squareT sqFrom, squareT sqTo, squareT sqBlock)
 Checks if there is a valid ray from sqFrom to sqTo and if a piece on sqBlock would block that ray.
 

Variables

constexpr int scid::core::move_predicates::NSQUARES = 8
 
constexpr int scid::core::move_predicates::kWPHomeRank = 1
 
constexpr int scid::core::move_predicates::kBPHomeRank = NSQUARES - 2
 

Detailed Description

Move validation predicates.

Function Documentation

◆ attack()

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

Validate an ATTACK move, that is if a piece placed at sqFrom can capture an enemy piece at sqTo.

Parameters
sqFromsquare of the piece.
sqTosquare of the piece to be captured.
pieceColcolor of the moving piece.
pieceTypetype of the moving piece.
isOccupiedcallable object which should returns true if a square is occupied by a piece. Since it is not invoked with sqFrom or sqTo, it's is irrelevant if the position is the one before or after the move was made.
Returns
true if the move is a valid ATTACK move.

◆ blocks_ray()

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

Checks if there is a valid ray from sqFrom to sqTo and if a piece on sqBlock would block that ray.

Parameters
sqFromstart square of the ray.
sqToend square of the ray.
sqBlockthe square that may block the ray.
Returns
true if a piece on sqBlock would block the ray.

◆ opens_ray()

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

Given a pseudo-legal move, this functions return the type and the location of the piece that can possibly pin the moving piece, making the move not legal.

Parameters
sqFromstart square of the pseudo-legal move.
sqTodestination square of the pseudo-legal move.
sqRaythe projected ray starts from sqRay and goes through sqFrom; it is usually the square where the king is.
isOccupiedcallable object which should returns true if a square is occupied by a piece.
Returns
a std::pair with the type (INVALID_PIECE, BISHOP, ROOK) and the square of the candidate pinning piece. If the type is INVALID_PIECE there is no pin and the move is legal, otherwise it's necessary to test the board position and if the returned square is occupied by an enemy QUEEN, or an enemy piece matching the returned type, the move is not legal.