Have you ever actually tried to do one of these puzzles? That strategy doesn't work. Ex 15-puzzle:
[ 1] [ 2] [ 3] [15]
[ x] [ x] [ ] [ 4]
[ x] [ x] [ x] [ x]
[ x] [ x] [ x] [ x]
There is no way to move 4 into place without moving 3.
The algorithm is only worked when the puzzle is solvable, I'm not sure if your example is a solvable one or not... and yes I have actually coded this algorithm few years ago, I don't remember the details but that's the main idea. Perhaps, we can move 3 (or even 1, 2) in some immediate steps, but after the steps are done, we should have 1, 2, 3, 4 in line.