Define your problem as a states-graph:
G=(V,E)
where V=S={(x_1,x_2,...,x_54) | all possible states the 3d board can be in}
[each number is representing a single 'square' on the 3d board].
and define E={(v1,v2)| it is possible to move from state v1 to state v2 with a single step}
an alternative definition [identical] for E
is by using the function successors(v)
:
For each v in V: successors(v)={all possible boards you can get, with 1 step from v}
You will also need an admissible heuristic function, a pretty good one for this problem can be: h(state)=Sigma(manhattan_distance(x_i)) where i in range [1,54])
basically, it is the summation of manhattan distances for each number from its target.
Now, once we got this data, we can start running A* on the defined graph G, with the defined heuristic. And since our heuristic function is admissible [convince yourself why!], it is guaranteed that the solution A* finds will be optimal, due to admissibility and optimality of A*.
Finding the actual path: A* will end when you develop the target state. [x_i=i
in the terms we used earlier]. You will find your path to it by stepping back from the target to the source, using the parent
field in each node.