From Gigantua, the fastest chess move generator, it says that
The same holds true for the castling squares and most importantly the current moving color becomes a compiletime template and not an if statement. No single if statement should be wasted on non existing moves or which colors move it currently is.
...
We have 6 independent boolean board state flags - and none of these will ever need a single if during runtime. The cost of having if (Color == White) or Attack[Color] compiles away into nothingness. We only need a single switch statement as an entry point
Here is the struct used for the current game state:
class BoardStatus {
public:
const bool WhiteMove; const bool HasEPPawn;
const bool WCastleL; const bool WCastleR;
const bool BCastleL; const bool BCastleR;
constexpr BoardStatus(bool white, bool ep, bool wcast_left,
bool wcast_right, bool bcast_left, bool bcast_right) :
WhiteMove(white), HasEPPawn(ep), WCastleL(wcast_left),
WCastleR(wcast_right), BCastleL(bcast_left), BCastleR(bcast_right)
{
}
}
Because of the constructor, this implies that a new BoardStatus
structure will be created for every turn. How can that be efficient?
For example, how does this reduce the number of if
statements, because you still have to check the value of the WhiteMove
boolean?