SebLague / Chess-Challenge

Create your own tiny chess bot!
https://www.youtube.com/watch?v=Ne40a5LkK6A
MIT License
1.78k stars 1.07k forks source link

Significant performance boost to IsDraw method #474

Open Sparxel opened 10 months ago

Sparxel commented 10 months ago

The IsDraw() method in the Board.cs is currently public bool IsDraw() { return IsFiftyMoveDraw() || IsInsufficientMaterial() || IsInStalemate() || IsRepeatedPosition(); } I messed with the API code and moved the IsStalemate() part to the end, which actually gave ~7% boost to my nodes/second for my implementation. I suspect this is because the code for the IsStalemate and hence move generation is not evaluated at all if IsRepeatedPosition() returns true. So can this tiny change be made to the API?

Vanny-Chuck commented 9 months ago

Issue a pull request!

Vanny-Chuck commented 9 months ago

@SebLague

mcthouacbb commented 9 months ago

You can just use isrepeateddraw and isfiftymovedraw alone, and detect stalemate and checkmate manually by detecting when there are 0 legal moves. insufficient material is just a waste of tokens as it does not provide any significant boost in playing strength