const bool WhiteMove;tcusr wrote: ↑Sun Oct 03, 2021 10:59 pm you still didn't answer the question, if this everything is used as a template parameter how is it possible to pass the fen string as a command line argument?
i don't understand your example, i too use a special function for castling (by passing the king square, rook square and color as template arguments) but i still need to do a runtime check of the castling rights
const bool HasEPPawn;
const bool WCastleL;
const bool WCastleR;
const bool BCastleL;
const bool BCastleR;
Since you seem to be interested I will PM you URL for the codeproject article once its out.
These fields live outside of the runtime. When you enter FEN - you have to a lookup which of the 64 possible template configurations to use.
For example a pawn push only affects the HasEPPPawn flag. The others are copied. Thats the beauty. You can "call" a constexpr function inside a template argument:
Code: Select all
constexpr BoardStatus PawnPush() const {
return BoardStatus(!WhiteMove, true, WCastleL, WCastleR, BCastleL, BCastleR);
}
Notice how that constexpr is used as a template argument which returns the boardstatus. itself. Since you always call one of the 64 configurations the compiler has everything it needs to know

This is a compiletime statemachine which makes it so that if you move the king - no castling is possible anymore - the C++ code does not even contain an if for it for the calls after that. It is constexpr pruned away.
The lookup if (Color == White) Pawn >> 8 else Pawn << 8 -> becomes a simple shift without the condition etc.
This is applicable for CUDA too since templates are just part of the function signature and nothing more!
This is not new in hight perf c++ - but i didnt see it used much in chess. Only for color so far.