Classic Computer Magazine Archive COMPUTE! ISSUE 53 / OCTOBER 1984 / PAGE 78

Horse Racing

Robert Onufer

Watch your favorite pony win (or lose) in this detailed, effective simulation of race-track betting. Versions included for the TI-99/4A with Extended BASIC, the Commodore 64, VIC-20, Apple II+/IIc/IIe, and IBM PC/PCjr.

"Horse Racing" is a multiplayer game in which you must wager on horses. Up to nine players may play the game, and each starts the game with $500. There are five races. The player with the greatest amount of money after the fifth race is the winner. To make the simulation more accurate, the program recalculates the odds at the beginning of each race. That means that the favorite will always pay lower odds. And you will always know these new odds because they are posted just before the race begins.

Some of the most exciting horse races occur when the track conditions vary. The reason for this is that long shots often have a better chance of winning on slippery tracks because the track could cause some of the better horses to fall or not get a good footing for speed. Horse Racing varies the track conditions from race to race and gives a slight advantage to one horse for each particular track condition. This advantage is taken into account when the initial odds are calculated, making a horse the favorite very often, but not always. In the TI version of Horse Racing, you can change the advantage by changing the value of AD(T) in line 1030. (For other versions, see "Programmer's Notes.")

Track Graphics

After the final odds are displayed, the track is drawn using custom characters. These are drawn on the screen transparently and then lit up all at once in either line 710 or line 720, depending on track conditions. Using the powerful graphics capabilities of TI Extended BASIC, the horses are magnified sprites drawn on a 16 X 16 grid. The animation effect is created by alternating each horse through two different patterns, making the horses appear to move. Speed is randomly updated in lines 750 through 790.

When the program determines that a horse has crossed the finish line, the position of each horse is checked. The victory is given to the horse furthest across the finish line. The track is then erased, payoffs are made or monies deducted, and a summary appears on the screen. After the last race, you may choose to play again by pressing the 1 key or to exit the game by pressing the 2 key.

Programmer's Notes For VIC, 64, IBM, and Apple Versions

Patrick Parrish, Programming Supervisor

The VIC-20, Commodore 64, IBM, and Apple versions of "Horse Racing" are designed to capture the excitement of going to the races. As many as nine players can play the game by betting on one of five horses (six horses in the IBM version). Five hundred dollars is awarded to each player to start the game.

Winning odds are based on the wagers made before a race. When betting, bear in mind that each horse favors a different track condition. The advantage gained by a horse running under optimum conditions is determined by the variable AD(T) located in lines 50, 550, 730, and 380 in the VIC, 64, IBM, and Apple versions, respectively. If you want to add to the advantage given to a particular horse under specific track conditions, increase the value assigned to this variable.

The VIC version of Horse Racing runs on the unexpanded VIC with a few bytes to spare. The 64 version uses multicolor sprites to define the horse and riders. A short ML routine to move the sprites is loaded in from the DATA statements beginning at line 1350. The IBM version requires BASICA and a color/graphics adapter for the PC, or a PCjr with Cartridge BASIC. The race track is depicted on graphics screen 1 with the horse and riders drawn from DATA stored in lines 290-500.

The Apple version of Horse Racing runs on all Apple IIs with DOS 3.3 or ProDOS. Since the program uses the secondary text page (at 2048, where the BASIC program normally resides), a series of POKEs is required to relocate the BASIC program. These POKEs are done by Program 5, which serves as our loader program. It locates Program 6 (which must be saved as "HORSERACE") at location 24576 by POKEing 104 and 103 (the high- and low-byte pointers to the start of the BASIC program) with 96 and 0, respectively (256*96 + 0 = 24576).

Program 6 defines the horses as high-resolution shapes with shape table DATA stored from line 790 on. The movement of the horses is animated by use of a high-resolution page-flipping routine in lines 190–210. This routine lets you view the horses on one high-resolution screen while drawing them further along the track on a second high-resolution screen. After the shapes have been placed on the second screen, this screen is viewed and drawing is done on the first screen. This sequence continues until the race is won.

A series of POKEs enables us to page flip in Program 6. By alternately accessing locations –16300 and –16299, either high-resolution screen 1 or 2 is displayed. POKEing location 230 with 32 or 64 causes the shapes to be drawn on high-resolution screen 1 or 2, respectively.

"Horse Racing" for the TI home computer.

Horse-racing action in the Commodore 64 version of "horse Racing."

Six horses racing for victory in the IBM version of "Horse Racing."