This program implements a simplified text-based golf game for nine holes. The player enters a swing power value between 1 and 100, which is converted into a distance using the formula `a/(6+RND)`, adding randomness to each shot. The hole position is randomized at the start of each hole using `INT(RND*15)`, and a two-stroke penalty is applied if the ball overshoots position 27 (the cup). The game tracks cumulative stroke totals across all nine holes and offers a replay option at the end.
Program Analysis
Program Structure
The program is organized into a main loop spanning holes 1 through 9, with a subroutine at line 300 for updating the total score. The overall flow is:
- Lines
10–40: Initialization — border color, clear screen, reset total strokes, print title. - Lines
50–70: Per-hole setup — randomize hole positionj, reset stroke counters. - Lines
80–260: Shot loop — draw course, accept input, compute new ball position, check win/overshoot conditions. - Lines
300–320: Score subroutine — accumulate totalt, print it, advanceNEXT y. - Lines
330–350: Post-game prompt — pollINKEY$for replay.
Gameplay Mechanics
At the start of each hole, the cup is placed at column j = INT(RND*15) (columns 0–14). The player inputs a power value a (capped at 100), and the ball advances by INT(a/(6+RND)) columns per stroke. The target column is fixed at 27. If the ball lands exactly on column 27 (j=27), a brief animation plays and the subroutine records the score. If it overshoots (j>27), two penalty strokes are added before the subroutine is called.
Key Variables
| Variable | Purpose |
|---|---|
t | Cumulative total strokes across all holes |
s | Stroke count for the current hole |
j | Current horizontal position of the ball |
a | Player-entered swing power (1–100) |
y | FOR loop counter — current hole number (1–9) |
Notable Techniques
- Randomized distance formula:
INT(a/(6+RND))divides power by a value between 6 and 7, introducing shot-to-shot variability even for identical inputs. - Course rendering: Line
80uses a string of block graphic characters (\::= █) to draw a solid fairway row, with the hole markerOprinted at the randomized columnj. - Ball erasure: Line
150erases the previous ball position by printing a space atAT 17,jbefore recalculatingj. - Hole-in-one animation: Line
210briefly shows the ball dropping into the cup — printingOat row 17, immediately overwriting it with a space, then printingOat row 18 — simulating a drop. - Replay loop: Lines
330–350pollINKEY$continuously without aPAUSE, which keeps the CPU busy-waiting for a keypress.
Bugs and Anomalies
- Broken game loop via
RUN: Lines280–290and line340useRUNto restart, which reinitializes all variables includingtand theFORloop variabley. This means the nine-hole loop never naturally completes — each hole restart viaRUNresets the total, sotnever accumulates across holes as intended. TheNEXT yat line320is effectively unreachable in the overshoot path (lines230–290jump past the subroutine’sNEXT yonly afterCLS : RUN). - Subroutine flow inconsistency: The win path (line
220) callsGO SUB 300, which containsNEXT yand loops correctly. The penalty path (lines230–290) also callsGO SUB 300at line260, but then executesPAUSE 120,CLS, andRUNafter the subroutine returns, restarting the program before the next hole can begin normally. - Input validation: Power values below 1 are not rejected; entering 0 will result in no ball movement (
INT(0/...)=0), looping the shot prompt indefinitely.
Content
Source Code
10 REM golf
20 BORDER 6: CLS
30 LET t=0
40 PRINT AT 0,12;"G O L F"
50 FOR y=1 TO 9
60 LET j=INT (RND*15)
70 LET s=0
80 PRINT AT 18,0; INK 4;"\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\:: \::\::\::\::";AT 17,j;"O"
90 PRINT AT 8,22;"HOLE ";y
100 PRINT AT 2,0;"Enter Power of Swing (1 to 100)."
110 PRINT AT 4,6;"TWO STROKE PENALTY";AT 5,7;"IF YOU OVERSHOOT"
120 INPUT a
130 IF a>100 THEN LET a=100
140 PRINT AT 2,0;" "
150 PRINT AT 17,j;" "
160 LET j=j+INT (a/(6+RND))
170 LET s=s+1
180 PRINT AT 8,4;"STROKES ";s
190 IF j<27 THEN GO TO 80
200 IF j>27 THEN GO TO 230
210 IF j=27 THEN PRINT AT 17,27;"O";AT 17,27;" ";AT 18,27;"O"
220 GO SUB 300
230 LET s=s+2
240 PRINT AT 8,13;s
250 PRINT AT 4,17;"PENALTY": PAUSE 120
260 GO SUB 300
270 PAUSE 120
280 CLS
290 RUN
300 LET t=t+s
310 PRINT AT 20,7;"TOTAL STROKES: ";t
320 NEXT y
330 PRINT AT 21,6;"Another Round?(y/n)"
340 IF INKEY$="y" THEN RUN
350 GO TO 330
9999 SAVE "golf" LINE 1: BEEP 1,32
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
