13 : u_positionFlags{bb.u_positionFlags}
15 , m_fields{bb.m_fields}
20 : u_positionFlags{std::move(bb.u_positionFlags)}
21 , m_hash{std::move(bb.m_hash)}
22 , m_fields{std::move(bb.m_fields)}
31#pragma GCC diagnostic push
32#pragma GCC diagnostic ignored "-Weffc++"
41 std::string sFen = belofte::alltrim(fen);
42 belofte::stringList
const fenParts = belofte::stringSplit(sFen,
" ");
43 belofte::stringList
const rowParts = belofte::stringSplit(fenParts[0],
"/");
46 for (
rank_t iRank = 0; iRank < 8; iRank++) {
47 auto initRank = [
this](
rank_t iR, std::string
const& rankdata) ->
void {
51 unsigned char c =
static_cast<unsigned char>(rankdata[i++]);
54 }
else if ((c >=
'1') && (c <=
'8')) {
62 initRank(7 - iRank, rowParts[
static_cast<unsigned long>(iRank)]);
65 if (fenParts.size() > 2) {
73 if (fenParts.size() > 3) {
75 if (fenParts[3] ==
"-") {
82 if (fenParts.size() > 4) {
87 if (fenParts.size() > 5) {
89 setPly(
static_cast<plynum_t>((atoi(fenParts[5].c_str()) - 1) * 2));
92 if (fenParts.size() > 1) {
94 if (fenParts[1] ==
"b")
incPly();
109#pragma GCC diagnostic pop
121 for (
rank_t iRank = 0; iRank < 8; iRank++) {
123 for (
column_t iCol = 0; iCol < 8; iCol++) {
126 if (iBlanks) strfen +=
static_cast<char>(iBlanks +
'0');
133 if (iBlanks) strfen +=
static_cast<char>(iBlanks +
'0');
134 if (iRank < 7) strfen +=
"/";
143 strfen += castl.size() ? castl :
"-";
146 strfen +=
" " + std::string(
bCase(
getEp())) +
" ";
180 return !m_fields[bc];
192 m_fields[bc] = piece;
198 m_fields[bc] =
static_cast<piece_t>(piece);
206 piece_t oldPiece = m_fields[bc];
207 m_fields[bc] = piece;
215 piece_t oldPiece = m_fields[bc];
223 m_fields[bc] = piece;
358 uint8_t piecesonboard = 0;
359 for (
case_t iCase = 0; iCase < 64; iCase++) {
414 if (newcol != oldcol) {
430 if ((newcol - oldcol) == 2) {
434 }
else if ((newcol - oldcol) == -2) {
443 if (newcol != oldcol) {
459 if ((newcol - oldcol) == 2) {
463 }
else if ((newcol - oldcol) == -2) {
506 if ((newcol - oldcol) == 2) {
510 }
else if ((newcol - oldcol) == -2) {
523 if ((newcol - oldcol) == 2) {
527 }
else if ((newcol - oldcol) == -2) {
544 std::stringstream ss;
545 ss << std::uppercase << std::setfill(
'0')
546 << std::setw(16) << std::hex <<
m_hash;
553#pragma GCC diagnostic push
554#pragma GCC diagnostic ignored "-Weffc++"
564 , u_boardFlags1{std::move(b.u_boardFlags1)}
573 , u_boardFlags1{std::move(b.u_boardFlags1)}
574 , m_castledoneWhite{std::move(b.m_castledoneWhite)}
575 , m_castledoneBlack{std::move(b.m_castledoneBlack)}
576 , m_boardeval{std::move(b.m_boardeval)}
578#if !defined(INCOMPLETE_C11)
579 , m_whitePieces{std::move(b.m_whitePieces)}
580 , m_blackPieces{std::move(b.m_blackPieces)}
582 , m_previousmoves{std::move(b.m_previousmoves)}
584#if defined(INCOMPLETE_C11)
586 m_whitePieces[i] = std::move(b.m_whitePieces[i]);
587 m_blackPieces[i] = std::move(b.m_blackPieces[i]);
606 m_previousmoves.emplace_back(m);
623 , m_previousmoves{b.getPreviousMoves()}
625 m_previousmoves.emplace_back(std::move(m));
647 , u_boardFlags1{0ULL}
648 , m_castledoneWhite{false}
649 , m_castledoneBlack{false}
659#pragma GCC diagnostic pop
664 for (
auto& v : m_whitePieces) v.clear();
665 for (
auto& v : m_blackPieces) v.clear();
667 m_previousmoves.clear();
677 for (
auto& v : m_whitePieces) v.clear();
678 for (
auto& v : m_blackPieces) v.clear();
680 for (
case_t iCase = 0; iCase < 64; iCase++) {
767 for (
column_t iCol = 0; iCol < 8; iCol++) {
768 for (
rank_t iRank = 0; iRank < 4; iRank++) {
813void bBoard::applyMove(
bMove const& m)
817 m_hash &= ~HASH_BLACKTOMOVE;
831void bBoard::applyWhiteMove(
bMove const& m)
890void bBoard::applyBlackMove(
bMove const& m)
969 return m_moves[moveid];
988bBoard::operator std::string()
const
990 std::stringstream ss;
992 for (
rank_t iRank = 0; iRank < 8; iRank++) {
993 ss <<
"+---+---+---+---+---+---+---+---+\n";
994 for (
column_t iCol = 0; iCol < 8; iCol++) {
1001 ss <<
"+---+---+---+---+---+---+---+---+\n";
1003 ss <<
"Move " << getMoveNumber() <<
" - "
1004 << (whiteToMove() ?
"White" :
"Black") <<
" to move"
1007 ss <<
"Castling : ";
1008 for (uint8_t i = 0; i < 4; i++) ss << canCastle(static_cast<uint8_t>(1 << i));
1009 if (getEp()) ss <<
" E.p. " <<
bCase(getEp());
1010 if (isNonSilent() || isInCheck())
1011 ss <<
" QS:" << (isInCheck() ?
" Check" :
"")
1012 << (isCapture() ?
" Capture" :
"");
1024 os << bd.operator std::string();
hashkey_t hashmultiplexer[tPiece::P_SIZE][64]
unsigned long long hashkey_t
constexpr hashkey_t HASH_INIT
constexpr hashkey_t HASH_ODDMATERIAL
constexpr hashkey_t HASH_BLACKTOMOVE
This is the main include file, needs to be included before any other include.
std::ostream & operator<<(std::ostream &os, bBoard const &bd)
print board
void setPiece(case_t const bc, piece_t const piece)
used for promotion move generation
piece_t getPiece(case_t const bc) const
1 for white, 2 for black
void setCastle(uint8_t const f)
int16_t getMoveNumber() const
void setPly50Moves(movenum50_t const p)
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,...
void setEp(case_t const e)
void movePiece(case_t const f, case_t const t, piece_t const p)
void moveBlackKing(case_t const f, case_t const t)
side_t getColourToMove() const
std::string getHashStr() const
void setPieceKU(case_t const bc, piece_t const piece)
calculate and set hash
void clearPiece(case_t const bc)
virtual void setInCheck()
void moveWhiteKing(case_t const f, case_t const t)
virtual void setCapture(piece_t const p, case_t const c)
Clear castle flag if rook captured update piece counter, update hash, clear field.
movenum50_t incPly50Moves()
piece_t m_capturedpiece
4 castling bits as uints as copy ctor stumbles on bool array
piece_t setGetPiece(column_t const newcol, rank_t const newrank, piece_t const piece)
used for makeBoardMove
piece_t removePiece(column_t const newcol, rank_t const newrank)
used for makeBoardMove
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
void swapPiece(case_t const t, piece_t const op, piece_t const np)
void calcHash()
Set hash based on board position, also calc pieces Byte 0: bits 4-6 capture count (masked) bit 7 play...
movenum50_t getPly50Moves() 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
void clearCastle(uint8_t const f)
bool isFieldEmpty(case_t const bc) const
void setPly(plynum_t const p)
basicmove_t getBasicMoveT() const
MEMBER_CONSTEXPR case_t to() const
MEMBER_CONSTEXPR case_t from() const
column_t tocolumn() const
void setCapture(piece_t const p, case_t const c) override
set non-silent flag, store captured piece and case (for undo)
void setCastleDoneWhite(bool const c)
bBoard(bBoard &&b) noexcept
Used when Push board on gamestack (playGameMove)
void invertColours()
invert colours update kingpos, update colour to move, castle rights, ...
bMove const & getMove(movenum_t const moveid) const
void setVariation(bBoard const &chldbrd)
bMoveList & getMoveListRef()
return reference to movelist
movesequence_t const & getPreviousMoves() const
void setCastleDoneBlack(bool const c)
movesequence_t const & getVariation() const
void calcGameStage()
calculate pieces
bool atLeastOneMovePossible() const
see if at least one move can be played e.g.
position on board, defined as 255 if invalid used primarily to compose a move or a source or destinat...
static constexpr case_t coordToCase(column_t const c, rank_t const r)
bScore EvalForPlayer(bBoard const &b)
piece_t getBlackPromotionPiece() const
bool isMajorPromotion() const
test if major promotion or mating promotion (queen, knight) if minor promotion, move is considered as...
bool isCastleMove() const
bool isEPPossible() const
piece_t getWhitePromotionPiece() const
bool isLongCastleMove() const
movenum_t generateMoves(bBoard const &b)
generate moves if not yet generated
bool atLeastOneMovePossible(bBoard const &b) const
see if at least one move can be played e.g.
static cpiece_t getPieceChar(piece_t const p)
static class member function
uint8_t capturedpiece
4 castling bits, plus incheck flag and capture move