78 for (
case_t iCase = 0; iCase < 64; ++iCase) {
114 if (newcol < 0 || newcol > 7)
return 0;
115 if (newrank < 0 || newrank > 7)
return 0;
192 if (!p)
return false;
200 if (!p)
return false;
208 if (!p)
return false;
215 if (!p)
return false;
261 for (
unsigned int i=0; i < b.m_blackPieces[
STAT_KNIGHT].size(); i++) {
308 for (
unsigned int i=0; i < b.m_whitePieces[
STAT_KNIGHT].size(); i++) {
361 piece_t const cPiece, int8_t
const ri, int8_t
const ci)
const
363 return (b.
getPieceCtl(fromcol + ci, fromrank + ri) == cPiece);
380 int8_t
const ri, int8_t
const ci)
const
382 rank_t newrank = fromrank + ri;
386 for (int8_t i = 0; i < 7; i++) {
388 if (newrank < 0 || newrank > 7)
return false;
389 if (newcol < 0 || newcol > 7)
return false;
393 if (piece == cPiece)
return true;
394 if (piece == cPiece2)
return true;
398 newrank += ri; newcol += ci;
409 int8_t
const ri, int8_t
const ci)
const
414 if (newcol < 0 || newcol > 7)
return false;
418 rank_t newrank = oldrank + ri;
419 if (newrank < 0 || newrank > 7)
return false;
441 int8_t
const ri, int8_t
const ci,
442 piece_t const cPromotion)
const
447 if (newcol < 0 || newcol > 7)
return false;
451 rank_t newrank = oldrank + ri;
452 if (newrank < 0 || newrank > 7)
return false;
474 int8_t
const ri, int8_t
const ci)
const
479 if (newcol < 0 || newcol > 7)
return false;
483 rank_t newrank = oldrank + ri;
484 if (newrank < 0 || newrank > 7)
return false;
506 int8_t
const ri, int8_t
const ci,
507 piece_t const cPromotion)
const
512 if (newcol < 0 || newcol > 7)
return false;
516 rank_t newrank = oldrank + ri;
517 if (newrank < 0 || newrank > 7)
return false;
537 int8_t
const ri, int8_t
const ci,
bMoveList& ml)
const
540 if (newcol < 0 || newcol > 7)
return 0;
543 if (newrank < 0 || newrank > 7)
return 0;
555 int8_t
const ri, int8_t
const ci,
bMoveList& ml)
const
558 if (newcol < 0 || newcol > 7)
return 0;
561 if (newrank < 0 || newrank > 7)
return 0;
577 int8_t
const ri, int8_t
const ci,
bMoveList& ml)
const
579 int_fast8_t nMax = 7;
584 while (--nMax >= 0) {
585 if (newcol < 0 || newcol > 7)
return nMoves;
586 if (newrank < 0 || newrank > 7)
return nMoves;
605 int8_t
const ri, int8_t
const ci,
bMoveList& ml)
const
607 int_fast8_t nMax = 7;
612 while (--nMax >= 0) {
613 if (newcol < 0 || newcol > 7)
return nMoves;
614 if (newrank < 0 || newrank > 7)
return nMoves;
635bool bWhitePawn::canPawnMove(
bBoard& b,
case_t const& cf)
const
649bool bWhitePawn::canPawnCapture(
bBoard& b,
case_t const& cf,
650 int8_t
const ci)
const
653 if (newcol < 0 || newcol > 7)
return false;
665bool bWhitePawn::canPawnEPMove(
bBoard& b,
666 case_t const& cf, int8_t
const ci)
const
669 if (newcol < 0 || newcol > 7)
return false;
696bool bBlackPawn::canPawnMove(
bBoard& b,
case_t const& cf)
const
710bool bBlackPawn::canPawnCapture(
bBoard& b,
case_t const& cf,
711 int8_t
const ci)
const
714 if (newcol < 0 || newcol > 7)
return false;
726bool bBlackPawn::canPawnEPMove(
bBoard& b,
727 case_t const& cf, int8_t
const ci)
const
730 if (newcol < 0 || newcol > 7)
return false;
784 if (newcol < 0 || newcol > 7)
return 0;
799 if (newcol < 0 || newcol > 7)
return 0;
843 if (newcol < 0 || newcol > 7)
return 0;
861 if (newcol < 0 || newcol > 7)
return 0;
912 if (canPawnMove(b, cf))
return true;
913 if (canPawnCapture(b, cf, -1))
return true;
914 if (canPawnCapture(b, cf, 1))
return true;
916 if (canPawnEPMove(b, cf, -1))
return true;
917 if (canPawnEPMove(b, cf, 1))
return true;
952 if (canPawnMove(b, cf))
return true;
953 if (canPawnCapture(b, cf, -1))
return true;
954 if (canPawnCapture(b, cf, 1))
return true;
956 if (canPawnEPMove(b, cf, -1))
return true;
957 if (canPawnEPMove(b, cf, 1))
return true;
1009 nMoves +=
addMoves(b, cf, -1, 0, ml);
1010 nMoves +=
addMoves(b, cf, 1, 0, ml);
1011 nMoves +=
addMoves(b, cf, 0, -1, ml);
1012 nMoves +=
addMoves(b, cf, 0, 1, ml);
1021 nMoves +=
addMoves(b, cf, -1, 0, ml);
1022 nMoves +=
addMoves(b, cf, 1, 0, ml);
1023 nMoves +=
addMoves(b, cf, 0, -1, ml);
1024 nMoves +=
addMoves(b, cf, 0, 1, ml);
1059 nMoves +=
addMove(b, cf, 1, 2, ml);
1060 nMoves +=
addMove(b, cf, 1, -2, ml);
1061 nMoves +=
addMove(b, cf, 2, 1, ml);
1062 nMoves +=
addMove(b, cf, -2, 1, ml);
1063 nMoves +=
addMove(b, cf, -1, 2, ml);
1064 nMoves +=
addMove(b, cf, -1, -2, ml);
1065 nMoves +=
addMove(b, cf, 2, -1, ml);
1066 nMoves +=
addMove(b, cf, -2, -1, ml);
1075 nMoves +=
addMove(b, cf, 1, 2, ml);
1076 nMoves +=
addMove(b, cf, 1, -2, ml);
1077 nMoves +=
addMove(b, cf, 2, 1, ml);
1078 nMoves +=
addMove(b, cf, -2, 1, ml);
1079 nMoves +=
addMove(b, cf, -1, 2, ml);
1080 nMoves +=
addMove(b, cf, -1, -2, ml);
1081 nMoves +=
addMove(b, cf, 2, -1, ml);
1082 nMoves +=
addMove(b, cf, -2, -1, ml);
1109 nMoves +=
addMoves(b, cf, -1, -1, ml);
1110 nMoves +=
addMoves(b, cf, 1, -1, ml);
1111 nMoves +=
addMoves(b, cf, -1, 1, ml);
1112 nMoves +=
addMoves(b, cf, 1, 1, ml);
1121 nMoves +=
addMoves(b, cf, -1, -1, ml);
1122 nMoves +=
addMoves(b, cf, 1, -1, ml);
1123 nMoves +=
addMoves(b, cf, -1, 1, ml);
1124 nMoves +=
addMoves(b, cf, 1, 1, ml);
1159 nMoves +=
addMoves(b, cf, 0, -1, ml);
1160 nMoves +=
addMoves(b, cf, 0, 1, ml);
1161 nMoves +=
addMoves(b, cf, 1, -1, ml);
1162 nMoves +=
addMoves(b, cf, 1, 0, ml);
1163 nMoves +=
addMoves(b, cf, 1, 1, ml);
1164 nMoves +=
addMoves(b, cf, -1, -1, ml);
1165 nMoves +=
addMoves(b, cf, -1, 0, ml);
1166 nMoves +=
addMoves(b, cf, -1, 1, ml);
1175 nMoves +=
addMoves(b, cf, 0, -1, ml);
1176 nMoves +=
addMoves(b, cf, 0, 1, ml);
1177 nMoves +=
addMoves(b, cf, 1, -1, ml);
1178 nMoves +=
addMoves(b, cf, 1, 0, ml);
1179 nMoves +=
addMoves(b, cf, 1, 1, ml);
1180 nMoves +=
addMoves(b, cf, -1, -1, ml);
1181 nMoves +=
addMoves(b, cf, -1, 0, ml);
1182 nMoves +=
addMoves(b, cf, -1, 1, ml);
1217 nMoves +=
addMove(b, cf, 0, -1, ml);
1218 nMoves +=
addMove(b, cf, 0, 1, ml);
1219 nMoves +=
addMove(b, cf, 1, -1, ml);
1220 nMoves +=
addMove(b, cf, 1, 0, ml);
1221 nMoves +=
addMove(b, cf, 1, 1, ml);
1222 nMoves +=
addMove(b, cf, -1, -1, ml);
1223 nMoves +=
addMove(b, cf, -1, 0, ml);
1224 nMoves +=
addMove(b, cf, -1, 1, ml);
1265 nMoves +=
addMove(b, cf, 0, -1, ml);
1266 nMoves +=
addMove(b, cf, 0, 1, ml);
1267 nMoves +=
addMove(b, cf, 1, -1, ml);
1268 nMoves +=
addMove(b, cf, 1, 0, ml);
1269 nMoves +=
addMove(b, cf, 1, 1, ml);
1270 nMoves +=
addMove(b, cf, -1, -1, ml);
1271 nMoves +=
addMove(b, cf, -1, 0, ml);
1272 nMoves +=
addMove(b, cf, -1, 1, ml);
This is the main include file, needs to be included before any other include.
piece_t getPiece(case_t const bc) const
1 for white, 2 for black
u_positionFlags_t makeBoardMove(column_t const oldcol, rank_t const oldrank, column_t const newcol, rank_t const newrank, piece_t const promotion)
apply move to check if in check only, board to be discarded as it will be in incomplete state,...
case_t getBlackKingPos() const
void unMakeBoardMove(case_t const &cf, column_t const newcol, rank_t const newrank, u_positionFlags_t const oldFlags, piece_t const promotion)
undo makeBoardMove, restoring previous situation
case_t getWhiteKingPos() const
piece_t getPieceCtl(column_t const iColumn, rank_t const iRank) const
retrieve piece with bounds checking, return field empty in case of out of bounds
bool isFieldEmpty(case_t const bc) const
bool hasValidMovePreflightCheck(bBoard &b, case_t const &cf) final
movenum_t GenerateMoves(bBoard const &b, case_t const &cf, bMoveList &ml) final
bool hasValidMovePreflightCheck(bBoard &b, case_t const &cf) final
movenum_t GenerateMoves(bBoard const &b, case_t const &cf, bMoveList &ml) final
movenum_t GenerateMoves(bBoard const &b, case_t const &cf, bMoveList &ml) final
bool hasValidMovePreflightCheck(bBoard &b, case_t const &cf) final
movenum_t addEPMove(bBoard const &b, case_t const &cf, int8_t const ci, bMoveList &ml) const
Test move is possible, e.p.
bool hasValidMovePreflightCheck(bBoard &b, case_t const &cf) final
check if there is at least one move possible currently, relies on full move generation for pawn
movenum_t addNonCapturePawnMove(bBoard const &b, case_t const &cf, bMoveList &ml) const
Test move is possible, single step move non capture move.
movenum_t addCapturePromotionMove(bBoard const &b, case_t const &cf, int8_t const ci, bMoveList &ml) const
movenum_t addCapturePawnMove(bBoard const &b, case_t const &cf, int8_t const ci, bMoveList &ml) const
movenum_t GenerateMoves(bBoard const &b, case_t const &cf, bMoveList &ml) final
movenum_t addNonCaptureDoublePawnMove(bBoard const &b, case_t const &cf, bMoveList &ml) const
movenum_t addNonCapturePromotionMove(bBoard const &b, case_t const &cf, bMoveList &ml) const
movenum_t addMove(bBoard const &b, case_t const &cf, int8_t const ri, int8_t const ci, bMoveList &ml) const final
movenum_t addMoves(bBoard const &b, case_t const &cf, int8_t const ri, int8_t const ci, bMoveList &ml) const final
bool canMovePreflightCheck(bBoard &b, case_t const &cf, int8_t const ri, int8_t const ci) const override
Check if move could be added by just checking there is not check.
bool isAttacked(bBoard const &b, case_t const &cf) const override
bool hasValidMovePreflightCheck(bBoard &b, case_t const &cf) final
movenum_t GenerateMoves(bBoard const &b, case_t const &cf, bMoveList &ml) final
bool hasValidMovePreflightCheck(bBoard &b, case_t const &cf) final
movenum_t GenerateMoves(bBoard const &b, case_t const &cf, bMoveList &ml) final
static constexpr case_t coordToCase(column_t const c, rank_t const r)
static constexpr boardbitmap_t caseToBit(case_t const c)
void setShortCastleMove()
movenum_t addWhiteCaptureIfValid(bBoard const &b, case_t const &cf, case_t const &to)
movenum_t addBlackPromotionIfValid(bBoard const &b, bMove const &m)
Only add move to movelist if valid.
movenum_t addWhitePromotionIfValid(bBoard const &b, bMove const &m)
Only add move to movelist if valid.
movenum_t addBlackCaptureIfValid(bBoard const &b, case_t const &cf, case_t const &to)
movenum_t addBlackMoveIfValid(bBoard const &b, bMove const &m)
Only add move to movelist if valid.
movenum_t addWhiteMoveIfValid(bBoard const &b, bMove const &m)
Only add move to movelist if valid.
bool isAttackedByPiece(bBoard const &b, column_t const fromcol, rank_t const fromrank, piece_t const cPiece, int8_t const ri, int8_t const ci) const
Return true if position is attacked by opponent respecting move offsets.
bool isAttackedBySlider(bBoard const &b, column_t const fromcol, rank_t const fromrank, piece_t const cPiece, piece_t const cPiece2, int8_t const ri, int8_t const ci) const
Return true if position is attacked by opponent respecting move offsets.
static bool isOwnColour(side_t const s, piece_t const p)
static class member function
static bPiece * getPieceClass(piece_t const piece)
static class member function
static cpiece_t getPieceChar(piece_t const p)
static class member function
static bool isBlackPiece(piece_t const p)
static class member function
static bool isWhitePiece(piece_t const p)
static class member function
static bool isOpponent(side_t const s, piece_t const p)
static class member function
static const std::string getPieceStrUpper(piece_t const piece)
static class member function
bool hasValidMovePreflightCheck(bBoard &b, case_t const &cf) final
movenum_t GenerateMoves(bBoard const &b, case_t const &cf, bMoveList &ml) final
bool hasValidMovePreflightCheck(bBoard &b, case_t const &cf) final
movenum_t GenerateMoves(bBoard const &b, case_t const &cf, bMoveList &ml) final
bool hasValidMovePreflightCheck(bBoard &b, case_t const &cf) final
movenum_t GenerateMoves(bBoard const &b, case_t const &cf, bMoveList &ml) final
movenum_t addCapturePromotionMove(bBoard const &b, case_t const &cf, int8_t const ci, bMoveList &ml) const
Test move is possible, single step move capture only move.
movenum_t GenerateMoves(bBoard const &b, case_t const &cf, bMoveList &ml) final
bool hasValidMovePreflightCheck(bBoard &b, case_t const &cf) final
check if there is at least one move possible currently, relies on full move generation for pawn
movenum_t addNonCapturePromotionMove(bBoard const &b, case_t const &cf, bMoveList &ml) const
Test move is possible, single step move non capture move.
movenum_t addEPMove(bBoard const &b, case_t const &cf, int8_t const ci, bMoveList &ml) const
Test move is possible, e.p.
movenum_t addCapturePawnMove(bBoard const &b, case_t const &cf, int8_t const ci, bMoveList &ml) const
movenum_t addNonCapturePawnMove(bBoard const &b, case_t const &cf, bMoveList &ml) const
Test move is possible, single step move non capture move.
movenum_t addNonCaptureDoublePawnMove(bBoard const &b, case_t const &cf, bMoveList &ml) const
movenum_t addMoves(bBoard const &b, case_t const &cf, int8_t const ri, int8_t const ci, bMoveList &ml) const final
Add moves for Queen, Rook and Bishop.
bool isAttacked(bBoard const &b, case_t const &cf) const override
Check if piece on position is attacked, start with piece always on board and then with pieces with gr...
movenum_t addMove(bBoard const &b, case_t const &cf, int8_t const ri, int8_t const ci, bMoveList &ml) const final
Check for in-check position, single step move used for King and Knight.
bool canMovePreflightCheck(bBoard &b, case_t const &cf, int8_t const ri, int8_t const ci) const override
Check if move could be added by just checking there is not check.
bool hasValidMovePreflightCheck(bBoard &b, case_t const &cf) final
movenum_t GenerateMoves(bBoard const &b, case_t const &cf, bMoveList &ml) final
movenum_t GenerateMoves(bBoard const &b, case_t const &cf, bMoveList &ml) final
bool hasValidMovePreflightCheck(bBoard &b, case_t const &cf) final
Allow index mapper for char values of piece into int in 1-12 range to reduce space and easy initialis...
static boardbitmap_t kingmoves[64]
static bPiece * pieceinstances[tPiece::P_SIZE]
static boardbitmap_t knightmoves[64]
static piece_t bPieceIndex[128]
static cpiece_t bPieceMapper[tPiece::P_SIZE]
boardbitmap_t destinationbits_knight(case_t const iCase)
boardbitmap_t destinationbits_king(case_t const iCase)
boardbitmap_t destinationbits(case_t const iCase, int8_t const ri, int8_t const ci)