Belofte version 2.1.8
A promising chess program using the UCI or Winboard interface
bBasicBoard Class Reference

#include <board.h>

+ Inheritance diagram for bBasicBoard:

Public Member Functions

plynum_t getPly () const
 
void setPly (plynum_t const p)
 
void incPly ()
 
void decPly ()
 
case_t getEp () const
 
void setEp (case_t const e)
 
void clearEp ()
 
movenum50_t getPly50Moves () const
 
void setPly50Moves (movenum50_t const p)
 
movenum50_t incPly50Moves ()
 
void clearPly50Moves ()
 
bool canCastle () const
 
bool canCastle (uint8_t const f) const
 
void setCastle (uint8_t const f)
 
void setCastle (uint8_t const f, bool const c)
 
void clearCastle (uint8_t const f)
 
bool isInCheck () const
 
virtual void setInCheck ()
 
void clearInCheck ()
 
bool whiteToMove () const
 
int16_t getMoveNumber () const
 
side_t getColourToMove () const
 
piece_t getPiece (case_t const bc) const
 1 for white, 2 for black
 
piece_t getPiece (column_t const iColumn, rank_t const iRank) 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 setPiece (case_t const bc, piece_t const piece)
 used for promotion move generation
 
void setPiece (case_t const bc, uint8_t const piece)
 used for unMakeBoardMove
 
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 movePiece (case_t const f, case_t const t, piece_t const p)
 
void swapPiece (case_t const t, piece_t const op, piece_t const np)
 
void clearPiece (case_t const bc)
 
void moveWhiteKing (case_t const f, case_t const t)
 
void moveBlackKing (case_t const f, case_t const t)
 
bool isFieldEmpty (case_t const bc) const
 
bool isFieldEmpty (column_t const iColumn, rank_t const iRank) const
 
virtual void setCapture (piece_t const p, case_t const c)
 Clear castle flag if rook captured update piece counter, update hash, clear field.
 
case_t getWhiteKingPos () const
 
case_t getBlackKingPos () const
 
bFen getFEN () const
 
std::string getHashStr () const
 
hashkey_t getHash () const
 
void setHash (hashkey_t const newHash)
 
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, no hash update no check flag set, etc.
 
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
 

Protected Member Functions

 bBasicBoard ()
 
 bBasicBoard (bBasicBoard const &bb)
 
 bBasicBoard (bBasicBoard &&bb)
 
 bBasicBoard (bFen const &fen)
 
virtual ~bBasicBoard ()
 
bBasicBoardoperator= (bBasicBoard const &)=delete
 
bBasicBoardoperator= (bBasicBoard &&)=delete
 
void calcHash ()
 Set hash based on board position, also calc pieces Byte 0: bits 4-6 capture count (masked) bit 7 player to move We are using 64 bits for hash.
 
void setPieceKU (case_t const bc, piece_t const piece)
 calculate and set hash
 

Protected Attributes

union { 
 
   uint64_t   u_positionFlags = 0ULL 
 
   struct { 
 
      case_t   m_whiteKing 
 
      case_t   m_blackKing 
 
      plynum_t   m_ply 
 
      case_t   m_ep 
 
      movenum50_t   m_ply50moves 
 
      uint8_t   m_castling 
 
      piece_t   m_capturedpiece 
 4 castling bits as uints as copy ctor stumbles on bool array More...
 
   }  
 
};  
 
hashkey_t m_hash
 

Detailed Description

Definition at line 38 of file board.h.

Constructor & Destructor Documentation

◆ bBasicBoard() [1/4]

bBasicBoard::bBasicBoard ( )
protected

◆ bBasicBoard() [2/4]

bBasicBoard::bBasicBoard ( bBasicBoard const &  bb)
explicitprotected

Definition at line 12 of file board.cpp.

◆ bBasicBoard() [3/4]

bBasicBoard::bBasicBoard ( bBasicBoard &&  bb)
explicitprotected

Definition at line 19 of file board.cpp.

◆ bBasicBoard() [4/4]

bBasicBoard::bBasicBoard ( bFen const &  fen)
explicitprotected
Todo:
check legality of position: Max number of pieces of each type e.g. K=1, Q=(9 - # pawns), N=(10 - # pawns) colour of bishops, double in-check, in case of ep, adjacent pawn movenumber if not initial position, location of pawns, position of king and rooks in case of castle allowed (att. 960) for each promoted piece, an opponent piece must have been taken

Definition at line 35 of file board.cpp.

+ Here is the call graph for this function:

◆ ~bBasicBoard()

bBasicBoard::~bBasicBoard ( )
protectedvirtual

Definition at line 26 of file board.cpp.

Member Function Documentation

◆ operator=() [1/2]

bBasicBoard & bBasicBoard::operator= ( bBasicBoard const &  )
protecteddelete

◆ operator=() [2/2]

bBasicBoard & bBasicBoard::operator= ( bBasicBoard &&  )
protecteddelete

◆ getPly()

plynum_t bBasicBoard::getPly ( ) const
inline

Definition at line 52 of file board.h.

◆ setPly()

void bBasicBoard::setPly ( plynum_t const  p)
inline

Definition at line 53 of file board.h.

Referenced by bBasicBoard().

+ Here is the caller graph for this function:

◆ incPly()

void bBasicBoard::incPly ( )
inline

Definition at line 54 of file board.h.

Referenced by bBasicBoard(), bBoard::invertColours(), and makeBoardMove().

+ Here is the caller graph for this function:

◆ decPly()

void bBasicBoard::decPly ( )
inline

Definition at line 55 of file board.h.

Referenced by bBoard::invertColours().

+ Here is the caller graph for this function:

◆ getEp()

case_t bBasicBoard::getEp ( ) const
inline

◆ setEp()

void bBasicBoard::setEp ( case_t const  e)

Definition at line 233 of file board.cpp.

Referenced by bBasicBoard().

+ Here is the caller graph for this function:

◆ clearEp()

void bBasicBoard::clearEp ( )
inline

Definition at line 60 of file board.h.

Referenced by bBasicBoard().

+ Here is the caller graph for this function:

◆ getPly50Moves()

movenum50_t bBasicBoard::getPly50Moves ( ) const
inline

Definition at line 63 of file board.h.

Referenced by getFEN(), and bPositionEvaluation::isGameEnded().

+ Here is the caller graph for this function:

◆ setPly50Moves()

void bBasicBoard::setPly50Moves ( movenum50_t const  p)
inline

Definition at line 64 of file board.h.

Referenced by bBasicBoard().

+ Here is the caller graph for this function:

◆ incPly50Moves()

movenum50_t bBasicBoard::incPly50Moves ( )
inline

Definition at line 65 of file board.h.

◆ clearPly50Moves()

void bBasicBoard::clearPly50Moves ( )
inline

Definition at line 66 of file board.h.

Referenced by setCapture().

+ Here is the caller graph for this function:

◆ canCastle() [1/2]

bool bBasicBoard::canCastle ( ) const

Definition at line 243 of file board.cpp.

Referenced by calcHash(), bWhiteKing::GenerateMoves(), bBlackKing::GenerateMoves(), getFEN(), and bBoard::invertColours().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ canCastle() [2/2]

bool bBasicBoard::canCastle ( uint8_t const  f) const

Definition at line 249 of file board.cpp.

◆ setCastle() [1/2]

void bBasicBoard::setCastle ( uint8_t const  f)

Definition at line 260 of file board.cpp.

Referenced by bBasicBoard(), bBoard::invertColours(), and setCastle().

+ Here is the caller graph for this function:

◆ setCastle() [2/2]

void bBasicBoard::setCastle ( uint8_t const  f,
bool const  c 
)

Definition at line 254 of file board.cpp.

+ Here is the call graph for this function:

◆ clearCastle()

void bBasicBoard::clearCastle ( uint8_t const  f)

Definition at line 269 of file board.cpp.

Referenced by setCapture(), and setCastle().

+ Here is the caller graph for this function:

◆ isInCheck()

bool bBasicBoard::isInCheck ( ) const

Definition at line 278 of file board.cpp.

Referenced by SearchAlphaBeta::CalcBestMove(), SearchAlphaBetaFH::CalcBestMove(), canCastle(), and SearchAlphaBeta::Quiescence().

+ Here is the caller graph for this function:

◆ setInCheck()

void bBasicBoard::setInCheck ( )
virtual

Reimplemented in bBoard.

Definition at line 283 of file board.cpp.

Referenced by bBoard::setInCheck().

+ Here is the caller graph for this function:

◆ clearInCheck()

void bBasicBoard::clearInCheck ( )

Definition at line 288 of file board.cpp.

◆ whiteToMove()

bool bBasicBoard::whiteToMove ( ) const
inline

◆ getMoveNumber()

int16_t bBasicBoard::getMoveNumber ( ) const
inline

Definition at line 81 of file board.h.

Referenced by getFEN().

+ Here is the caller graph for this function:

◆ getColourToMove()

side_t bBasicBoard::getColourToMove ( ) const
inline

Definition at line 82 of file board.h.

Referenced by bMoveList::atLeastOneMovePossible(), calcHash(), bMoveList::generateMoves(), getFEN(), makeBoardMove(), and unMakeBoardMove().

+ Here is the caller graph for this function:

◆ getPiece() [1/2]

◆ getPiece() [2/2]

piece_t bBasicBoard::getPiece ( column_t const  iColumn,
rank_t const  iRank 
) const

Definition at line 162 of file board.cpp.

+ Here is the call graph for this function:

◆ getPieceCtl()

piece_t bBasicBoard::getPieceCtl ( column_t const  iColumn,
rank_t const  iRank 
) const

retrieve piece with bounds checking, return field empty in case of out of bounds

Definition at line 171 of file board.cpp.

Referenced by bPieceColour::isAttackedByPiece().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setPiece() [1/2]

void bBasicBoard::setPiece ( case_t const  bc,
piece_t const  piece 
)

used for promotion move generation

Definition at line 190 of file board.cpp.

Referenced by bMoveList::addBlackPromotionIfValid(), bMoveList::addWhitePromotionIfValid(), makeBoardMove(), and unMakeBoardMove().

+ Here is the caller graph for this function:

◆ setPiece() [2/2]

void bBasicBoard::setPiece ( case_t const  bc,
uint8_t const  piece 
)

used for unMakeBoardMove

Definition at line 196 of file board.cpp.

◆ setGetPiece()

piece_t bBasicBoard::setGetPiece ( column_t const  newcol,
rank_t const  newrank,
piece_t const  piece 
)

used for makeBoardMove

Definition at line 202 of file board.cpp.

Referenced by makeBoardMove().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removePiece()

piece_t bBasicBoard::removePiece ( column_t const  newcol,
rank_t const  newrank 
)

used for makeBoardMove

Definition at line 212 of file board.cpp.

Referenced by makeBoardMove().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ movePiece()

void bBasicBoard::movePiece ( case_t const  f,
case_t const  t,
piece_t const  p 
)

Definition at line 317 of file board.cpp.

◆ swapPiece()

void bBasicBoard::swapPiece ( case_t const  t,
piece_t const  op,
piece_t const  np 
)

Definition at line 324 of file board.cpp.

◆ clearPiece()

void bBasicBoard::clearPiece ( case_t const  bc)

Definition at line 228 of file board.cpp.

Referenced by makeBoardMove(), and unMakeBoardMove().

+ Here is the caller graph for this function:

◆ moveWhiteKing()

void bBasicBoard::moveWhiteKing ( case_t const  f,
case_t const  t 
)

Definition at line 330 of file board.cpp.

◆ moveBlackKing()

void bBasicBoard::moveBlackKing ( case_t const  f,
case_t const  t 
)

Definition at line 338 of file board.cpp.

◆ isFieldEmpty() [1/2]

◆ isFieldEmpty() [2/2]

bool bBasicBoard::isFieldEmpty ( column_t const  iColumn,
rank_t const  iRank 
) const

Definition at line 183 of file board.cpp.

+ Here is the call graph for this function:

◆ setCapture()

void bBasicBoard::setCapture ( piece_t const  p,
case_t const  c 
)
virtual

Clear castle flag if rook captured update piece counter, update hash, clear field.

Reimplemented in bBoard.

Definition at line 297 of file board.cpp.

Referenced by bBoard::setCapture().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getWhiteKingPos()

◆ getBlackKingPos()

◆ getFEN()

bFen bBasicBoard::getFEN ( ) const

Definition at line 114 of file board.cpp.

Referenced by bel_debug::execute().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getHashStr()

std::string bBasicBoard::getHashStr ( ) const

Definition at line 542 of file board.cpp.

◆ getHash()

hashkey_t bBasicBoard::getHash ( ) const
inline

Definition at line 106 of file board.h.

◆ setHash()

void bBasicBoard::setHash ( hashkey_t const  newHash)
inline

Definition at line 107 of file board.h.

◆ makeBoardMove()

u_positionFlags_t bBasicBoard::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, no hash update no check flag set, etc.

Parameters
oldcolcolumn from
oldrankrank from
newcolcolumn to
newrankrank to
promotionpiece
Returns
captured piece

Definition at line 400 of file board.cpp.

Referenced by bWhitePiece::canMovePreflightCheck(), bBlackPiece::canMovePreflightCheck(), bWhitePiece::canMovePreflightCheck(), and bBlackPiece::canMovePreflightCheck().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unMakeBoardMove()

void bBasicBoard::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

Parameters
cfcase from
newcolcolumn to
newrankrank to
oldFlagsthe positionFlags of the old position
promotionmove signals return to pawn

Definition at line 481 of file board.cpp.

Referenced by bWhitePiece::canMovePreflightCheck(), bBlackPiece::canMovePreflightCheck(), bWhitePiece::canMovePreflightCheck(), and bBlackPiece::canMovePreflightCheck().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ calcHash()

void bBasicBoard::calcHash ( )
protected

Set hash based on board position, also calc pieces Byte 0: bits 4-6 capture count (masked) bit 7 player to move We are using 64 bits for hash.

Todo:
TOCHECK: increase to 64 bits, is there added value

Definition at line 355 of file board.cpp.

Referenced by bBasicBoard(), and bBoard::invertColours().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setPieceKU()

void bBasicBoard::setPieceKU ( case_t const  bc,
piece_t const  piece 
)
protected

calculate and set hash

used for setboard only

Definition at line 221 of file board.cpp.

Referenced by bBasicBoard(), and bBoard::invertColours().

+ Here is the caller graph for this function:

Member Data Documentation

◆ u_positionFlags

uint64_t bBasicBoard::u_positionFlags = 0ULL

Definition at line 122 of file board.h.

Referenced by bBasicBoard(), makeBoardMove(), and unMakeBoardMove().

◆ m_whiteKing

case_t bBasicBoard::m_whiteKing

Definition at line 124 of file board.h.

Referenced by getWhiteKingPos(), makeBoardMove(), moveWhiteKing(), setPieceKU(), and unMakeBoardMove().

◆ m_blackKing

case_t bBasicBoard::m_blackKing

Definition at line 125 of file board.h.

Referenced by getBlackKingPos(), makeBoardMove(), moveBlackKing(), setPieceKU(), and unMakeBoardMove().

◆ m_ply

plynum_t bBasicBoard::m_ply

Definition at line 126 of file board.h.

Referenced by decPly(), getColourToMove(), getMoveNumber(), getPly(), incPly(), setPly(), and whiteToMove().

◆ m_ep

case_t bBasicBoard::m_ep

Definition at line 127 of file board.h.

Referenced by clearEp(), getEp(), and setEp().

◆ m_ply50moves

movenum50_t bBasicBoard::m_ply50moves

Definition at line 128 of file board.h.

Referenced by clearPly50Moves(), getPly50Moves(), incPly50Moves(), and setPly50Moves().

◆ m_castling

uint8_t bBasicBoard::m_castling

Definition at line 129 of file board.h.

Referenced by canCastle(), canCastle(), clearCastle(), clearInCheck(), isInCheck(), setCastle(), and setInCheck().

◆ m_capturedpiece

piece_t bBasicBoard::m_capturedpiece

4 castling bits as uints as copy ctor stumbles on bool array

Definition at line 130 of file board.h.

Referenced by bBoard::isCapture(), and bBoard::setCapture().

◆ [union]

union { ... } bBasicBoard

◆ m_hash

hashkey_t bBasicBoard::m_hash
protected