user15810: It's White to move. What was Black's last move, and what could have happened before that?
[FEN "8/8/8/8/8/3P2P1/3P2Pk/2KR3N w - - 0 1"]


user12873: For the King to be on h2, it must have previously been on either h3 to g1. Being on h3 would have been impossible, since the g2-pawn has been there the entire game. So, the King must have been on g1.
One could give a counterargument saying that Rd1 has been on the 1st rank for more than one move, since it appears stuck. However, this idea is refuted by the fact that White could have castled with 0-0-0.
But then if White castled queenside, his King must have been on e1 the entire game.... which poses the problem of how Black's King got to g1 in the first place. I'm stuck at this point.
EDIT: I didn't consider the possibility of White ALREADY castling, and then Black moves his King to e2. Maybe there's some White piece on the first rank that allows Black's King to move to g1 without being attacked by Rd1. Then, as user1583209 pointed out, a move like Nf1-Nh2+ Kxh2 would give us the final position.

user13433: Building on user1583209's answer, here is a complete sequence of moves to show how the black king managed to trap himself in the corner in the first place:
[FEN "8/8/8/8/2N1N3/3k2P1/3P2P1/2KRq3 b - - 0 1"]

1... Ke2 2. Nc3+ Kf1 3. Ne4 Kg1 4. Ne3 Kh2 5. Nf2 Qg1 6. Nh1 Qf1 7. Nxf1+ Kg1 8. Nh2+ Kxh2

Another possibility:
[FEN "8/8/8/7q/2N1N3/3k2P1/3P2P1/2KRq3 b - - 0 1"]    

1... Ke2 2. Nc3+ Kf1 3. Ne4 Kg1 4. Nf2 Kf1 5. Nh1 Kg1 6. Ne3 Qf1 7. Nxf1 Qh2 8. Nxh2+ Kxh2


Third example by user1583209 without blocking piece:
[FEN "8/8/8/7q/2N1N3/3k2P1/3P2P1/2KR4 b - - 0 1"]

1... Qh6 2. Kb2 Qh7 3. Ra1 Qh6 4. Kc1 Qh7 5. Nf2+
Ke2 6. Nh1 Kf1 7. Ne3+ Kg1 8. Nf1 Qh6 9. Kb2
Qh7 10. Rd1 Qh6 11. Kc1 Qh2 12. Nxh2+ Kxh2


user11629: There is only one black piece left, so the last move was with the king. Black's last move was obviously Kg1-h2.
The king could not have come from h3, because there is no way the white pawn could have given check from g2 (its initial position). All other squares around h2 are occupied by white pieces.
Since the black king came from g1, it was in check from the rook on d1 before the last move. Obviously the rook could not have moved to d1 from somewhere on the d file because the pawn on d2 blocks the way. So there are two possibilities how the rook could have given check:

discovered check, i.e. a white piece moved away  form e1 or f1 making space for the attack on the black king on g1
long castle

As for "1" None of the pieces currently on the board could have moved away from the 1st row (i.e. from e1 or f1) to give way for the check. However if a white knight moved from f1 to h2 giving check that would be a discovered check and the black king captured this knight on h2. Obviously this is the only option for a discovered check.
As for "2". If white castled long, that means that the white king never moved (castling rules) before, meaning the white king was always on e1. Then the question is: How did the black king get to g1? With the white king on e1, the black king could not have entered via f1 or f2. Neither it could have come via g2 (where there is still the original white pawn). 
This would mean that it came via h2. But is that possible? In order to get to h2, it would have to come from h3 (not possible because of the original never-moved pawn on g2) or from g3. 
However the black king could never have entered via g3, because the square was either i) attacked by a pawn from f2 or ii) occupied by that same pawn from f2.
That leaves as the only option, as last moves 1. Nf1-h2+ Kxh2

Going back one move further, what was the last move of black before Nf1-h2+? There are two possibilities: it could be a move by the king or it could be a move by a piece which got captured on h2 by the knight.
Let's analyze both options.
Black moved the king in move 0
If the last move was by the black king it could not have come from f1, g2, h1 (which are blocked by white pieces) and neither could it have come from f2, because there is no way the knight on h1 could have given check. That leaves only h2 as possible option. So assuming the king came from h2, where it was in check, the last white move must have been Ne3-f1+. So the moves are now 0. Ne3-f1+ Kh2-g1 1. Nf1-h2+ Kxh2. 
That is not the end of the story yet, because looking at the position before 0. Ne3-f1+ you note (basically for the same arguments as before, that the last move of black must have been Kg1-h2. On g1 the king would have been in check. This check (for the same arguments as presented before) could only have been a discovered check by the knight on e3.
So we have a situation where the black king is shuffling between g1 and h2 while the white knight is moving between f1 and e3. How can this infinite loop be broken? The only way to break this is, if there was a black piece at some point on f1, which blocked the check from the rook. This black piece on f1 got captured by the white knight when the black king was on h2.
Black moved a piece to h2 in move 0
If black must moved another piece that  got captured on h2, this piece can be a black pawn, knight, rook, or queen. It can not be a black bishop, because it could not have moved to h2 (because g3 and g1 were occupied by pieces).
Summary
Two possible solutions:
0. .... N/Q/R/pawn h2
1. Nf1xh2 Kg1xh2

or
Initial position: 
white: pawns on d2,g2,g3; Nh1; Ne3; Kc1; Rd1; 
black: Kh2; some piece on f1
-n. Nx piece f1+ Kh2g1
[any number of repeating moves with the knight shuffling between f1 and e3 and the king between g1 and h2]
-1. .... Kg1h2
 0. Ne3f1+ Kh2g1
 1. Nf1h2 Kg1xh2


15810: <p>It's White to move. What was Black's last move, and what could have happened before that?</p>
<pre><code>[FEN &quot;8/8/8/8/8/3P2P1/3P2Pk/2KR3N w - - 0 1&quot;]
</code></pre>
 12873: <p>For the King to be on h2, it must have previously been on either h3 to g1. Being on h3 would have been impossible, since the g2-pawn has been there the entire game. So, the King must have been on g1.</p>

<p>One could give a counterargument saying that Rd1 has been on the 1st rank for more than one move, since it appears stuck. However, this idea is refuted by the fact that White could have castled with 0-0-0.</p>

<p>But then if White castled queenside, his King must have been on e1 the entire game.... which poses the problem of how Black's King got to g1 in the first place. I'm stuck at this point.</p>

<p>EDIT: I didn't consider the possibility of White ALREADY castling, and then Black moves his King to e2. Maybe there's some White piece on the first rank that allows Black's King to move to g1 without being attacked by Rd1. Then, as user1583209 pointed out, a move like Nf1-Nh2+ Kxh2 would give us the final position.</p>
 13433: <p>Building on user1583209's answer, here is a complete sequence of moves to show how the black king managed to trap himself in the corner in the first place:</p>

<pre><code>[FEN "8/8/8/8/2N1N3/3k2P1/3P2P1/2KRq3 b - - 0 1"]

1... Ke2 2. Nc3+ Kf1 3. Ne4 Kg1 4. Ne3 Kh2 5. Nf2 Qg1 6. Nh1 Qf1 7. Nxf1+ Kg1 8. Nh2+ Kxh2
</code></pre>

<p>Another possibility:</p>

<pre><code>[FEN "8/8/8/7q/2N1N3/3k2P1/3P2P1/2KRq3 b - - 0 1"]    

1... Ke2 2. Nc3+ Kf1 3. Ne4 Kg1 4. Nf2 Kf1 5. Nh1 Kg1 6. Ne3 Qf1 7. Nxf1 Qh2 8. Nxh2+ Kxh2
</code></pre>

<hr>

<p>Third example by user1583209 without blocking piece:</p>

<pre><code>[FEN "8/8/8/7q/2N1N3/3k2P1/3P2P1/2KR4 b - - 0 1"]

1... Qh6 2. Kb2 Qh7 3. Ra1 Qh6 4. Kc1 Qh7 5. Nf2+
Ke2 6. Nh1 Kf1 7. Ne3+ Kg1 8. Nf1 Qh6 9. Kb2
Qh7 10. Rd1 Qh6 11. Kc1 Qh2 12. Nxh2+ Kxh2
</code></pre>
 11629: <p>There is only one black piece left, so the last move was with the king. Black's last move was obviously Kg1-h2.
The king could not have come from h3, because there is no way the white pawn could have given check from g2 (its initial position). All other squares around h2 are occupied by white pieces.</p>

<p>Since the black king came from g1, it was in check from the rook on d1 before the last move. Obviously the rook could not have moved to d1 from somewhere on the d file because the pawn on d2 blocks the way. So there are two possibilities how the rook could have given check:</p>

<ol>
<li>discovered check, i.e. a white piece moved away  form e1 or f1 making space for the attack on the black king on g1</li>
<li>long castle</li>
</ol>

<p>As for "1" None of the pieces currently on the board could have moved away from the 1st row (i.e. from e1 or f1) to give way for the check. However if <strong>a white knight moved from f1 to h2 giving check</strong> that would be a discovered check and the black king captured this knight on h2. Obviously this is the only option for a discovered check.</p>

<p>As for "2". If white castled long, that means that the white king never moved (castling rules) before, meaning the white king was always on e1. Then the question is: How did the black king get to g1? With the white king on e1, the black king could not have entered via f1 or f2. Neither it could have come via g2 (where there is still the original white pawn). </p>

<p>This would mean that it came via <strong>h2</strong>. But is that possible? In order to get to h2, it would have to come from h3 (not possible because of the original never-moved pawn on g2) or from <strong>g3</strong>. </p>

<p>However the black king could never have entered via g3, because the square was either i) attacked by a pawn from f2 or ii) occupied by that same pawn from f2.</p>

<p>That leaves as the only option, as last moves 1. Nf1-h2+ Kxh2</p>

<hr>

<p>Going back one move further, what was the last move of black before Nf1-h2+? There are two possibilities: it could be a move by the king or it could be a move by a piece which got captured on h2 by the knight.</p>

<p>Let's analyze both options.</p>

<h2>Black moved the king in move 0</h2>

<p>If the last move was by the black king it could not have come from f1, g2, h1 (which are blocked by white pieces) and neither could it have come from f2, because there is no way the knight on h1 could have given check. That leaves only h2 as possible option. So assuming the king came from h2, where it was in check, the last white move must have been Ne3-f1+. So the moves are now 0. Ne3-f1+ Kh2-g1 1. Nf1-h2+ Kxh2. </p>

<p>That is not the end of the story yet, because looking at the position before 0. Ne3-f1+ you note (basically for the same arguments as before, that the last move of black must have been Kg1-h2. On g1 the king would have been in check. This check (for the same arguments as presented before) could only have been a discovered check by the knight on e3.</p>

<p>So we have a situation where the black king is shuffling between g1 and h2 while the white knight is moving between f1 and e3. How can this infinite loop be broken? The only way to break this is, if there was a black piece at some point on f1, which blocked the check from the rook. This black piece on f1 got captured by the white knight when the black king was on h2.</p>

<h2>Black moved a piece to h2 in move 0</h2>

<p>If black must moved another piece that  got captured on h2, this piece can be a black pawn, knight, rook, or queen. It can not be a black bishop, because it could not have moved to h2 (because g3 and g1 were occupied by pieces).</p>

<h2>Summary</h2>

<p>Two possible solutions:</p>

<pre><code>0. .... N/Q/R/pawn h2
1. Nf1xh2 Kg1xh2
</code></pre>

<p>or</p>

<p>Initial position: </p>

<p>white: pawns on d2,g2,g3; Nh1; Ne3; Kc1; Rd1; 
black: Kh2; some piece on f1</p>

<pre><code>-n. Nx piece f1+ Kh2g1
[any number of repeating moves with the knight shuffling between f1 and e3 and the king between g1 and h2]
-1. .... Kg1h2
 0. Ne3f1+ Kh2g1
 1. Nf1h2 Kg1xh2
</code></pre>
