Golf

This file is part of and SINCUS Exchange Tape 101 - Entertainment. Download the collection to get this file.
Type: Program
Platform(s): TS 2068
Tags: Game

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:

  1. Lines 1040: Initialization — border color, clear screen, reset total strokes, print title.
  2. Lines 5070: Per-hole setup — randomize hole position j, reset stroke counter s.
  3. Lines 80260: Shot loop — draw course, accept input, compute new ball position, check win/overshoot conditions.
  4. Lines 300320: Score subroutine — accumulate total t, print it, advance NEXT y.
  5. Lines 330350: Post-game prompt — poll INKEY$ 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

VariablePurpose
tCumulative total strokes across all holes
sStroke count for the current hole
jCurrent horizontal position of the ball
aPlayer-entered swing power (1–100)
yFOR 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 80 uses a string of block graphic characters (\:: = █) to draw a solid fairway row, with the hole marker O printed at the randomized column j.
  • Ball erasure: Line 150 erases the previous ball position by printing a space at AT 17,j before recalculating j.
  • Hole-in-one animation: Line 210 briefly shows the ball dropping into the cup — printing O at row 17, immediately overwriting it with a space, then printing O at row 18 — simulating a drop.
  • Replay loop: Lines 330350 poll INKEY$ continuously without a PAUSE, which keeps the CPU busy-waiting for a keypress.

Bugs and Anomalies

  • Broken game loop via RUN: Lines 280290 and line 340 use RUN to restart, which reinitializes all variables including t and the FOR loop variable y. This means the nine-hole loop never naturally completes — each hole restart via RUN resets the total, so t never accumulates across holes as intended. The NEXT y at line 320 is effectively unreachable in the overshoot path (lines 230290 jump past the subroutine’s NEXT y only after CLS : RUN).
  • Subroutine flow inconsistency: The win path (line 220) calls GO SUB 300, which contains NEXT y and loops correctly. The penalty path (lines 230290) also calls GO SUB 300 at line 260, but then executes PAUSE 120, CLS, and RUN after 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

Related Products

Related Articles

Related Content

Image Gallery

Golf

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.

People

No people associated with this content.

Scroll to Top