--- title: "Slot Machine" id: 57264 type: "computer_media" slug: "slot-machine-2" url: "http://localhost/computer_media/slot-machine-2/" markdown_url: "http://localhost/computer_media/slot-machine-2.md" published_at: "2024-10-04T07:48:19+00:00" modified_at: "2026-03-30T21:18:52+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2024/10/152_Slot.png" excerpt: "A one-armed bandit built from block graphics and clever arithmetic constants — spin the reels and gamble between $1 and $5 per pull." 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 1000" slug: "ts1000" taxonomy: "post_tag" url: "http://localhost/tag/ts1000/" model: - name: "Timex/Sinclair 1000" slug: "ts-1000" taxonomy: "model" url: "http://localhost/model/ts-1000/" genre: - name: "Gambling" slug: "gambling" taxonomy: "genre" url: "http://localhost/type/gambling/" - name: "Game" slug: "game" taxonomy: "genre" url: "http://localhost/type/game/" media_contents: - id: 56734 title: "Timex Sinclair Public Domain Library Tape 1003" type: "computer_media" url: "http://localhost/computer_media/timex-sinclair-public-domain-library-tape-1003/" media_type: "Program" mediadate: "198x" images: - url: "http://localhost/wp-content/uploads/2024/10/152_Slot.png" media_type_tags: "Gambling, Game" --- This program implements a text-based slot machine game using block graphics characters to draw the reels. The player bets between $1 and $5 per spin, with winnings multiplied by a payout factor that depends on which symbols align. Two constants, E=2 and F=3, are used throughout as arithmetic building blocks to encode key values (e.g., E-E=0, F-E=1, E+F=5, D=20, D*D=400, D+D=40) rather than using those literals directly. The slot reel subroutine at line 400 picks a random value from 0–4, loops briefly (possibly for a spin animation delay), then prints a block-graphic character using CHR$(128+A*2). Payout logic awards a multiplier of 2 for a partial match involving symbol 3, 5 for three-of-a-kind with symbol 3, and 20 for any other three-of-a-kind. *** ## Program Analysis ### Program Structure The program is organized into three logical sections: 1. **Initialization (lines 1–45):** Sets up constants, displays title, randomizes, shows a lucky/unlucky message, and initializes the money variable. 2. **Main game loop (lines 50–320):** Prompts for a bet, draws the slot machine frame, calls the reel subroutine three times, evaluates the result, and applies winnings. 3. **Reel subroutine (lines 400–440):** Picks a random symbol, performs a short FOR loop (possibly for timing), and prints a block graphic character. ### Constant Encoding with E and F Rather than using numeric literals, the program defines `E=2` and `F=3` at lines 5–10 and then builds all needed values from arithmetic on these two constants. This is a well-known memory-saving idiom on Sinclair machines, where storing a small integer in a variable and reusing it can be more compact than repeating multi-digit numeric tokens. | Expression | Value | Used for | | --- | --- | --- | | `E-E` | 0 | Zero / AT row 0 / loop start | | `F-E` | 1 | Minimum bet check, condition threshold | | `E` | 2 | Column offset, multiplier in CHR$ calculation | | `F` | 3 | Symbol number for special payout | | `E+F` | 5 | Maximum bet | | `D` | 20 | Line number target, maximum payout multiplier | | `D*F` | 60 | GOTO target for invalid bet (line 60 = INPUT) | | `D*D` | 400 | GOSUB target = reel subroutine | | `D/E` | 10 | TAB column for third reel | | `D+D` | 40 | GOTO target line 40 (start of next round) | ### Slot Machine Frame Lines 80–130 draw a simple three-reel frame using block graphic characters. Line 80 uses `\''\''\''` sequences (▀ top-half block) for the top border of each reel, and line 100 uses `\..\..\..)` sequences (▄ bottom-half block) for the bottom border. The middle row (line 90) is blank spaces padded with `%` column separators, leaving room for the reel symbols to be printed by the subroutine calls. ### Reel Subroutine (Lines 400–440) The subroutine at line 400 generates a random integer `A` in the range 0–4 via `INT(RND*(E*F))` — i.e., `INT(RND*6)`, giving values 0–5, though only 0–4 are meaningful given the five block graphic characters starting at CHR$(128). The `FOR Z=0 TO 15` loop at lines 410–420 introduces a brief delay to simulate spinning. Line 430 prints `CHR$(128+A*2)`, selecting every other block graphic from the set at character codes 128, 130, 132, 134, 136. ### Payout Logic Lines 250–310 handle the win condition and payout multiplier: - If `X` (first reel) is not symbol 3 (`F`), AND not all three reels match, the game jumps to line 20 (next round, no win). - Default multiplier `C=2` (line 270) — a partial win when `X=3`. - If the second reel `Y=3`, multiplier becomes `C=5` (line 280). - If all three reels match (`X=Y=Z`), multiplier becomes `C=20` (line 290). - Winnings paid = `C*B` added to running total `M`. ### Notable Bugs and Anomalies - **Win condition logic (line 250):** The condition `IF X<>F THEN IF X<>Y OR X<>Z THEN GOTO D` is ambiguous. It skips the win if X is not 3 AND (X≠Y or X≠Z), meaning a non-symbol-3 three-of-a-kind can still reach the win block only if X=Y=Z, but the inner OR makes it hard to win with other symbols. In practice, any non-3 three-of-a-kind slips through because both conditions are false when X=Y=Z. - **RND range (line 400):**`INT(RND*(E*F))` = `INT(RND*6)` can produce 0–5, giving six possible values, but the payout code only specially handles symbol `F=3`. Symbol 5 would display `CHR$(138)` and could still match for the generic three-of-a-kind payout. - **TAB column line 170:**`PRINT TAB E*F;` = `TAB 6` for the second reel position. Combined with the AT on line 140 (`AT F-E,E` = AT 1,2), this sequences the three reel outputs horizontally across row 1. - **Line 460 `RUN`:** After SAVE, a bare `RUN` restarts the program, which is normal for a SAVE/autostart pattern. ## Source Code ``` 1 PRINT AT 0,14;"SLOT MACHINE" 5 LET E=2 10 LET F=3 15 LET M=E-E 20 RAND 25 LET D=RND*E 30 IF D>=F-E THEN PRINT "TRY YOUR LUCK" 35 IF DE+F THEN GOTO D*F 80 PRINT AT E-E,E-E;"% \''\''\''% \''\''\''% \''\''\''% " 90 PRINT "% % % % " 100 PRINT "% \..\..\..% \..\..\..% \..\..\..% " 110 PRINT " " 120 PRINT " " 130 PRINT " " 140 PRINT AT F-E,E; 150 GOSUB D*D 160 LET X=A 170 PRINT TAB E*F; 180 GOSUB D*D 190 LET Y=A 200 PRINT TAB D/E; 210 GOSUB D*D 220 LET Z=A 230 PRINT AT F,E-E; 240 LET M=M-B 250 IF X<>F THEN IF X<>Y OR X<>Z THEN GOTO D 260 PRINT "YOU WIN $"; 270 LET C=E 280 IF Y=F THEN LET C=E+F 290 IF X=Y AND X=Z THEN LET C=D 300 LET M=M+C*B 310 PRINT C*B 320 GOTO D+D 400 LET A=INT (RND*(E*F)) 410 FOR Z=E-E TO 15 420 NEXT Z 430 PRINT CHR$ (128+A*E); 440 RETURN 450 SAVE "1015%2" 460 RUN ```