Nick Haubrich

Generating Chess Endgame Puzzles

Oct 19, 2023

A problem with chess books is that they can only contain so many puzzles. Page space is limited and tends to be spent on analyzing a single example in depth. This is helpful to learn the basics of the technique, but to fully master it one needs to use it repeatedly until it becomes second nature. In that view, while reviewing the classic Silman’s Complete Endgame Course, I whipped up a script to generate simple endgames in bulk.

The code, builds off a previous project that generated endgames with exceptionally long forced checkmate sequences. Now it generates randomly a position for python’s chess package and converts the boardstate’s FEN to a lichess-friendly URL, which can be viewed in the browser. Lichess’s endgame tablebase can be opened with a click to check the evalutation of the position or to play against the computer. It’s easy to go through 100 positions, and difficult problems can be saved to a lichess study for review.

I’ve collected a few interesting examples.

King and Pawn v King

This may look like a draw at first glance since White’s king is nearly in front of the pawn, but Black can play Ka6 and sneak ahead of the pawn. White is too slow to stop it.

Here White needs to gain the opposition, and Ke2 would accomplish this on an empty board. But Black’s Kd6 regains the opposition because White can’t follow with Kd2. White can try Kf2 instead of Ke2, but …Kd5 blockades the pawn so retaing the opposition with Kf3 doesn’t help.

King, Rook, Pawn V King, Rook

White seems lost given Black’s e pawn is ready to promote and Ra1 can be met with Rf1. The drawing resource, however, is Ra6+ and then Re6 to attack the pawn from behind. This buys time for White’s king to catch up to the pawn.

Black has cut off White’s king from the pawn and protects his own pawn. Unfortunately White’s king is already optimally placed. Black can let the pawn advance, and when it gets to f2 White won’t reach the Lucena position. Black’s rook can perpetually check White’s king from the side thanks to the king cutting off g1 and g2. Moving Black’s rook from the g file to block checks would let White’s king blockade the pawn with no hope of a win.