Slots is a one-player slot machine game that gives the player $100 and allows bets of up to $5 per spin. The program uses GOSUB-based dispatch to draw a detailed slot machine cabinet using block graphics characters, then spins three reels by calling a random-number subroutine that selects from six symbols encoded as characters starting at CHR$(128). Payoffs are calculated by comparing the three reel results: two of a kind pays 2:1, two matching pays 3:1 scaled by symbol, and three of a kind pays 20:1. The program switches between FAST and SLOW modes to balance drawing speed with display visibility, and uses arithmetic expressions such as GOSUB D*D and GOTO D+D as computed line-number targets rather than literal constants.
Program Analysis
Program Structure
The program is organized into several distinct regions:
- Lines 1–5: REMs, initialization of variable
E=2, and entry point dispatch viaGOSUB 2000. - Lines 10–65: Main game loop — sets up constants, randomizes, displays status, accepts a bet.
- Lines 70–320: Slot machine draw and spin logic, win detection, and payout.
- Lines 400–440: Reel symbol subroutine — picks a random symbol, pauses in a loop, prints it.
- Lines 450–470: Game-over (bankrupt) handler.
- Lines 1000–1170: Cabinet drawing subroutine using block graphics.
- Lines 2000–2110: Introduction/instructions screen with a timed PAUSE.
- Line 3000–3010: SAVE and restart utility.
- Lines 4010–4110: Animated lever/arm subroutine drawn at column
P=25.
Key Variables and Constants
| Variable | Value / Role |
|---|---|
E | 2 — used as a constant throughout to avoid literal 2s |
F | 3 — used as a constant for comparisons and arithmetic |
D | Set to 20 at line 40; used in computed GOSUB/GOTO targets |
M | Player’s current money, starts at 100 |
B | Current bet (1–5) |
X, Y, Z | Results of the three reel spins |
A | Symbol index returned by reel subroutine (lines 400–440) |
C | Multiplier used in payout calculation |
Computed GOSUB and GOTO Targets
A distinctive idiom used throughout is arithmetic in branch targets. At line 150, GOSUB D*D evaluates to GOSUB 400 (since D=20), jumping to the reel subroutine. Lines 180 and 210 repeat this for the second and third reels. At line 250, GOTO D (value 20) loops back to the top of the game cycle. At line 320, GOTO D+D evaluates to GOTO 40, resuming the main loop after a win. This technique reduces memory slightly compared to literal line numbers and doubles as a mild form of self-documentation through arithmetic.
Reel Symbol Generation (Lines 400–440)
The reel subroutine picks a symbol index A = INT(RND * (E*F)), which resolves to a random integer from 0 to 5 (six possible symbols). A short FOR loop from E-E (i.e., 0) to 65 acts as a delay — a spin animation pause. The symbol is printed as CHR$(128 + A*E), stepping through even-numbered positions in the UDG/block graphic range starting at character 128, selecting every other character to space the symbol set.
Win Detection Logic (Lines 250–310)
Win detection at line 250 uses a compound conditional: IF X<>F THEN IF X<>Y OR X<>Z THEN GOTO D. This checks if neither a specific symbol (F=3, treated as a “lucky” reel value used in determining multiplier) nor a pair/trio match exists. The payout multiplier C is set progressively: starting at E=2 (two of a kind), raised to F=3 if the middle reel also matches the lucky symbol, and raised to D=20 if all three reels match — giving the advertised 2:1, ~3:1, and 20:1 payouts respectively.
Cabinet and Lever Graphics (Lines 1000–1170, 4010–4110)
The slot machine cabinet is drawn entirely with block graphic characters using PRINT AT positioning. Lines 1000–1170 draw the outer frame, switching to FAST mode for speed then back to SLOW. The lever animation in lines 4010–4110 simulates a handle pull by iterating column P=25 downward then upward with ▐█ and ▌ characters, creating a two-pass animation of the arm swinging down and returning.
Bugs and Anomalies
- At line 250, the condition
IF X<>Y OR X<>Zis logically weak: it will be true unless bothYandZequalX, meaning any non-matching pair still skips the win branch correctly for three-of-a-kind, but the two-of-a-kind detection path through lines 270–280 relies solely on whether a reel result equalsFrather than comparing reel values directly to each other, so the “2 of a kind” payout is specifically tied to symbol index 3 appearing, not to any two reels matching arbitrarily. - Variable
Zis reused: it stores the third reel result (line 220) but is also used as the loop variable in the delay loop at lines 410–420. Since the delay loop runs inside the reel subroutine called for the third reel last,Zwill be overwritten with the loop’s final value (65) rather than the reel symbol. The win comparison at line 250 involvingZwill therefore always compare against 65, not the actual third reel symbol, which is a genuine bug affecting three-of-a-kind detection for the third reel. - The introduction screen (lines 2060–2080) advertises “▚– PAYS 2 TO 1” and “▚ ▚- PAYS 5 TO 1”, but the actual payout logic gives multipliers of 2 and 3, not 5, for partial matches.
Content
Image Gallery
Source Code
1 REM SLOTS
2 REM BY WESLEY WEEKS
3 REM COPYRIGHT 1982
4 GOSUB 2000
5 LET E=2
6 SLOW
10 LET F=3
15 LET M=100
20 RAND
25 LET D=RND*E
26 PRINT
30 IF D>=F-E THEN PRINT TAB 9;"TRY YOUR LUCK"
35 IF D<F-E THEN PRINT TAB 9;"PAY ME TO WIN"
40 LET D=20
45 PRINT TAB 9;"NOW AT$";M
46 IF M<=0 THEN GOTO 450
50 PRINT TAB 9;"BET UP TO $5"
60 INPUT B
65 IF B>5 THEN GOTO 60
70 CLS
75 GOSUB 1000
80 PRINT AT 8,9;"▒~~~~~~▒~~~~~~▒~~~~~~▒"
90 PRINT AT 9,9;"▒ ▒ ▒ ▒"
100 PRINT AT 10,9;"▒,,,,,,▒,,,,,,▒,,,,,,▒"
110 GOSUB 4010
140 PRINT AT 9,11;
150 GOSUB D*D
160 LET X=A
170 PRINT AT 9,15;
180 GOSUB D*D
190 LET Y=A
200 PRINT AT 9,19;
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 ,,TAB 9;"YOU WIN $";
270 LET C=E
280 IF Y=F THEN LET C=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 65
420 NEXT Z
430 PRINT CHR$ (128+A*E);
440 RETURN
450 CLS
460 PRINT AT 10,10;"YOU LOSE"
470 STOP
1000 FAST
1010 PRINT AT 2,7;"▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄"
1020 FOR J=3 TO 7
1030 PRINT AT J,7;"▌"
1040 PRINT AT J,23;"▐"
1050 NEXT J
1060 FOR J=8 TO 15
1070 PRINT AT J,6;"▐"
1080 PRINT AT J,24;"▌"
1090 NEXT J
1100 PRINT AT 16,5;"▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀"
1110 PRINT AT 11,25;"█";AT 12,25;"█"
1120 PRINT AT 11,24;"█";AT 12,24;"█"
1130 FOR J=4 TO 12
1140 PRINT AT J,26;"▌"
1150 NEXT J
1160 PRINT AT 3,26;"█";AT 3,25;"▐"
1165 SLOW
1170 RETURN
2000 PRINT " SLOTS"
2010 PRINT
2020 PRINT "IS A SLOT MACHINE GAME FOR 1."
2030 PRINT "YOU HAVE 100 DOLLARS CASH AND "
2040 PRINT "YOU MAY BET UP TO $5 EACH TIME."
2050 PRINT "THE PAYOFF IS AS FOLLOWS:"
2060 PRINT ,,"▚-- PAYS 2 TO 1"
2070 PRINT ,,"▚ ▚- PAYS 5 TO 1"
2080 PRINT ,,"3 OF A KIND PAYS 20 TO 1"
2090 PAUSE 1200
2100 CLS
2110 RETURN
3000 SAVE "SLOT[S]"
3010 GOTO 1
4010 LET P=25
4015 FOR W=3 TO 8
4020 PRINT AT W-1,P;" "
4030 PRINT AT W,P;"▐█"
4035 PRINT AT W+1,P;" ▌"
4050 NEXT W
4060 FOR W=8 TO 3 STEP -1
4070 PRINT AT W+1,P;" ▌"
4080 PRINT AT W,P;"▐█"
4090 PRINT AT W+1,P;" ▌"
4100 NEXT W
4110 RETURN
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.