I have two 3x3 matrices. One representing the actual state and the other in a "current" state.
Actual state -> 1,2,3
5,7,6,
9,8,x
Current state1 -> 3,1,2
x,6,7
8,9,4
I need to bring the current state matrix to the original state by doing only swaps of elemen开发者_开发知识库t x and its adjacent element in horizontal or vertical direction.(diagonal is not allowed).
E.g. Current state 2 can be x,1,2 or 3,1,2
3,6,7 6,x,7
8,9,4 8,9,4
I can solve it till it reaches this state
current state n -> 1,2,3
5,7,6
8,9,x
I am clueless how to proceed to the original state after this, that is swapping two elements. Could you help me here?
Thanks
So, assuming you are talking about a puzzle like this (only smaller)
alt text http://www.maukatoyventures.com/images/T/Number%20Puz%20Wall%20Panel.jpg
then you can use most any graph search algorithm (Depth-First Search, Breadth-First Search, A* if you want to get fancy) to solve it. There is a decent overview of these as they apply to this specific problem here. There is also a massive amount of information about all of these floating around on the web.
精彩评论