--- title: "Poker Game" id: 56825 type: "computer_media" slug: "poker-game" url: "http://localhost/computer_media/poker-game/" markdown_url: "http://localhost/computer_media/poker-game.md" published_at: "2024-09-29T07:19:03+00:00" modified_at: "2026-04-03T07:58:50+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2024/09/314_PG.png" excerpt: "A complete five-card draw poker game with computer AI betting, bluffing, card replacement, and full hand evaluation from nothing up to royal flush." 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: "Card Game" slug: "card-game" taxonomy: "genre" url: "http://localhost/type/card-game/" - name: "Game" slug: "game" taxonomy: "genre" url: "http://localhost/type/game/" media_contents: - id: 56738 title: "Timex Sinclair Public Domain Library Tape 1007" type: "computer_media" url: "http://localhost/computer_media/timex-sinclair-public-domain-library-tape-1007/" media_type: "Program" mediadate: "198x" images: - url: "http://localhost/wp-content/uploads/2024/09/314_PG.png" media_type_tags: "Card Game, Game" --- This program implements a five-card draw poker game for one human player against a computer opponent. The deck is tracked using a 4×13 array S(4,13) representing suits and ranks, preventing duplicate cards from being dealt. Hand evaluation uses a dedicated subroutine at line 640 that detects pairs, two pair, three of a kind, straights, flushes, full house, four of a kind, straight flush, and royal flush, encoding hand strength as an integer value in T. The computer employs simple betting logic using random thresholds and the computed hand strength to decide whether to fold, call, or raise, and discards up to three cards during the draw phase. *** ## Program Analysis ### Program Structure The program is organised into a main game loop with clearly delineated phases and a set of subroutines. Execution flows through initialisation, deal, player draw, computer draw, betting rounds, showdown, and replay prompt before looping. 1. Lines 10–70: Array declarations — `T(13)` rank tally, `E(4)` suit tally, `S(4,13)` deck tracking, `M(5)`/`N(5)` player hand, `J(5)`/`F(5)` computer hand. 2. Lines 80–169: Title display, instructions, ante setup (`P9=100`, `A9=5`), deck reset, and deal trigger. 3. Lines 170–200: Deal five cards each to player and computer using subroutine 920. 4. Lines 201–284: Opening bet, player card replacement loop. 5. Lines 290–370: Hand evaluation and computer draw phase. 6. Lines 380–530: Second betting round with raise/call/fold logic and hand reveal subroutine. 7. Lines 540–632: Showdown comparison and winnings accounting. 8. Lines 640–912: Hand evaluation, hand-name printing, and utility subroutines. 9. Lines 920–1032: Card dealing, card name, and suit name subroutines. 10. Lines 1040–1096: Hand display and tally reset subroutines. 11. Lines 1100–1130: Stop, clear, and save. ### Data Structures The 4×13 array `S(4,13)` acts as a boolean deck: when a card with suit `S` and rank `J` is dealt, `S(S,J)` is set to 1, and subroutine 920 retries on collision. This guarantees no duplicate cards without sorting or shuffling. The rank tally array `T(13)` and suit tally `E(4)` are rebuilt by the reset subroutine at 1070 before each evaluation pass. ### Hand Evaluation (Lines 640–796) Subroutine 640 encodes poker hand strength into the variable `T` using an integer scale, and places the best high-card rank in `H9`. | T value | Hand | | --- | --- | | 0 | Nothing (high card) | | 1 | One pair | | 2 | Two pair | | 3 | Three of a kind | | 4 | Straight | | 5 | Flush | | 6 | Full house | | 7 | Four of a kind | | 9 | Straight flush | | 10 | Royal flush | The straight detection (lines 660–720) uses a decremented pointer `I` that walks backwards through the rank tally, looking for five consecutive non-zero entries. Ace is handled by temporarily remapping rank 1 to 14 (line 675). A flush is detected by checking if any `E(I)=5` (line 644). A straight flush scores `T+4` (line 710) giving 9; a royal flush adds 1 more (line 715) giving 10. Four of a kind is assigned T=7 directly (line 743). Three of a kind adds 5 to the current T (line 751), so a full house (flush base 0 + three + pair contributions) accumulates to 6. There is a notable anomaly at line 714: `IF T=4 THEN GOTO 170`. When a straight flush starting at rank 10 (i.e., a royal flush) is detected during the *computer’s initial deal* evaluation, the program jumps back to line 170 and redeals entirely rather than awarding the royal flush. This appears to be an intentional or accidental avoidance of an edge case. ### Computer AI Betting Logic The computer’s betting decisions are driven by a combination of hand strength (`F`, stored from `T` after evaluation) and randomness: - Line 216: A 20% random chance to skip the fold check and always accept the player’s opening bet. - Line 220: The computer folds if the player’s bet exceeds a threshold derived from `T`, `H9`, and a random factor. - Line 382: A random bluff flag — if `RND < F*0.5`, the computer’s maximum bet `B9` is set to 99.99, making it virtually uncapped (line 384). - Lines 420–472: The computer compares the pot total to `B9` and either calls, folds, or raises by a random fraction of the deficit. ### Card Drawing and Discard The computer’s discard strategy (lines 312–340) iterates through its five cards and replaces any card with a rank that appears only once in the tally (`T(J(Z))<>1`), up to a maximum of three replacements (`H9=3` guard at line 322). This is a simple keep-pairs heuristic. The player specifies card numbers 1–5 to replace; input is validated to reject values above 5 (line 270). ### Subroutine Map | Line | Purpose | | --- | --- | | 640 | Evaluate hand in `T()`/`E()`; return strength in `T`, high card in `H9` | | 800 | Remap `H9=1` to `H9=14` (Ace high) | | 820 | Print hand name from `T` value | | 920 | Deal one card: generate suit `S` and rank `J`, retry if already dealt | | 940 | Print rank name from `J` | | 1000 | Print suit name from `S` | | 1040 | Display player hand using `M()`/`N()` | | 1070 | Reset `T()` and `E()` tallies to zero | | 1080 | Rebuild tallies for computer hand `J()`/`F()` and evaluate | ### Notable Techniques and Idioms - The card name printer (lines 940–998) uses a separate `IF` per rank value rather than a lookup array or `ON...GOTO`, which is verbose but straightforward on this platform. - The variable name collision between array `S(4,13)` and scalar `S` (suit of dealt card) is resolved by context — BASIC treats them as distinct — but is a readability hazard. - Similarly, scalar `T` (hand strength) shares a name with array `T(13)` (rank tally); the hand-strength result is copied into scalar `T` inside subroutine 640 and read back in the main program. - Line 593 uses `PAUSE 1000` followed by `INKEY$` checks at lines 594–595 as a timed keypress wait idiom. - The T=8 hand strength value is unassigned, leaving a gap between full house (6) and four of a kind (7) — the straight flush jumps to 9, which is consistent with the `820` PRINT subroutine (no line for T=8). - At line 294, the program accumulates `T(M(X))` for the player hand tally but never resets `T()` beforehand at this point, relying on the fact that the reset was called at line 1070 via subroutine 1040. This ordering dependency means the tally logic is sensitive to call sequence. ### Bugs and Anomalies - Line 714: `IF T=4 THEN GOTO 170` causes a redeal whenever the computer is evaluated mid-deal to hold a straight flush, instead of crediting the hand. This is almost certainly a bug. - Lines 590–595: After the replay prompt, the program checks `INKEY$="N"` then falls through to line 600 regardless, meaning pressing N and pressing nothing both lead to the exit block. The “N” branch at line 595 is redundant. - Line 612 checks `IF P9<100 THEN PRINT …` immediately after line 610 already established `P9<100` via the failed `P9>=100` test, so the condition on 612 is always true if reached — a harmless redundancy. - The `SAVE "1031%4"` at line 1120 follows a `CLEAR`, which on some configurations would erase the program before saving — this appears to be a vestigial or erroneous line. ## Source Code ``` 10 DIM T(13) 20 DIM E(4) 30 DIM S(4,13) 40 DIM M(5) 50 DIM N(5) 60 DIM J(5) 70 DIM F(5) 80 CLS 90 PRINT AT 0,9;"% %P%O%K%E%R% %G%A%M%E% " 100 LET P9=100 110 PRINT 120 PRINT "ON BETTING, BET A ZERO TO CALL, " 130 PRINT "A NEGATIVE NUMBER TO GO OUT." 131 PRINT 140 FOR X=1 TO 4 142 FOR I=1 TO 13 144 LET S(X,I)=0 146 NEXT I 148 NEXT X 150 PRINT TAB 5;"CARDS ARE RESHUFFLED." 160 LET A9=5 161 PRINT 162 PRINT " $5.OO ANTE"; 164 PRINT ", YOU HAVE $";P9 165 PRINT ,TAB 6;"HIT -ENTER- TO BEGIN" 167 INPUT Z$ 169 CLS 170 FOR X=1 TO 5 171 GOSUB 920 172 LET M(X)=J 173 LET N(X)=S 174 NEXT X 175 GOSUB 1040 180 PRINT 181 PRINT "I WILL PICK MY HAND." 190 FOR X=1 TO 5 192 GOSUB 920 193 LET J(X)=J 194 LET F(X)=S 196 NEXT X 200 GOSUB 1080 201 LET F=T 203 LET C2=H9 205 LET P1=-5 210 PRINT 211 PRINT "OPEN WITH A BET "; 212 INPUT B 213 PRINT B 214 IF B<0 THEN GOTO 210 216 IF RND<.2 THEN GOTO 230 220 IF INT (((T*RND)+1)+((H9*RND)+1)+(T*10))3 THEN GOTO 350 320 FOR Z=1 TO 5 322 IF H9=3 THEN GOTO 340 326 IF T(J(Z))<>1 THEN GOTO 340 327 LET H9=H9+1 330 GOSUB 920 331 LET J(Z)=J 332 LET F(Z)=S 340 NEXT Z 350 PRINT 351 PRINT "I WILL TAKE ";H9;" CARD(S)." 352 LET H8=H9 360 GOSUB 1080 362 LET F=T 364 GOSUB 800 366 LET C2=H9 370 LET B9=INT ((F*RND)+(C2*RND)+(F*10))+INT (A9/3)+((K9-H8)*2)+7 380 LET B1=0 382 IF RND=100 THEN GOTO 620 612 IF P9<100 THEN PRINT "YOU LEFT LOSING $";100-P9 614 GOTO 1100 620 PRINT "YOU LEFT WINNING $";P9 622 GOTO 1100 630 PRINT "YOU OWE ME $";-P9 632 GOTO 1100 640 LET T=0 642 FOR I=1 TO 4 644 IF E(I)<>5 THEN GOTO 650 645 LET T=5 650 NEXT I 651 LET I=2 652 LET H9=0 660 LET I=I-1 662 IF I<>0 THEN GOTO 670 663 LET I=13 670 IF T(I)<1 THEN GOTO 660 671 LET H9=1 674 IF I<>1 THEN GOTO 680 675 LET I=14 680 LET Z=I-4 690 LET I=I-1 692 IF T(I)<>1 THEN GOTO 720 700 IF Z<>1 THEN GOTO 690 710 LET T=T+4 712 IF Z<>10 THEN GOTO 720 714 IF T=4 THEN GOTO 170 715 LET T=T+1 720 IF I=13 THEN GOTO 660 722 IF T<>5 THEN GOTO 730 724 IF T(1)<>1 THEN GOTO 730 725 LET H9=1 730 IF T=0 THEN GOTO 740 732 RETURN 740 FOR I=1 TO 13 742 IF T(I)<>4 THEN GOTO 750 743 LET T=7 750 IF T(I)<>3 THEN GOTO 760 751 LET T=T+5 752 LET H9=I 760 IF T(I)<>2 THEN GOTO 790 762 IF T=5 THEN GOTO 780 764 IF T<>0 THEN GOTO 770 765 LET H9=0 770 IF H9=1 THEN GOTO 780 772 IF H9>I THEN GOTO 780 773 LET H9=I 780 LET T=T+1 790 NEXT I 792 IF T<>5 THEN GOTO 810 793 LET T=3 796 RETURN 800 IF H9<>1 THEN GOTO 810 801 LET H9=14 810 RETURN 820 IF T=0 THEN PRINT "NOTHING" 830 IF T=1 THEN PRINT "ONE PAIR" 840 IF T=2 THEN PRINT "TWO PAIR" 850 IF T=3 THEN PRINT "THREE OF A KIND" 860 IF T=4 THEN PRINT "STRAIGHT" 870 IF T=5 THEN PRINT "FLUSH" 880 IF T=6 THEN PRINT "FULL HOUSE" 890 IF T=7 THEN PRINT "FOUR OF A KIND" 900 IF T=9 THEN PRINT "STRAIGHT FLUSH" 910 IF T=10 THEN PRINT "ROYAL FLUSH" 912 RETURN 920 LET S=INT (4*RND)+1 922 LET J=INT (13*RND)+1 930 IF S(S,J)=1 THEN GOTO 920 931 LET S(S,J)=1 934 RETURN 940 IF J=1 THEN PRINT "ACE"; 950 IF J=11 THEN PRINT "JACK"; 960 IF J=12 THEN PRINT "QUEEN"; 970 IF J=13 THEN PRINT "KING"; 980 IF J=14 THEN PRINT "ACE"; 988 IF J=9 THEN PRINT J; 989 IF J=10 THEN PRINT J; 990 IF J=2 THEN PRINT J; 992 IF J=3 THEN PRINT J; 994 IF J=4 THEN PRINT J; 995 IF J=5 THEN PRINT J; 996 IF J=6 THEN PRINT J; 997 IF J=7 THEN PRINT J; 998 IF J=8 THEN PRINT J; 999 RETURN 1000 IF S=1 THEN PRINT " OF HEARTS" 1010 IF S=2 THEN PRINT " OF SPADES" 1020 IF S=3 THEN PRINT " OF DIAMONDS" 1030 IF S=4 THEN PRINT " OF CLUBS" 1032 RETURN 1040 CLS 1042 PRINT "HERE IS YOUR HAND" 1043 PRINT 1044 FOR X=1 TO 5 1050 LET J=M(X) 1051 LET S=N(X) 1052 PRINT "CARD ";X;" IS A "; 1054 GOSUB 940 1056 GOSUB 1000 1060 NEXT X 1062 RETURN 1070 FOR X=1 TO 4 1072 LET E(X)=0 1074 NEXT X 1076 FOR X=1 TO 13 1077 LET T(X)=0 1078 NEXT X 1079 RETURN 1080 GOSUB 1070 1082 FOR X=1 TO 5 1084 LET T(J(X))=T(J(X))+1 1090 LET E(F(X))=E(F(X))+1 1092 NEXT X 1094 GOSUB 640 1096 RETURN 1100 STOP 1110 CLEAR 1120 SAVE "1031%4" 1130 RUN ```