I assume you are talking about legality checking ("is enemy king in check"), I hope I did not misunderstand you. The normal "is my king in check" should not consume a huge amount of time IMO.stevemulligan wrote:My move generation is terrible. I get slow perft results too. I guess I should try and speed it up. I spend all most of my time checking for check.
Are you doing fully legal move generation, or do you generate pseudolegal moves and check for legality only after making it in the regular search?
The latter has some potential to be a lot faster than the former since you save many legality checks for those moves which are never made due to a cutoff.
For the "fully legal" approach, usually you can get a comparable performance only if you are using all the tricks to avoid calling some "isOpponentInCheck()" function for almost every move.
Even with the "check for legality only after makeMove()" approach you can be a lot smarter than always calling "isOpponentInCheck()" there. In my engine, for instance, I have some "last move may have been illegal" logic which reduces to something like:
Code: Select all
!lastMoveWasNullMove
&& (lastMoveWasCheckEvasion || lastMoveWasKingMove || lastMovePossiblyMovedAPinnedPiece)
Sven