lichess.org
Donate

Automatic puzzle categorization

Hi, is there any way to categorize my own set of puzzles, like in Lichess, automatically using Python? Specifically, I am looking for the sacrifice theme in my puzzles. Does Lichess categorize them manually?
Answering my own question here. I pondered the above problem over the weekend. It turns out it's not as complicated as I initially thought. If anyone is interested, the general algorithm is:

1. Check if the solution for a puzzle is Mate.
2. If it is mate, then check the material loss for each color at the start and end positions.
Typical sacrifices should have a bigger material loss compared to the opponent.
3. If it's not mate, then check the immediate capture and recapture.
A typical sacrifice does not have an immediate equal value of recapture.