Classic Computer Magazine Archive ANTIC VOL. 6, NO. 1 / MAY 1987


An 8-bit classic comes to ST

Article by PATRICK BASS, Antic ST Program Editor

Antic Towers screenWe all tend to think video games have been around five, maybe ten years at the most. This month, Antic's ST Resource presents a videogame which was first written about 4,000 years ago.


No, it wasn't written on the legendary Apple 0.5, or even the rumored Atari Model 1. If anything, it was written (in disk format, of course,) on a early CLAY-0 computer, and has been used by educators for many thousands of years as a test of a person's reasoning ability. Believe it or not, you've probably played this game many times under another name.

Originally, the game was called the Towers of Hamurrabi, and more recently, the Towers of Hanoi. For our super version in the ST Resource we decided to call our program Antic Towers, to coincide with us moving to our new, expanded building near the heart of downtown San Francisco.

The object of the game is to transfer however many disks you start with from the left pole over to another pole in the least number of moves. Sounds easy, right? However, you can't place a larger disk on top of a smaller disk. Now it gets harder.


Harder? It starts out easily enough, but the devilish part of this game is that the complexity of the game increases exponentially with the number of disks to move. This means the least number of moves required to complete the game will be the number of disks raised to its power of 2, (minus one). Sound complicated? It's not really. Here's a list of the minimum number of moves needed to complete each level.


1 ........ 1
2 ........ 3
3 ........ 7
4 ........ 15
5 ........ 31
6 ........ 63
7 ........ 127
So you can see that with seven disks, the least number of moves you could finish the puzzle in is 127. And if you get confused, the number grows upward from there. Plan to stay all day!


Carefully type in Listing 1, TOWERS.BAS, using either the editor built into ST BASIC or your favorite word processor. If you use a word processor, make sure the file is saved in ASCII format, which basically means making sure WP mode is turned off in lstWord, or selecting the proper menu selection from WordWriter. (See the January 1986 Antic for more information on using a word processor to type in ST BASIC listings.) When you finish, run TYPO ST and generate the TYPO Table for TOWERS.BAS. Check each line entry. If one of the checksums doesn't match, recheck that particular line again. Antic Disk Owners: TOWERS.BAS is on SIDE B of the Antic Monthly disk. Follow the ST Help file instructions to transfer the program from your 8-bit disk to your ST.

It starts out easily
enough, but the devil-
ish part of this
game is the complex-
ity of the game
increases exponentially
with the number of
disks to move.
Now it gets harder.


TOWERS.BAS is a straightforward BASIC program which includes some interesting GEM tricks performed within an ST BASIC environment. While it will run and operate in any resolution, it likes LO-RES best, and will encourage you to use it. LO-RES brings out the best colors in the game by far. Now, let's examine the program in detail.

Lines 1000-1050 are comments, signified by the leading single-quote. Lines 1060-1300 set the program up, and clear the screen graphically. The routine MAIN is where the program spends most of its time. First, get the current state and position of the mouse from the GET.MOUSE call. Next, determine if we're picking a disk up, or placing one down. If placing one down, check for the end of the game, and when the end is reached (by moving the disks successfully), fall through and END the game. The subroutine PULL/PULL.UP will extract a disk from a pole, and DOWN/PUT.DOWN will place the disk back down on a pole. Below that, between lines 2230 and 2370, NEW.GAME refreshes the ST and readies it for another round.


Examine the subroutine VRO.COPYFORM. This subroutine calls a GEM VDI function which will move a picture around the screen by using "bitblock" transfer, which is more commonly known as blitting. This function is built into every ST computer. You need to specify the upper-left corner coordinates, along with the width and heigth of the block to blit. and where to move it to. When the call is made, the block magically moves. (You'll see this feature used extensively in an upcoming version of "Kaboom" which Pratt and Everman are writing for us.)

Check Out the subroutine REVERSE. Have you needed to PRINT to the screen in reverse video? This one does it for you. It actually makes a call to GEM VDI to set the writing mode to reverse. Below that, the routine POLYLINE duplicates the GEM VDI call v_pline(), which will draw line segments from point to point very, very quickly. Here, it's used to erase the borders around the perimeter of the screen.


A 4000-year-old game? Yes. We ran it to show just how incredibly compatible the ST series computer is with software created before its time. Well, that's stretching things a bit, but it's certainly easier coding a game from 4000 years ago than one from 4000 years in the future!

Listing 1: TOWERS.BAS Download