Im Magazin „Microcomputing" wurde im Juni 1981 der folgende Artikel abgedruckt.
Das Spiel Number Squares - Magisches Quadrat.
|
|
Here's an intriguing kid's game program written for the SWTP, but in fairly standard BASIC, with no specialities of the system.
Number Squares
By Marc I. Leavey
It all started when my five-year-old daughter returned from a birthday party with a small plastic square with a four-by-four grid, in which there are 15 numbered tiles and one blank square.
The object of this number squares game is to move the tiles one at a time until they are in the desired order.
It may not seem like much, but it's fun, and it even had me going for a while.
Did I say it "had me going"?
That was the problem ‐ I was becoming addicted.
What makes the game so intriguing is that you can only move one tile at a time.
It wasn't long, though, before I duplicated the game on my CRT.
In the computer version, the board is represented by a four-by-four array.
Shifting a tile into the solitary blank space is the only legal move.
The number of the piece to be moved is thus the player input.
The computer checks to see if the piece input is next to a space and, if it is, moves the piece.
Moves continue until the pieces are in the desired order, at which time a win is declared.
|
Fig. 1.
One sequential solution to Number Squares.
|
To set up the program, a four by four array is established and sequentially filled with the integers one through 16.
The blank is represented by 16, and resides at the lower right.
Next, the board is scrambled by randomly moving the blank 200 times.
Each move is up, down, left or right, and, after 200 random moves, the board is quite a mess.
It is important to realize the board is not randomly filled with numbers.
If it were, there might be no solution to the puzzle.
Instead, the board is scrambled just as a real one is, by starting with a correct setup, and then moving pieces randomly – by the rules – to clear the board.
Once the board is initialized, it is displayed on the screen, and a user input is requested.
The input number is checked for range and validity of movement.
If all is in order, the input piece is moved into the blank, and the blank into the position of the input piece.
Remember, only vertical or horizontal moves are allowed; no diagonals are permitted.
After each move, the order of the board is scanned and, if in proper order, a win is declared.
But what is the proper order?
As originally conceived, a player wins when the tiles are in numerical order (Fig. 1).
However, another solution is possible.
In the Magic Square, every column and row adds up to 30.
In the interest of a more challenging game, I will not provide a diagram of the Magic Square solution.
It is available in the program if you look for it, but not knowing it exactly makes the game that much more fun.
I set up the display of the game for a terminal running at 1200 baud, with homing and erasing capabilities.
With some creative programming and a VDM, quite a nice display can be constructed and inserted in place of the display module in the program.
No fancy features of any special BASIC were used, and the program should run on any machine.
Marc I. Leavey, M.D., 4006 Winlee Road, Randallstown, MD 21133.
This is not a complicated program, but it shows methods of array handling and move checking.
Display formatting and concern for screen readability are also factors.
The game itself is addicting.
If you want to make it easier at first, change the setup scramble in line 480 to loop to 50 instead of 200, or make the loop variable and allow the user to choose his own degree of difficulty.
A sample routine might be:
0480 INPUT "DEGREE OF DIFFICULTY (10-500);"Q9
0485 FOR Q=1 TO Q9
Try it.
And if you've got a little girl around five, don't blame me if she takes over.
Mine did!
Eingescanned von
Werner Cirsovius
Januar 2014
© Microcomputing (kilobaud)