47 unsigned distRank = 1 + (sqTo /
NSQUARES) - (sqFrom / NSQUARES);
48 unsigned distFyle = 1 + (sqTo %
NSQUARES) - (sqFrom % NSQUARES);
49 return distRank <= 2 && distFyle <= 2;
53 int distRank = (sqTo /
NSQUARES) - (sqFrom / NSQUARES);
54 int distFyle = (sqTo %
NSQUARES) - (sqFrom % NSQUARES);
55 int distProduct = distRank * distFyle;
56 return (distProduct == 2 || distProduct == -2);
62 int distRank = (sqTo /
NSQUARES) - (sqFrom / NSQUARES);
63 int distFyle = (sqTo %
NSQUARES) - (sqFrom % NSQUARES);
67 bool isDiagonal =
false;
70 }
else if (distFyle == 0) {
72 }
else if (distFyle == distRank) {
73 sqStep = NSQUARES + 1;
75 }
else if (distFyle == -distRank) {
76 sqStep = NSQUARES - 1;
81 if (pieceType ==
ROOK && isDiagonal)
83 if (pieceType ==
BISHOP && !isDiagonal)
90 int distRank = (sqTo /
NSQUARES) - (sqFrom / NSQUARES);
91 int distFyle = (sqTo %
NSQUARES) - (sqFrom % NSQUARES);
92 if (pieceCol ==
WHITE && distRank != 1)
94 if (pieceCol ==
BLACK && distRank != -1)
97 return (distFyle == 1 || distFyle == -1);
100 template <
typename TBoard>
102 const TBoard*
board,
const TBoard EMPTY_SQUARE) {
111 for (
int sq = sqFrom + sqStep;
sq != sqTo;
sq += sqStep) {
112 if (board[
sq] != EMPTY_SQUARE)
131 template <
typename TBoard>
133 const TBoard*
board,
const TBoard EMPTY_SQUARE) {
144 return attack_slider(sqFrom, sqTo, pieceType, board, EMPTY_SQUARE);
147 template <
typename TBoard>
149 const TBoard*
board,
const TBoard EMPTY_SQUARE) {
159 return attack_slider(sqFrom, sqTo, pieceType, board, EMPTY_SQUARE);
178 template <
typename TBoard>
181 const TBoard EMPTY_SQUARE) {
185 int distFyle = (sqRay %
NSQUARES) - fyleFrom;
186 int distRank = (sqRay /
NSQUARES) - (sqFrom / NSQUARES);
197 if (fyleFrom == 0 || fyleFrom == (NSQUARES - 1))
204 }
else if (distFyle == distRank) {
205 sqStep = NSQUARES + 1;
208 }
else if (distFyle == -distRank) {
209 sqStep = NSQUARES - 1;
210 fyleEdge = NSQUARES - 1;
216 if (sqFrom > sqRay) {
218 fyleEdge = NSQUARES - 1 - fyleEdge;
221 for (
int sq = sqFrom + sqStep;
sq != sqRay;
sq += sqStep) {
222 if (
sq == sqTo || board[
sq] != EMPTY_SQUARE)
226 for (
int sq = sqFrom - sqStep;
sq < NSQUARES *
NSQUARES;
sq -= sqStep) {
227 if (
sq < 0 ||
sq == sqTo)
230 if (board[
sq] != EMPTY_SQUARE)
231 return std::make_pair(pt, static_cast<squareT>(
sq));
233 if ((
sq % NSQUARES) == fyleEdge)
bool attack(squareT sqFrom, squareT sqTo, pieceT pieceCol, pieceT pieceType, const TBoard *board, const TBoard EMPTY_SQUARE)
Validate an ATTACK move, that is if a piece placed at sqFrom can capture an enemy piece at sqTo...
bool pseudo(squareT sqFrom, squareT sqTo, colorT, pieceT pieceType, const TBoard *board, const TBoard EMPTY_SQUARE)
std::pair< pieceT, squareT > opens_ray(squareT sqFrom, squareT sqTo, squareT sqRay, const TBoard *board, const TBoard EMPTY_SQUARE)
Given a pseudo-legal move, this functions return the type and the location of the piece that can poss...
bool valid_king(squareT sqFrom, squareT sqTo)
bool attack_pawn(squareT sqFrom, squareT sqTo, colorT pieceCol)
bool valid_knight(squareT sqFrom, squareT sqTo)
const pieceT INVALID_PIECE
bool attack_slider(squareT sqFrom, squareT sqTo, pieceT pieceType, const TBoard *board, const TBoard EMPTY_SQUARE)
int valid_slider(squareT sqFrom, squareT sqTo, pieceT pieceType)