This program implements a simplified dice game where the player bets on whether two rolled dice will total under 7, equal 7, or over 7. The player starts with a stake of $50 and wagers between $1 and $6 per round. A “7” bet pays 4-to-1 (net gain of 4× the wager), while under/over bets pay even money; a roll of 7 wipes out under/over bets, and a non-7 wipes out a “7” bet. The game ends automatically when the stake drops below $1 or the player presses “S” to stop. Lines 340–360 form a loader stub that clears memory, saves the program with an auto-run flag, and then runs it.
Program Analysis
Program Structure
The program is organised into a main loop and a single subroutine:
- Initialisation (line 20): Sets the starting stake
Mto 50. - Bet entry (lines 30–70): Displays the current stake via
GOSUB 320, prints the betting options, and accepts a choice inA$. - Amount entry (lines 90–120): Prompts for a wager
Ain the range 1–6, looping back on invalid input. - Dice roll (lines 130–180): Generates two random dice values
BandC, prints them along with their sumD. - Win/loss calculation (lines 190–230): Four conditional assignments determine winnings
W, then updates the stake. - Result display and loop (lines 240–310): Prints outcome, refreshes the stake display, delays with a
FORloop, checks for bankruptcy, clears the screen, and repeats. - Stake subroutine (lines 320–330): Prints the current stake at a fixed screen position and returns.
- Loader stub (lines 340–360):
CLEAR,SAVEwith auto-run, andRUN— never reached during normal play.
Betting Logic
The payout structure is encoded across lines 190–220:
| Condition | Net change to stake (W) |
|---|---|
D=7 and bet "B" | +4*A (4-to-1 payout) |
D<7 and bet "A" | +A (even money) |
D>7 and bet "C" | +A (even money) |
| Incorrect guess (any) | -A |
Note that line 220 uses a compound boolean expression to catch all losing scenarios in a single statement, covering both “7” bets that didn’t land on 7 and under/over bets that landed exactly on 7.
Key BASIC Idioms
- Dice simulation:
INT(RND*6)+1produces a uniform integer in the range 1–6, applied twice for two independent dice. - Input validation loop: Line 110 uses
IF A<1 OR A>6 THEN GOTO 100to re-prompt without a structured loop construct. - Soft delay: Lines 270–280 use a
FOR/NEXTloop with no body as a timing delay — a classic technique on machines without a reliablePAUSEin all contexts. - Trailing spaces in PRINT: Line 320 appends
" "after printing the stake value to erase any leftover wider digits from a previous display.
Bugs and Anomalies
- Uninitialised
W: IfA$is neither"A","B", nor"C"(for example an accidental keypress), none of lines 190–220 will setW, so the previous round’s value persists and corrupts the stake. There is no explicit initialisation ofWat the top of the loop. - Line 80 exit only before betting: The “S to stop” check occurs only at bet-selection time; there is no escape during amount entry or after a round.
- Stake display on first run:
GOSUB 320at line 30 is called before any bet or win/loss, soMis displayed correctly from the start — this is intentional and correct. - Loader stub unreachable: Lines 340–360 cannot be reached through normal
GOTO/GOSUBflow; they exist solely to be executed manually or as part of a distribution workflow.
Content
Source Code
20 LET M=50
30 GOSUB 320
40 PRINT AT 4,3;"PLACE YOUR BET"
50 PRINT AT 10,0;"(A) UNDER 7 (B) 7 (C) OVER 7"
60 PRINT AT 11,5;"EVEN 5 FOR 1 EVEN"
70 INPUT A$
80 IF A$="S" THEN STOP
90 PRINT AT 16,10;"AMOUNT ?"
100 INPUT A
110 IF A<1 OR A>6 THEN GOTO 100
120 PRINT AT 16,10;" OK $";A
130 LET B=INT (RND*6)+1
140 PRINT AT 13,3;B;TAB 10;
150 LET C=INT (RND*6)+1
160 PRINT C;TAB 6;
170 LET D=C+B
180 PRINT D
190 IF D=7 AND A$="B" THEN LET W=4*A
200 IF D<7 AND A$="A" THEN LET W=A
210 IF D>7 AND A$="C" THEN LET W=A
220 IF ((A$="A" OR A$="C") AND D=7) OR (A$="B" AND D<>7) THEN LET W=-A
230 LET M=M+W
240 IF W>0 THEN PRINT AT 16,4;"YOU WIN $";W
250 IF W<0 THEN PRINT AT 16,4;"YOU LOSE $";-W
260 GOSUB 320
270 FOR N=1 TO 60
280 NEXT N
290 IF M<1 THEN STOP
300 CLS
310 GOTO 30
320 PRINT AT 2,12;"STAKE $";M;" "
330 RETURN
340 CLEAR
350 SAVE "1029%3"
360 RUN
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
