Due date Nov. 20, 2003
The purpose of this assignment is to improve on the "Fifteen" puzzle
discussed in class. You have to implement the following enhancements:
a) The generation of the initial position is not guaranteed to create
a board that can be solved. Instead of assigning random numbers to
the buttons, a better approach is to start from the solved position
(empty square on the bottom right-hand corner) and generate a series
of random moves (i.e move any of the neighbors of the empty square into
the empty position). Use 50 moves to scramble the board reasonably well.
b) If the user gets discouraged, it might be friendly to fix the board
for him. To do this, keep track of the sequence of moves that you generated
in a), and keep track of the moves he has performed as well. Upon request,
execute those moves in the reverse order. You have to figure out how to encode
the moves so that this playback is easy to program.
c) These interactions with the player require a user interface: add two
buttons to the frame, under the board itself. The two buttons are labelled
"scramble" and "solve", and trigger the corresponding actions.
d) Everyone wants some recognition: after each user move, check if the
board is solved. If so, change the color of the board, print a congratulatory
message, etc. (Playing a little fanfare is optional).