This program implements a full five-card draw poker game for one human player against the computer. The computer uses a randomized betting strategy tied to hand-strength variables, supports folding, checking, raising, and a mid-game pawning mechanic where players can sell a watch or tie tack when funds run low. Hand evaluation is performed entirely in BASIC using sorting and pattern-matching on a five-element array, with hand types encoded as integers (e.g., 11111 for a straight or flush, 11 for a pair). The animated title screen uses 13 custom UDG characters loaded via a DATA/POKE loop at subroutine 9000, composing a large “POKER” logo from block-graphic tiles with randomized INK colors and BORDER flashing.
Program Analysis
Program Structure
The program is organized into several functional regions:
- Lines 5–85: Initialization, animated UDG title screen, and introductory messages.
- Lines 90–130: Game-state setup (player/computer stacks, pot, ante).
- Lines 140–640: Main game loop — dealing, printing hands, pre-draw computer betting.
- Lines 650–810: Fold/win resolution subroutine.
- Lines 820–1460: Draw phase and post-draw betting.
- Lines 1460–1720: Hand comparison and pot award.
- Lines 1730–1840: Card-dealing subroutine (unique card generation).
- Lines 1850–2160: Hand-display subroutines (rank and suit symbols).
- Lines 2170–3040: Hand-evaluation engine (sort, classify, assign strength).
- Lines 3050–3470: Player/computer betting input and raise logic.
- Lines 3480–3660: Computer funds check and pawn-item recovery.
- Lines 3670–4130: Bust/end-game handling, play-again prompt.
- Lines 9000–9170: UDG loader subroutine, called once at startup.
- Lines 9998–9999: SAVE/VERIFY utility.
Card Representation
Each card is stored as a three-digit integer in array a(). The hundreds digit encodes the suit (0–3), and the units/tens digits encode the rank (0–12, representing 2 through Ace). The helper function FN b(x) extracts the rank via x-100*INT(x/100), a common modulo-100 idiom. The suit is recovered with INT(a(z)/100). Card uniqueness is enforced at lines 1770–1790 by comparing each newly generated card against all previously dealt cards.
Hand Evaluation Engine
The evaluation routine beginning at line 2170 is the computational core of the program. It works as follows:
- Counts matching suits to detect flushes (
u=15if all five match). - Performs a bubble sort on rank values (lines 2310–2400) to enable sequential comparison.
- Scans adjacent pairs to build the variable
x, an integer whose digits (base-10 positional) flag matching ranks; each pair match adds11*10^(z-n). - Checks for straights by verifying that
b(n)+3=b(n+3)andb(n+1)+3=b(n+4). - Classifies pair, two-pair, three-of-a-kind, full house, and four-of-a-kind using the value of
xand context checks in the subroutine starting at line 2760.
Hand strength is encoded in the integer variable u:
| Value of u | Hand |
|---|---|
| 9 | High card (“schmaltz”) |
| 10 | Straight (partial) / low straight indicator |
| 11 | One pair |
| 12 | Two pair |
| 13 | Three of a kind |
| 14 | Straight |
| 15 | Flush |
| 16 | Full house |
| 17 | Four of a kind |
Computer Betting Strategy
The computer’s betting decisions are driven by u (hand strength) combined with FN a(0) (a random 1–10 roll) to introduce bluffing. Before the draw, if the computer has a strong hand (i=7), it always bets; otherwise it may check or bet small amounts. The variable z serves as a base bet amount that is randomized by adding FN a(0). After the draw, strategy thresholds are adjusted: a weak hand (i=6, nothing improved) causes the computer to check or fold; strong hands trigger larger raises via z=28.
UDG Title Screen
Subroutine 9000 defines 13 custom UDGs (\a through \m) by POKEing bitmaps read from DATA statements into the UDG memory area via POKE USR a$+m, any. The title at line 40 uses a large PRINT AT string that assembles these UDGs with block graphics to render a decorative “POKER” logo. The display loop at lines 38–42 redraws it 14 times with randomized INK and BORDER colors, creating a color-cycling animation effect accompanied by random BEEP tones.
Pawn Shop Mechanic
When either player cannot cover a bet, subroutines at lines 3830 and 3480 offer the human player the chance to sell a watch (for $25 or $75, randomly determined) or a diamond tie tack (for $25 or $100). The variable o tracks ownership: it starts at 1 and is multiplied by 2 when the watch is sold (or divided by 2 when bought back), and multiplied/divided by 3 for the tie tack. Divisibility tests (o/2=INT(o/2)) determine which items remain available.
Key BASIC Idioms
DEF FN a(x)=INT(10*RND+(1))— one-liner random integer 1–10; the argumentxis unused, allowing calls likeFN a(0)as a parameterless random roll.VAL "number"style is not used here, butGO SUB 3050/GO SUB 3060on consecutive lines allow the same subroutine to be entered either resettingg=0(line 3050) or skipping that step (line 3060).- Hand description strings are split across
h$andi$to fit within string variable constraints while still composing readable output (e.g.,"a flus"+"h in","straig"+"ht"). - The
b()array (15 elements) stores sorted rank values for the current hand being evaluated, overlapping with the player hand at indices 1–5 and computer hand at 6–10.
Anomalies and Notable Observations
- Line 400 uses
IF FN a(0)>=1 THEN GO TO 450, which is always true (sinceFN a(0)returns 1–10), makingLET x=11111at line 410 dead code in that branch. - Lines 3250–3280 contain a redundant check:
IF z>=2 THEN GO TO 3350immediately after settingz=1can never be true, makingLET v=5at line 3280 unreachable. - Line 1655 compares
h$=j$(current hand descriptor vs. saved copy) to detect a tie; sincej$was just assigned fromh$at line 1480, this is always true when both players have the same hand type, correctly routing to tiebreaker logic. - The
BEEPsound subroutine at line 80 is reused with differentbandmparameters (loop count and pitch offset) to produce varied sound effects for different introductory screens.
Content
Source Code
5 CLS : BEEP .15,20: BORDER 6
10 DIM a(50): DIM b(15)
20 DEF FN a(x)=INT (10*RND+(1))
30 DEF FN b(x)=x-100*INT (x/100)
35 GO SUB 9000
38 FOR n=14 TO 1 STEP -1: CLS
39 INK RND*6
40 PRINT AT n,0;" \::\::\::\::\i \j\::\::\::\i \:: \f\h \::\::\::\::\:: \::\::\::\::\i \:: \:: \:: \:: \:: \f\h \:: \:: \:: \:: \:: \:: \:: \::\f\h \:: \:: \:: \::\::\::\::\k \:: \:: \::\m \::\::\::\:: \::\::\::\::\k \:: \:: \:: \::\g\e \:: \::\g\e \:: \:: \:: \:: \g\e \:: \:: \g\e \:: \l\::\::\::\k \:: \g\e \::\::\::\::\:: \:: \g\e"
42 BEEP .01,RND*50: BORDER RND*7: NEXT n
45 LET b=30: LET m=10: GO SUB 80
46 INK 0
48 PRINT : PRINT "Welcome to the casino.We each have $200."
49 GO SUB 80
50 PRINT : PRINT "I will open the betting before the draw.You open after."
55 LET b=20: LET m=20: GO SUB 80
60 PRINT : PRINT "When you fold,bet 0; to check,bet .5 ."
65 LET b=10: LET m=30: GO SUB 80
70 PRINT : PRINT "Enough talk--let's get down to business."
75 GO TO 85
80 FOR n=1 TO b: BORDER RND*7: BEEP .05,RND*60-m: NEXT n: RETURN
85 FOR n=1 TO 300: NEXT n: CLS : BORDER 6
90 LET o=1
95 FOR n=1 TO 100: NEXT n
100 LET c=200: LET s=200
110 LET g=0
120 LET p=0
130 RANDOMIZE
140 PRINT
150 IF c<=5 THEN GO TO 3670
160 PRINT "The ante is $5. I will deal."
164 BEEP .02,50
165 PRINT : PRINT "I am shuffling the deck."
170 PRINT
180 IF s>5 THEN GO TO 200
190 GO SUB 3830
200 LET p=p+10
210 LET s=s-5
220 LET c=c-5
230 FOR z=1 TO 10
240 GO SUB 1740
250 NEXT z
260 CLS
265 PRINT "Your hand:"
270 LET n=1
280 GO SUB 1850
290 LET n=6
300 LET i=2
310 GO SUB 2170
320 PRINT
330 IF i<>6 THEN GO TO 470
340 IF FN a(0)<=7 THEN GO TO 370
350 LET x=11100
360 GO TO 420
370 IF FN a(0)<=7 THEN GO TO 400
380 LET x=11110
390 GO TO 420
400 IF FN a(0)>=1 THEN GO TO 450
410 LET x=11111
420 LET i=7
430 LET z=23
440 GO TO 580
450 LET z=1
460 GO TO 510
470 IF u>=13 THEN GO TO 540
480 IF FN a(0)>=2 THEN GO TO 500
490 GO TO 420
500 LET z=0
510 LET k=0
520 PRINT "I check"
525 BEEP .05,30
530 GO TO 620
540 IF u<=16 THEN GO TO 570
550 LET z=2
560 IF FN a(0)>=1 THEN GO TO 580
570 LET z=35
580 LET v=z+FN a(0)
590 GO SUB 3480
600 PRINT "I'll open with ";v
610 LET k=v
620 GO SUB 3050
630 GO SUB 650
640 GO TO 820
650 IF i<>3 THEN GO TO 760
660 PRINT
670 PRINT "I win"
675 BEEP .05,10: BEEP .05,10
680 LET c=c+p
690 PRINT "I have $";c;" and you have $";s
700 PRINT "Do you wish to continue?"
710 LET h$=INKEY$
720 IF h$="y" THEN CLS : GO TO 120
730 IF h$="n" THEN FOR n=1 TO 30: NEXT n: GO TO 4100
750 GO TO 710
760 IF i<>4 THEN GO TO 810
770 PRINT
780 PRINT "You win"
785 BEEP .05,30: BEEP .05,30
790 LET s=s+p
800 GO TO 690
810 RETURN
820 PRINT
830 PRINT "Now we draw--how many cards do you want?"
840 INPUT t
845 BEEP .05,45
850 IF t=0 THEN GO TO 980
860 LET z=10
870 IF t<4 THEN GO TO 900
880 PRINT "You can't draw more than three cards."
890 GO TO 840
900 PRINT "Enter their numbers one at a time"
910 FOR q=1 TO t
920 INPUT u
925 BEEP .05,30
930 GO SUB 1730
940 NEXT q
950 CLS
955 PRINT "Your new hand:"
960 LET n=1
970 GO SUB 1850
980 LET z=10+t
990 FOR u=6 TO 10
1000 IF INT (x/10^(u-6))<>10*INT (x/10^(u-5)) THEN GO TO 1020
1010 GO SUB 1730
1020 NEXT u
1030 PRINT
1040 PRINT "I am taking ";z-10-t;" card";
1050 IF z=11+t THEN GO TO 1090
1060 PRINT "s"
1070 PRINT
1080 GO TO 1100
1090 PRINT
1100 LET n=6: LET v=i: LET i=1
1130 GO SUB 2170
1140 LET b=u
1150 LET m=d
1160 IF v<>7 THEN GO TO 1190
1170 LET z=28
1180 GO TO 1330
1190 IF i<>6 THEN GO TO 1220
1200 LET z=1
1210 GO TO 1330
1220 IF u>=13 THEN GO TO 1270
1230 LET z=2
1240 IF FN a(0)<>6 THEN GO TO 1260
1250 LET z=19
1260 GO TO 1330
1270 IF u>=16 THEN GO TO 1320
1280 LET z=19
1290 IF FN a(0)<>8 THEN GO TO 1310
1300 LET z=11
1310 GO TO 1330
1320 LET z=2
1330 LET k=0
1340 GO SUB 3050
1350 IF t<>.5 THEN GO TO 1450
1360 IF v=7 THEN GO TO 1400
1370 IF i<>6 THEN GO TO 1400
1380 PRINT "I'll check"
1390 GO TO 1460
1400 LET v=z+FN a(0)
1410 GO SUB 3480
1420 PRINT "I'll bet";v
1430 LET k=v
1440 GO SUB 3060
1450 GO SUB 650
1460 PRINT
1470 PRINT "Now we compare hands"
1480 LET j$=h$
1490 LET k$=i$
1500 PRINT "My hand:"
1510 LET n=6
1520 GO SUB 1850
1530 LET n=1
1540 GO SUB 2170
1550 PRINT
1560 PRINT "You have ";
1570 LET k=d
1580 GO SUB 3690
1590 LET h$=j$
1600 LET i$=k$
1610 LET k=m
1620 PRINT "and I have ";
1630 GO SUB 3690
1640 IF b>u THEN GO TO 670
1650 IF u>b THEN GO TO 780
1655 IF h$=j$ THEN GO TO 1700
1660 IF h$="a flus" THEN GO TO 1700
1670 PRINT "The hand is drawn"
1680 PRINT "All $";p;" remain in the pot"
1690 GO TO 140
1700 IF FN b(m)>FN b(d) THEN GO TO 670
1710 IF FN b(d)>FN b(m) THEN GO TO 780
1720 GO TO 1670
1730 LET z=z+1
1740 LET a(z)=INT (1000*RND+(1))
1750 IF INT (a(z)/100)>3 THEN GO TO 1740
1760 IF a(z)-100*INT (a(z)/100)>12 THEN GO TO 1740
1765 IF z=1 THEN GO TO 1800
1770 FOR k=1 TO z-1
1780 IF a(z)=a(k) THEN GO TO 1740
1790 NEXT k
1800 IF z<=10 THEN GO TO 1840
1810 LET n=a(u)
1820 LET a(u)=a(z)
1830 LET a(z)=n
1840 RETURN
1850 FOR z=n TO n+4
1860 PRINT z;"-- ";
1866 BEEP .05,45
1870 GO SUB 1950
1880 PRINT " of";
1890 GO SUB 2070
1900 IF z/2<>INT (z/2) THEN GO TO 1920
1910 PRINT
1920 NEXT z
1930 PRINT
1940 RETURN
1950 LET k=FN b(a(z))
1960 IF k<>9 THEN GO TO 1980
1970 PRINT "Jack";
1980 IF k<>10 THEN GO TO 2000
1990 PRINT "Queen";
2000 IF k<>11 THEN GO TO 2020
2010 PRINT "King";
2020 IF k<>12 THEN GO TO 2040
2030 PRINT "Ace";
2040 IF k>=9 THEN GO TO 2060
2050 PRINT k+2;
2060 RETURN
2070 LET k=INT (a(z)/100)
2080 IF k<>0 THEN GO TO 2100
2090 PRINT INK 4;" \d ",
2100 IF k<>1 THEN GO TO 2120
2110 PRINT " "; BRIGHT 1; INK 2;"\a"; BRIGHT 0;" ",
2120 IF k<>2 THEN GO TO 2140
2130 PRINT INK 2;" \b ",
2140 IF k<>3 THEN GO TO 2160
2150 PRINT " \c ",
2160 RETURN
2170 LET u=0
2180 FOR z=n TO n+4
2190 LET b(z)=FN b(a(z))
2200 IF z=n+4 THEN GO TO 2230
2210 IF INT (a(z)/100)<>INT (a(z+1)/100) THEN GO TO 2230
2220 LET u=u+1
2230 NEXT z
2240 IF u<>4 THEN GO TO 2310
2250 LET x=11111
2260 LET d=a(n)
2270 LET h$="a flus"
2280 LET i$="h in"
2290 LET u=15
2300 RETURN
2310 FOR z=n TO n+3
2320 FOR k=z+1 TO n+4
2330 IF b(z)<=b(k) THEN GO TO 2390
2340 LET x=a(z)
2350 LET a(z)=a(k)
2360 LET b(z)=b(k)
2370 LET a(k)=x
2380 LET b(k)=a(k)-100*INT (a(k)/100)
2390 NEXT k
2400 NEXT z
2410 LET x=0
2420 FOR z=n TO n+3
2430 IF b(z)<>b(z+1) THEN GO TO 2470
2440 LET x=x+11*10^(z-n)
2450 LET d=a(z)
2460 GO SUB 2760
2470 NEXT z
2480 IF x<>0 THEN GO TO 2620
2490 IF b(n)+3<>b(n+3) THEN GO TO 2520
2500 LET x=1111
2510 LET u=10
2520 IF b(n+1)+3<>b(n+4) THEN GO TO 2620
2530 IF u<>10 THEN GO TO 2600
2540 LET u=14
2550 LET h$="straig"
2560 LET i$="ht"
2570 LET x=11111
2580 LET d=a(n+4)
2590 RETURN
2600 LET u=10
2610 LET x=11110
2620 IF u>=10 THEN GO TO 2690
2630 LET d=a(n+4)
2640 LET h$="schmal"
2650 LET i$="tz, "
2660 LET u=9
2670 LET x=11000
2680 GO TO 2740
2690 IF u<>10 THEN GO TO 2720
2700 IF i=1 THEN GO TO 2740
2710 GO TO 2750
2720 IF u<>12 THEN GO TO 2750
2730 IF FN b(d)>6 THEN GO TO 2750
2740 LET i=6
2750 RETURN
2760 IF u>=11 THEN GO TO 2810
2770 LET u=11
2780 LET h$="a pair"
2790 LET i$=" of "
2800 RETURN
2810 IF u<>11 THEN GO TO 2910
2820 IF b(z)<>b(z-1) THEN GO TO 2870
2830 LET h$="three"
2840 LET i$=" "
2850 LET u=13
2860 RETURN
2870 LET h$="two p"
2880 LET i$="air, "
2890 LET u=12
2900 RETURN
2910 IF u<>12 THEN GO TO 2960
2920 LET u=16
2930 LET h$="full h"
2940 LET i$="ouse, "
2950 RETURN
2960 IF b(z)<>b(z-1) THEN GO TO 3010
2970 LET u=17
2980 LET h$="four"
2990 LET i$=" "
3000 RETURN
3010 LET u=16
3020 LET h$="full h"
3030 LET i$="ouse, "
3040 RETURN
3050 LET g=0
3060 PRINT "What is your bet ?"
3065 PRINT "(You have) ";s-g
3070 INPUT t
3075 BEEP .05,30
3080 IF t-INT (t)=0 THEN GO TO 3140
3090 IF k<>0 THEN GO TO 3120
3100 IF g<>0 THEN GO TO 3120
3110 IF t=.5 THEN GO TO 3410
3120 PRINT "No small change please."
3130 GO TO 3060
3140 IF s-g-t>=0 THEN GO TO 3170
3150 GO SUB 3830
3160 GO TO 3060
3170 IF t<>0 THEN GO TO 3200
3180 LET i=3
3190 GO TO 3380
3200 IF g+t>=k THEN GO TO 3230
3210 PRINT "If you can't see my bet, then fold"
3220 GO TO 3060
3230 LET g=g+t
3240 IF g=k THEN GO TO 3380
3250 IF z<>1 THEN GO TO 3420
3260 IF g>5 THEN GO TO 3300
3270 IF z>=2 THEN GO TO 3350
3280 LET v=5
3290 GO TO 3420
3300 IF z=1 THEN GO TO 3320
3310 IF t<=25 THEN GO TO 3350
3320 LET i=4
3330 PRINT "I fold"
3340 RETURN
3350 IF z=2 THEN GO TO 3430
3360 PRINT "I'll see you"
3370 LET k=g
3380 LET s=s-g
3390 LET c=c-k
3400 LET p=p+g+k
3410 RETURN
3420 IF g>3*z THEN GO TO 3350
3430 LET v=g-k+FN a(0)
3440 GO SUB 3480
3450 PRINT "I'll see you and raise you ";v
3460 LET k=g+v
3470 GO TO 3060
3480 IF c-g-v>=0 THEN GO TO 3660
3490 IF g<>0 THEN GO TO 3520
3500 LET v=c
3510 RETURN
3520 IF c-g>=0 THEN GO TO 3360
3530 IF o/2<>INT (o/2) THEN GO TO 3600
3540 PRINT "Would you like to buy back your watch for $50 ?"
3550 INPUT j$
3560 IF j$="n" THEN GO TO 3600
3570 LET c=c+50
3580 LET o=o/2
3590 RETURN
3600 IF o/3<>INT (o/3) THEN GO TO 3670
3610 PRINT "Would you like to buy back your tie for $50 ?"
3620 INPUT j$
3630 IF j$="n" THEN GO TO 3670
3640 LET c=c+50
3650 LET o=o/3
3660 RETURN
3670 PRINT "I'm busted. Congratulations"
3680 GO TO 4100
3690 PRINT h$;i$;
3700 IF h$<>"a flus" THEN GO TO 3750
3710 LET k=INT (k/100)
3720 GO SUB 2080
3730 PRINT
3740 RETURN
3750 LET k=FN b(k)
3760 GO SUB 1960
3770 IF h$="schmal" THEN GO TO 3790
3780 IF h$<>"straig" THEN GO TO 3810
3790 PRINT " high"
3800 RETURN
3810 PRINT "s"
3820 RETURN
3830 PRINT
3840 PRINT "You can't bet what you haven't got."
3850 IF o/2=INT (o/2) THEN GO TO 3970
3860 PRINT "Would you like to sell your watch ?"
3870 INPUT j$
3880 IF j$="n" THEN GO TO 3970
3890 IF FN a(o)>=7 THEN GO TO 3930
3900 PRINT "I'll give you $75 for it."
3910 LET s=s+75
3920 GO TO 3950
3930 PRINT "That's a pretty crummy watch - I'll give you $25"
3940 LET s=s+25
3950 LET o=o*2
3960 RETURN
3970 IF o/3=INT (o/3) THEN GO TO 4090
3980 PRINT "Will you part with that diamond tie tack ?"
3990 INPUT j$
4000 IF j$="n" THEN GO TO 4080
4010 IF FN a(0)>=6 THEN GO TO 4050
4020 PRINT "You are now $100 richer"
4030 LET s=s+100
4040 GO TO 4070
4050 PRINT "It's paste. $25"
4060 LET s=s+25
4070 LET o=o*3
4080 RETURN
4090 PRINT "Your wad is shot. So long sucker": FOR n=1 TO 100: NEXT n
4100 PRINT ; FLASH 1;" Would you like to play again ? "
4110 IF INKEY$="y" THEN RUN
4120 IF INKEY$="n" THEN STOP
4130 GO TO 4110
9000 FOR n=1 TO 13: READ a$
9010 FOR m=0 TO 7: READ any
9020 POKE USR a$+m,any
9030 NEXT m: NEXT n
9040 DATA "a",24,60,126,255,255,126,60,24
9050 DATA "b",102,255,255,255,255,126,60,24
9060 DATA "c",24,60,126,255,255,255,126,24
9070 DATA "d",60,60,219,255,255,219,24,24
9080 DATA "e",128,192,224,240,248,252,254,255
9090 DATA "f",1,3,7,15,31,63,127,255
9100 DATA "g",255,127,63,31,15,7,3,1
9110 DATA "h",255,254,252,248,240,224,192,128
9120 DATA "i",128,224,248,252,252,254,254,255
9130 DATA "j",1,7,31,63,63,127,127,255
9140 DATA "k",255,254,254,252,252,248,224,128
9150 DATA "l",255,127,127,63,63,31,7,1
9160 DATA "m",255,254,252,248,248,252,254,255
9170 RETURN
9998 CLEAR : SAVE "Poker" LINE 1: BEEP .4,15
9999 VERIFY ""
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

