guidopetri / chess-pipeline

Pulling games from the Lichess API into a PostgreSQL database for data analysis.
GNU General Public License v3.0
20 stars 2 forks source link

fix checkmate eval is none #74

Closed guidopetri closed 6 months ago

guidopetri commented 6 months ago

The checkmate eval is returning None which causes a lot of downstream problems. This isn't usually a problem because a checkmate only happens in a mate-in-1 position, so the eval from a previous position that is examined carries forward to the checkmate position, but if said mate-in-1 position is skipped in the eval analysis, this leads to errors estimating win probabilities.

This PR fixes this by checking whether the position is checkmate and returning 9999 / -9999 depending on the winner. As a result, get_sf_evaluation never returns None, so I cleaned up some code and made it a little more straightforward.

Finally, I added a test for a checkmate position so that this error hopefully does not happen again.