--- title: "Golf" id: 53797 type: "computer_media" slug: "golf" url: "http://localhost/computer_media/golf/" markdown_url: "http://localhost/computer_media/golf.md" published_at: "2024-05-13T18:56:52+00:00" modified_at: "2026-03-30T21:42:51+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2019/02/20230809-041332.jpg" excerpt: "A nine-hole text golf game where you pick swing power and random physics determine whether you sink the putt or suffer a two-stroke penalty." category: - name: "Archived Media" slug: "archived-media" taxonomy: "category" url: "http://localhost/category/archived-media/" post_tag: - name: "Downloadable" slug: "downloadable" taxonomy: "post_tag" url: "http://localhost/tag/downloadable/" - name: "TS 2068" slug: "ts2068" taxonomy: "post_tag" url: "http://localhost/tag/ts2068/" model: - name: "Timex/Sinclair 2068" slug: "ts-2068" taxonomy: "model" url: "http://localhost/model/ts-2068/" genre: - name: "Game" slug: "game" taxonomy: "genre" url: "http://localhost/type/game/" media_contents: - id: 53877 title: "SINCUS Exchange Tape 101 – Entertainment" type: "computer_media" url: "http://localhost/computer_media/sincus-exchange-tape-101-entertainment/" media_type: "Program" images: - url: "http://localhost/wp-content/uploads/2024/05/golf-sincus-101.png" media_type_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 `10`–`40`: Initialization — border color, clear screen, reset total strokes, print title. 2. Lines `50`–`70`: Per-hole setup — randomize hole position `j`, reset stroke counter `s`. 3. Lines `80`–`260`: Shot loop — draw course, accept input, compute new ball position, check win/overshoot conditions. 4. Lines `300`–`320`: Score subroutine — accumulate total `t`, print it, advance `NEXT y`. 5. Lines `330`–`350`: 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 | 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 `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 `330`–`350` poll `INKEY$` continuously without a `PAUSE`, which keeps the CPU busy-waiting for a keypress. ### Bugs and Anomalies - **Broken game loop via `RUN`:** Lines `280`–`290` 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 `230`–`290` 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 `230`–`290`) 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. ## 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 ```