"Allan W" <> wrote in message >
[He describes the classic plastic toy with pictures or symbols, where
> here are 15 square tiles arranged in a 4x4 grid, leaving one cell open.
> You slide tiles horizontally or vertically into the open cell, and
> thereby rearrange the tiles to correctly form the picture or put the
> symbols in order. His original ordering is
> > G B C J
> > M E O L
> > x A N D
> > F H K I
> with x marking the empty square, and he wants to arrange them like this:
> x A B C
> D E F G
> H I J K
> L M N O
> ]
>
> Presumably, JimC can create a program that performs an exhaustive search;
> first it would try every combination (all 3 of them!) of single moves,
> then every combination of 2 moves, and so on until it eventually finds
> the correct answer, or until the sun burns out, whichever comes first.
>
> I know about "tree-pruning" techniques, but I don't have a lot of
> experience with them. The obvious example for this problem would be
> to assign 1 point value for every tile that is in its correct place.
> When trees start exhibiting significant point differences, chuck the
> low-point trees.
>
> The problem with this approach (it seems to me) is that just before the
> puzzle is solved, it would have a pretty LOW point value -- in this
> game, pieces are moved by sliding others out of the way, and they
> eventually move back where they belong.
>
> Would a different scoring algorithm improve this? Maybe score 3 points
> for a piece in the right position, and 2 points for a piece right next
> to where it belongs? It seems to me that this would help the algorithm
> get the pieces in generally the right area, without causing the points
> to drop just because we're sliding another piece past some already-
> placed pieces (temporarily moving them).
I kindly doubt that this would help a lot. For example, imagine the
situation that almost everything is in place, except that O and N (or N & K)
are switched. Its point value is very high, just 2 point shy of the maximum,
yet it would be a pain somewhere to solve it.
> Again, I don't have a lot of experience with these types of algorithms
> (just book learnin'), so I'm probably not saying it right, maybe even
> making an ass out of myself, but I'd like to learn. I don't know about
> the OP, but I'd be interested in any suggestions anyone could offer,
> from anyone with experience.
I played a lot with these toys, so I dare to propose a not very elegant,
albeit workable algorithm. If you play around a little with the toy, you
will see that in general there is no problem arranging the last two lines.
1. So start backwards: put O,N in place. Get M next to L, then send them
together to their place.
2. Do the same with the third row: first K, then J, then H & I together.
3. For the first two rows you can apply brute force: there are only ~40000
possibilities, so you can avoid cyclicity by explicit checking. Or better
yet, move them all around in a circle (1->2->3->4->8->7->6->5->1) and
sometimes push a piece in the middle up or down until you get them in the
order (A->B->C->G->F->E->D).
It won't be the fastest solution (I estimate ~100 moves) and you will need 3
different routines (one for O, N, K, J; second for M,L and H,I pairs, third
for the first two lines) but it definitely will end before the Sun.
Sanyi