is it possible to generate FEN strings for endgames based on specific criteria: n-pieces, w/d/l, and side to move?

So say I wanted all FEN strings for King plus Rook vs King plus Pawn (KPKR) endgames, where it is white to move, and white draws with perfect play.

I know there would be an extremly large number of results, and the next step would be to then categorize those results further by other criteria, like say white king is in front of the pawn, or the black pawn has passed the 6th rank.

I assume an endgame tablebase (egtb) has this information stored in it already, but how to get this information out of them? Or is there some other way of generating this?


2 Answers 2


Firstly, FEN notation is used to describe a board state or permutation, not a family of board states or permutations.

What you are talking about, is a way to index board positions based on your criteria. i.e. Rook vs Knight end games or such

This can be done by most database software (Fritz, Chessbase). This is done by searching games in the database, and pulling them out based on the board positions.

For example, if I want to get a bunch of rook vs knight end games, I can search for all FEN strings that contain only K,k,p,P,r,R,n,N. Basically, positions that contain pawns, knights, rooks and kings.

As for egtb, the format are stored using bit bases and the positions are assigned to a unique index. I would assume this is how Chess Position Trainer stores its FEN strings in order to determine transpositions.

  • 1
    Thank you for the reply! I know that chessbase can run those searches, the problem is the database uses real games which naturally means there are mistakes in the play (say a position that should be won with perfect play results in a draw or even loss due to inferior play). I would like to be able to somehow do the exact same search of an egtb or have some way of getting an egtb to generate a string of positions. Does that make sense?
    – Dan Forbes
    Dec 6, 2015 at 18:45

The most straightforward way would be to start with a chess program with tablebase capability and add a routine which would generate every possible position of a given endgame class and output those which had tablebase scores matching the selection criteria.

Trivia: An example from KRKP:

Longest mate score (BTM): MateIn43
Sample BTM longest mating position: 8/8/8/8/5R2/2pk4/5K2/8 b - - 0 1

Optimal move sequence from the above BTM longest mating position:

1... c2 2. Rf3+ Kd4 3. Rf4+ Kd5 4. Rf5+ Kc6 {Kd6} 5. Rf8 Kb7 {Kc7} 6. Rf7+ Kb6
7. Rf6+ Kb5 8. Rf5+ Kb4 9. Rf4+ Kb3 10. Rf3+ Kb2 11. Ke3 {Rf8} c1=Q+ 12. Kd4
Qc6 {Qc7 Qc8 Qd2+ Qe1 Qg1+ Qg5 Qh6} 13. Re3 Kc2 {Qb6+ Qd6+ Qf6+} 14. Re2+ Kb3
15. Re3+ Kb4 16. Ke5 Kc4 17. Re4+ Kd3 18. Rd4+ Ke3 19. Rd6 Qe4+ 20. Kf6 Kf4 21.
Re6 Qb4 {Qc2} 22. Kf7 Qb7+ {Qc3 Qc4} 23. Ke8 Kf5 {Qc7} 24. Rd6 Ke5 {Qc8+} 25.
Rd7 {Rh6} Qa8+ {Qb3 Qb5 Qc8+} 26. Kf7 Qc6 27. Re7+ Kf5 28. Kf8 {Kg8} Qd5 29.
Ke8 {Kg7} Qg8+ 30. Kd7 Kf6 31. Re8 Qf7+ 32. Kd8 Qb7 33. Re1 Qb4 34. Re2 {Re8}
Kf7 {Qa5+ Qb6+ Qb8+ Qd4+ Qd6+} 35. Kc7 {Kd7 Ra2 Rc2 Rf2+ Rg2} Qc4+ 36. Kd6 Qxe2
37. Kd5 Ke7 {Qd1+ Qd2+ Qd3+ Qe3 Qg4} 38. Kc5 Kd7 {Ke6 Qd2 Qd3 Qe3+ Qe4} 39. Kb4
{Kd4 Kd5} Qd3 {Qe3} 40. Ka4 {Kc5} Kc6 {Kc7 Kd6 Qb1} 41. Kb4 Kb6 42. Ka4 Kc5 43.
Ka5 Qa3# {Qb5#}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.