WilliamL. Colsher, 4328 Nutmeg Lane, Apt. Ill, Lisle, IL 60532.
The program that this article is
based on does more than just generate a puzzle.
One of the most important things it does is verify that the randomly generated puzzle is actually solvable.
Clearly, this is a nice feature to have.
The algorithm used in this section is given by D. D. Spencer Game Playing With Computers (Hayden Book Co., 1975).
Fig. 2 illustrates this algorithm in verbal form.
|
1. Let N be a number in position A of the puzzle to be solved.
Count how many num- bers smaller than N are in positions higherlettered than A.
Count the blank as 16.
2. Do this for all 16 positions (A-P) and add up the count.
3. If the blank square is one of the following: B, D, E, G, J, L, M or O, add one to the sum.
4. There is a solution if the sum is even.
5. There is no solution if the sum is odd.
|
Fig. 2. Algorithm for 15 Puzzle solvability. * |
* Adapted from Game Playing with Computers by D. D. Spencer. |
|
The program checks for legal moves by examining the four (at most) locations that surround a given number (specified during the game by its coordinates).
If any one of the locations contains the zero, then the move is legal.
Otherwise, an error message is printed and play continues.
Playing the game is really quite simple.
The computer will display the game board and then ask you for your move.
You then just type in the number you wish to move and hit ENTER, after which the computer will re-draw the game board, making your move.
In the event that your move results in a win (not very likely) the computer will congratulate you and ask if you want to play again.
|
Programm Listing.
[Das TRS-80 BASIC erlaubt für die Anweisungen Abkürzungen, z.B.
GOS. für GOSUB,
G. für GOTO,
RET. für RETURN usw.,
die in der MBASIC Quelle erweitert sind]
|
Eingescanned von
Werner Cirsovius
Februar 2014
© Microcomputing (kilobaud)