Answers.Body: <p>Firstly, FEN notation is used to describe a board state or permutation, not a family of board states or permutations.</p>
  
  <p>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</p>
  
  <p>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. </p>
  
  <p>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. </p>
  
  <p>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. </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-06T18:45:12.413Z
Answers.Text: 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?
Answers.UserDisplayName: Dan Forbes
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-05T16:37:06.183Z
Answers.LastActivityDate: 2015-12-05T16:37:06.183Z
Answers.UserDisplayName: Yusuf Ali
Answers.Body: <p>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.</p>
  
  <p>Trivia: An example from KRKP:</p>
  
  <pre><code>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#}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-11T10:30:28.927Z
Answers.LastActivityDate: 2016-01-11T10:30:28.927Z
Answers.UserDisplayName: ChessNotation
Body: <p>is it possible to generate FEN strings for endgames based on specific criteria:  n-pieces, w/d/l, and side to move?</p>
  
  <p>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.  </p>
  
  <p>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.</p>
  
  <p>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?</p>
  
  <p>Thanks!!</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-02-23T00:53:59.250Z
Comments.Text: Some answers below interpret the question term: "FEN for endgame"  as either from existing databases, providing the maximal EGTB input variable domain (FENs), or as "every possible position of a given endgame class", i.e. all FEN string within all the given materai N men classes (N not larger than 7).  
  
  That last case, does not specify the chess legal restriction type to those FEN being generated.  The first, hidden input DB.
  
  So which is it for the op.  Only some input database subset or the second unrestricted set of FEN (which would be implement in the code generating the FENs).
Comments.UserDisplayName: dbdb
Tags: <endgame><fen>
Title: Endgame FEN generator
ThreadText: # Endgame FEN generator
  
  (Asked by: username_0 on 2015-06-22)
  
  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?
  
  Thanks!!
  
  **Tags:** endgame, fen
  
  > **Comments:**
  > **username_1**: Some answers below interpret the question term: "FEN for endgame"  as either from existing databases, providing the maximal EGTB input variable domain (FENs), or as "every possible position of a given endgame class", i.e. all FEN string within all the given materai N men classes (N not larger than 7).    That last case, does not specify the chess legal restriction type to those FEN being generated.  The first, hidden input DB.  So which is it for the op.  Only some input database subset or the second unrestricted set of FEN (which would be implement in the code generating the FENs).  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2015-12-05. Score: 1
  
  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.
  
  > **Comments:**
  > **username_0**: 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?  
  
  ---
  
  ### Answer by username_3 on 2016-01-11. Score: 0
  
  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#}
  
  
  ---
  
  