When all you've got is a hammer, everything looks like a nail - so I'd say that this type of problem can be solved using constraint programming. But that's just what I've got a little experience in.
Basically, you have a board layout, and there are a small number of valid moves at each 'step'. The aim is to move into a known layout (ascending order).
To do this 'automatically', you need to have the program search for a solution path. The steps to do this are something like this:
- From the current layout, determine the valid moves.
- Calculate the layout after taking each of the valid moves.
- Check if any of the calculated layouts is the solution; if it is, you're finished.
- If none of the moves resulted in the solution, work out all the newly-valid moves, and repeat from 1.
You'll have some issues doing this. Firstly, memory constraints (making a bazillion copies of your board layout might not work). Secondly, time/computational constraints (it might take a long, long time to find a solution). There are some things you can do to at least minimize the damage from these issues.
- Choose a good search method. Breadth-first as opposed to Depth-first, for example. This will both decrease the time taken to find a solution and decrease the memory requirements.
- Some moves are "backwards". For example, moving square A to B, and then square B to A (repeating moves). Searching these 'loops' is both pointless and resource-wasting, so you'd want to ensure you don't do that.
- There is the possibility of symmetries in the search space. I haven't solved your particular problem, and I couldn't give you examples specific to you, but the n-queens has a nice section on symmetries specific to that problem - it might be worth a read if you're trying to find symmetries in your problem.
That might give you some information, or thoughts to start looking.