tcusr wrote: ↑Thu Sep 23, 2021 11:20 pm
what do you mean "the if constexpr are compiled away"? if constexpr only works with constants values and the en passant moves are run time values
also, i still don't understand if this is a perft tool or a chess engine. (if it was an engine you would have to save the moves in a move list and order them and this would defeat the purpose of your fast move generator)
Its a quick perft - which can be made a lot faster by implementing hashtables. The basis for a monte carlo engine. If stockfish visits one node and evaluates that position. In the same time a monte carlo engine with an ultra fast movegen can simulate the move + 50 resulting games in the same time - I think performance *COULD* be competitive.
Many people dont use templates for Whitemove and have If(Whitemove) all over the place. Big mistake.
Few? If any (I have only seen my engine) people use templates for very rare moves like castling. Also BIG performance mistake. Castles are rare. Even better once they happen its not possible to castle again. Enpassants are valid for only one move
Define a class like that:
Code: Select all
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)
{
}
constexpr BoardStatus SilentMove() const {
return BoardStatus(!WhiteMove, false, WCastleL, WCastleR, BCastleL, BCastleR);
}
}
And use it like that:
Code: Select all
template<class BoardStatus status>
MoveFunc(Move& move, Board& board){
MakeMove<status.SilentMove()>(move, board);
}
Also add the other constexpr functions like Kingmove and Pawnpush which may or may not affect the other flags. Whitemove is always toggled.
Please note how status.SilentMove() is executed as a template parameter at compiletime. When a pawn is pushed there is a constexpr template parameter: status.Pawnpush()
This means the compiler will have to emit every function 64x. But thats the price of performance. I measured it. Its a lot faster. That (and among other things) is why my executable has 12MB but its the fastest perft i have seen in the world in 2021. (excluding gpus and fpgas)