user25645: Given a FEN board position, is there an algorithm that can return a PGN move list that evaluates to it from the standard initial position?

user24693: The natural approach to this problem is a tablebase-like approach like outlined by Brian. But doing something similar to that for just 7 pieces (namely, 7 men tablebases) with current algorithms already takes many months of calculation and 1 Tera Byte of RAM, doing that and trying to get to the starting position sounds pretty impossible. (otherwise one may just as well try to solve chess by building a 32 men TB)
In general I strongly suspect this problem is NP hard. However in practice the following human-like approach should work for most positions: Determine which pieces are missing from either side and evaluate how many captures are necessary to form the given pawn structure. (e.g. you need at least one capture to create a doubled pawn) Based on that, create "paths" that the pawns might have taken to reach the current pawn structure. Then try to move the to be captured pieces on that path to be captured by pawns if necessary. Move the remaining pieces on their squares.
The reason why this will work most of the time is that the only irreversible moves are captures and pawn moves (this is not quite true, but close enough for this explanation). Therefore, the shuffling of other pieces does not need to be exact, there are many ways to bring some piece to some other square. (but there may only be one way to get a pawn to a certain square)
For most "real life" examples this should work well enough. Things will get more complicated, once you require promotions or specific move orders (for instance because some piece is locked in by pawns and the piece and pawn movements must be coordinated to achieve that position). Also, if 50 moves rule becomes a factor because in that case it might matter which path pieces choose. Nonetheless for most practical positions that is not an issue.
Even for those difficult positions I still think human like approaches might be useful. The following is very vague, but I think what could work is trying to determine certain scenarios that must have happened. For a contrived example, consider a position white Bf8, black Pg7 Pe7. The bishop can not have moved there since the pawns are on g7 and e7 still. So it must have come from a promotion of the f pawn.
Accumulate all relevant scenarios, determine which are dependent and try to put them in some order that makes it work. In practice you will fail here for some positions but such is the nature of NP hard problems. More specifically, I suspect that for every algorithm you devise, there will be some position that you can't solve with current computing power.

user4418: If you are familiar with mathematical induction then it should be clear to you that the answer is trivially "Yes".
Just as for any position (legal or otherwise) it is possible to use the laws of chess to calculate all the legal moves in that position (this is what computer engines do) so given any position (legal or otherwise), P(n), other than the start position and a side, S(n), either black or white, it is possible to calculate all the possible previous legal moves for player S(n). This will likely give many new positions (some may be illegal), P(n-1).
If P(n-1) is the empty set then we know that P(n) was an illegal position. If P(n-1) is not the empty set then set S(n-1) to the opposite of S(n) and repeat the previous step for all elements of P(n-1) for player S(n-1).
If the original position was legal then this induction process will terminate with the initial position. If the original position was not legal then it will terminate with some other position.

user25684: The task you are considered is usually called a proof game, named such because the task is to prove that the position is legal.  As a genre of puzzles, there are various aesthetic constraints, most commonly that the resulting game be unique.  However, this is not necessary in general, and there is even a genre of counting the number of solutions.
There are several programs available that perform this task of solving proof games:

Natch is often considered the fastest.  You can see it in use in this answer to another question on this site: "Can it be proven that 11. 0-0-0+ is legal in this position?"

Euclide is apparently most useful when the sequence of moves is unique.

Popeye can solve many chess problems, including fairy chess problems.  Apparently it is not the most performant for proof games.

Jacobi is a program to solve (fairy) chess proof game problems.  It is written in JavaScript and run from browser, which makes it easy to try.


I have used Natch most successfully myself.

25645: <p>Given a <a href="https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation" rel="nofollow noreferrer">FEN</a> board position, is there an algorithm that can return a <a href="https://en.wikipedia.org/wiki/Portable_Game_Notation" rel="nofollow noreferrer">PGN</a> move list that evaluates to it from the standard initial position?</p>
 24693: <p>The natural approach to this problem is a tablebase-like approach like outlined by Brian. But doing something similar to that for just 7 pieces (namely, 7 men tablebases) with current algorithms already takes many months of calculation and 1 Tera Byte of RAM, doing that and trying to get to the starting position sounds pretty impossible. (otherwise one may just as well try to solve chess by building a 32 men TB)</p>
<p>In general I strongly suspect this problem is NP hard. However in practice the following human-like approach should work for most positions: Determine which pieces are missing from either side and evaluate how many captures are necessary to form the given pawn structure. (e.g. you need at least one capture to create a doubled pawn) Based on that, create &quot;paths&quot; that the pawns might have taken to reach the current pawn structure. Then try to move the to be captured pieces on that path to be captured by pawns if necessary. Move the remaining pieces on their squares.</p>
<p>The reason why this will work most of the time is that the only irreversible moves are captures and pawn moves (this is not quite true, but close enough for this explanation). Therefore, the shuffling of other pieces does not need to be exact, there are many ways to bring some piece to some other square. (but there may only be one way to get a pawn to a certain square)</p>
<p>For most &quot;real life&quot; examples this should work well enough. Things will get more complicated, once you require promotions or specific move orders (for instance because some piece is locked in by pawns and the piece and pawn movements must be coordinated to achieve that position). Also, if 50 moves rule becomes a factor because in that case it might matter which path pieces choose. Nonetheless for most practical positions that is not an issue.</p>
<p>Even for those difficult positions I still think human like approaches might be useful. The following is very vague, but I think what could work is trying to determine certain scenarios that must have happened. For a contrived example, consider a position white Bf8, black Pg7 Pe7. The bishop can not have moved there since the pawns are on g7 and e7 still. So it must have come from a promotion of the f pawn.</p>
<p>Accumulate all relevant scenarios, determine which are dependent and try to put them in some order that makes it work. In practice you will fail here for some positions but such is the nature of NP hard problems. More specifically, I suspect that for every algorithm you devise, there will be some position that you can't solve with current computing power.</p>
 4418: <p>If you are familiar with <a href="https://en.wikipedia.org/wiki/Mathematical_induction" rel="noreferrer">mathematical induction</a> then it should be clear to you that the answer is trivially &quot;Yes&quot;.</p>
<p>Just as for any position (legal or otherwise) it is possible to use the <a href="https://handbook.fide.com/chapter/E012018" rel="noreferrer">laws of chess</a> to calculate all the legal moves in that position (this is what computer engines do) so given any position (legal or otherwise), P(n), other than the start position and a side, S(n), either black or white, it is possible to calculate all the possible previous legal moves for player S(n). This will likely give many new positions (some may be illegal), P(n-1).</p>
<p>If P(n-1) is the empty set then we know that P(n) was an illegal position. If P(n-1) is not the empty set then set S(n-1) to the opposite of S(n) and repeat the previous step for all elements of P(n-1) for player S(n-1).</p>
<p>If the original position was legal then this induction process will terminate with the initial position. If the original position was not legal then it will terminate with some other position.</p>
 25684: <p>The task you are considered is usually called a <a href="https://en.wikipedia.org/wiki/Proof_game" rel="noreferrer">proof game</a>, named such because the task is to <em>prove</em> that the position is legal.  As a genre of puzzles, there are various aesthetic constraints, most commonly that the resulting game be unique.  However, this is not necessary in general, and there is even a genre of <a href="https://arxiv.org/abs/math/0508645" rel="noreferrer">counting the number of solutions</a>.</p>
<p>There are several programs available that perform this task of solving proof games:</p>
<ol>
<li><p><a href="http://natch.free.fr/Natch.html" rel="noreferrer">Natch</a> is often considered the fastest.  You can see it in use in this answer to another question on this site: <a href="https://chess.stackexchange.com/a/18835/25684">&quot;Can it be proven that 11. 0-0-0+ is legal in this position?&quot;</a></p>
</li>
<li><p><a href="http://lestourtereaux.free.fr/euclide/" rel="noreferrer">Euclide</a> is apparently most useful when the sequence of moves is unique.</p>
</li>
<li><p><a href="https://github.com/thomas-maeder/popeye/" rel="noreferrer">Popeye</a> can solve many chess problems, including fairy chess problems.  Apparently it is not the most performant for proof games.</p>
</li>
<li><p><a href="http://wismuth.com/jacobi/" rel="noreferrer">Jacobi</a> is a program to solve (fairy) chess proof game problems.  It is written in JavaScript and run from browser, which makes it easy to try.</p>
</li>
</ol>
<p>I have used Natch most successfully myself.</p>
