Disclaimer: As far as I can tell, the original version of the Tower of London cognitive test is in the public domain, so I’m hoping that I am not violating any copyrights here.
The Tower of London cognitive test uses a horizontal board with three vertical posts and 3 colored balls (red, green and blue in the original version) drilled to slide onto the posts. The posts from left to right can hold 3, 2 and 1 balls respectively. This is similar to the classic Tower of Hanoi puzzle, but the varying post heights changes the game. The original version has one example and 12 problems. In each case, the starting position of the balls is the same, the goal is to rearrange them with the minimum number of legal moves to match the given target arrangement. The rules are that you can only move the top ball from a post, and only place it on a different post with free space, and each such rearrangement counts as one move.
For the original version the start arrangement is:
X
R X
G B X
where X indicates a free space, and R, G and B are the three colored balls. The trial example, shown below, requires a minimum of 2 moves; first move the red ball to post 3, then the blue ball to post 1.
X
B X
G X R
I have been asked to create a web version of the test, and so I want to find a way to enumerate all of the possible minimum move targets (final arrangements) possible given the constraints described above, and this finally leads to my question.
What I plan to do is to create code to take any initial state and step through all of the possible new states that one legal move can produce. If any such resulting state has already occurred after any lower number of moves, then this state can be eliminated at the current move number because it is possible to reach it with fewer moves, and so fails the minimum number of moves criteria. For each of these 1 move states, I repeat the process and generate the set of 2 move states, and so on. The original version of the test only went up to 5 move targets, although later versions of the test have used higher move numbers.
Will this approach work as I think it should? I have done this by hand for the original version starting arrangement for up to 5 moves, and it appears to be working, but I would like to create code to take any start arrangement and any (reasonable) number of moves.