--- title: "Poker" id: 64781 type: "computer_media" slug: "poker-3" url: "http://localhost/computer_media/poker-3/" markdown_url: "http://localhost/computer_media/poker-3.md" published_at: "2026-03-08T00:51:39+00:00" modified_at: "2026-03-30T21:44:46+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2026/03/Poker.png" excerpt: "A fully featured draw poker game with custom card graphics, a computerised opponent that reasons about its hand, and a complete betting system — all in BASIC." 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 2068" slug: "ts2068" taxonomy: "post_tag" url: "http://localhost/tag/ts2068/" model: - name: "Timex/Sinclair 2068" slug: "ts-2068" taxonomy: "model" url: "http://localhost/model/ts-2068/" 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: 64715 title: "Miscellaneous Programs" type: "computer_media" url: "http://localhost/computer_media/miscellaneous-programs/" media_type: "Program" mediadate: "198x" images: - url: "http://localhost/wp-content/uploads/2026/03/Poker.png" media_type_tags: "Card Game, Game" --- # Poker Five-card draw poker for the TS2068, player vs. computer, with UDG-drawn playing cards using the and 11-glyph rounded-frame set. The program includes a hand evaluator that scores all standard poker hands from high card through royal flush using a numeric ranking scheme, and a computer opponent that draws replacement cards based on hand type — standing pat on straights and above, drawing to pairs and incomplete sequences otherwise. Betting supports opening bets, raises, sees, and folds, with the computer folding probabilistically on weak hands. The player starts with $250 and antes $5 per hand, with a $25 cap on opening bets. *** ## Program Analysis This program implements a five-card draw poker game for one player against a computer dealer. It uses eleven user-defined graphics (UDGs “a” through “k”) loaded via DATA statements to render card outlines and suit symbols on screen. The deck is represented as a 104-character string in variable `a$`, with each card encoded as two characters: a rank character and a suit UDG character. The computer opponent uses a multi-stage decision tree spanning lines 900–1540 to evaluate hand strength and determine how many cards to draw, attempting straights, three-of-a-kind, and full-house improvements. A bubble-sort routine at lines 200–310 orders the hand by rank CODE values, and hand evaluation at lines 540–890 assigns a numeric score used for both the computer’s draw strategy and the final win/loss comparison. ### Program Structure The program is organised into clearly delineated subroutine blocks, with REM comments marking each section. Execution begins at line 1, initialises UDGs via `GO SUB 11`, then jumps to the main setup routine at line 2040 via `GO SUB 2040`, before entering the main game loop at line 29 via `GO TO 29`. | Lines | Purpose | | --- | --- | | 11–28 | UDG loader and REM catalogue of UDG characters | | 29–190 | Deck shuffle and deal preparation | | 200–310 | Bubble sort hand by rank (high-to-low) | | 320–420 | Convert rank codes to display characters (T,J,Q,K,A) and suit UDGs | | 430–530 | Card outline and value rendering on screen | | 540–890 | Hand evaluation — assigns numeric score to `v` | | 900–1540 | Computer draw decision logic | | 1550–2010 | Betting routine | | 2020–2030 | Display player’s current cash | | 2040–3130 | Main game loop: deal, discard, bet, compare | | 3140–3290 | End-game messages (fold, bust, win big) | | 3300–3360 | Instructions display | | 4000 | SAVE with auto-run | ### User-Defined Graphics Lines 11–24 load eleven UDGs (`\a` through `\k`) using `FOR a=USR "a" TO USR "k"+7` with `READ`/`POKE`. The DATA includes suit symbols (hearts, diamonds, clubs, spades implied by the bitmaps), card corner graphics, and a vertical bar character used for card borders. `NOT PI` evaluates to 0 and is used pervasively as a zero literal throughout the program. ### Deck Representation The entire 52-card deck is stored as a single string `a$` initialised at line 2050. Each card occupies two characters: the first is a rank character (`2`–`9`, `a`–`e` for Ten through Ace), and the second is a suit UDG character (`\a` or `\b` for two suits, `e` and `f` for the other two). Hands are dealt as 10-character slices of `c$`, the shuffled working copy. ### Shuffle Algorithm Lines 60–130 implement a selection-style shuffle. A random starting position `r` is chosen in `a$`, then the string is rotated: `x$=a$(r TO )+a$( TO r-1)`. A loop then picks 18 random card-pairs from `x$`, appending them to `c$` and removing them from `x$` by string concatenation — effectively building a partial deck of 18 cards used across the two hands and draw pool. ### Hand Evaluation Scoring The subroutine at lines 540–890 assigns a numeric value `v` based on hand rank. The encoding is: - `v = CODE k$` (base, high card) — rank of highest card - `v = 50 + CODE k$(l)` — one pair - `v = 100 + ...` — two pair - `v = 150 + ...` — three of a kind - `v = 200 + ...` — straight - `v = 250 + ...` — flush - `v = 300 + ...` — full house - `v = 350 + ...` — four of a kind - `v = 400 + ...` — straight flush - `v = 450 + ...` — royal flush (checks `CODE k$=42`, i.e. rank “T”) Detection of pairs, three-of-a-kind etc. relies on the hand already being bubble-sorted, allowing consecutive character comparisons. Flush detection at line 620 checks that all even-indexed characters (suit bytes) are equal. ### Computer Draw Strategy The AI decision subroutine (lines 900–1540) is the most complex section. It checks the current hand value `v` in descending order of strength and applies targeted card replacements to `o$` (a copy of the computer’s hand), substituting new cards from `c$`. The variable `t` records the number of cards drawn for display. Key strategies include: - Keeping four-of-a-kind or better untouched (line 930) - Drawing one card to a full house or four-of-a-kind draw - Drawing two cards to a three-of-a-kind - Drawing three cards to a pair - Attempting straight completions by detecting consecutive rank gaps ### Notable BASIC Idioms `NOT PI` is used throughout as a zero constant (since `PI ≠ 0`, `NOT PI = 0`), saving a keystroke vs. typing `0` and demonstrating awareness of the tokenised BASIC size optimisation. Similarly, `SGN PI` evaluates to 1 and is used as a 1-literal. `PI` alone (≈3.14159) is used where the integer 3 is needed via implicit truncation in string slicing — `k$(PI TO )` means `k$(3 TO )`. The expression `c$(PI TO )` advances the deal pointer by dropping the first two characters (indices 1–2, with slice starting at 3). Boolean string expressions appear in line 3040: `("Ok...,You Win" AND yv>mv)` concatenates the win message only if the condition is true, producing an empty string otherwise — a standard Spectrum/TS2068 idiom for conditional printing. ### Card Display Cards are rendered as 5×7 character blocks using UDGs for corners (`\f`, `\g`, `\h`, `\i`), horizontal rules (`\j`), and vertical bars (`\k`). Five cards are drawn across the screen in a single `FOR` loop at lines 440–460 with `STEP 6`. Rank and suit characters are printed inside the outlines by the subroutine at lines 480–530, which consumes `k$` two characters at a time as it iterates across columns. ### Betting System The player starts with $250 (line 2100) and pays a $5 ante per hand (line 2310). The maximum opening bet is $25. The computer’s betting aggression (lines 1550–1680) is modulated by a random variable: a roll above 0.9 triggers a maximum raise series, between 0.45 and 0.9 raises twice, and below 0.45 the computer folds if `btg<3`. The pot variable `wl` accumulates the total at stake. ### Potential Anomalies - Line 970 contains a duplicate condition (`k$(2)=k$(4) AND k$(2)=k$(10)` appears twice), making one branch unreachable. - The subroutine at line 1900 is called at lines 2970 and 3000 but does not exist in the listing — this would cause a runtime error when revealing hands. It appears to be a missing hand-display subroutine. - The variable `s` is set at line 2890 when the player is nearly out of money, but is never subsequently read. - The `c$` pointer advance at line 1070 uses `c$(PI TO )` (drop 2 chars) inside the loop but the loop draws 2-character cards, so the pointer advances correctly only if replacement cards are always taken in pairs — which holds for the three-of-a-kind case but may misalign for other draw counts. ## Source Code ``` 1 CLS : BORDER 6: PAPER 6: INK 0: 3 GO SUB 11 4 GO SUB 2040 6 GO TO 29 10 REM Shuffle Cards 11 FOR a=USR "a" TO USR "k"+7 12 READ user: POKE a,user 13 NEXT a: RETURN 14 DATA 24,60,126,255,255,126,60,24 15 DATA 24,60,90,255,255,90,24,60 16 DATA 16,56,124,254,254,124,16,56 17 DATA 68,238,254,254,254,124,56,16 18 DATA 204,204,51,51,204,204,51,51 19 DATA 0,NOT PI,NOT PI,7,15,12,24,24 20 DATA 0,NOT PI,NOT PI,192,240,48,24,24 21 DATA 24,24,12,15,7,NOT PI,NOT PI,0 22 DATA 24,24,48,240,192,NOT PI,NOT PI,0 23 DATA 0,NOT PI,NOT PI,255,255,NOT PI,NOT PI,0 24 DATA 24,24,24,24,24,24,24,24 27 REM a b c d e f g h i j k 28 REM \a \b \c \d \e \f \g \h \i \j \k 29 LET c$="" 30 PRINT AT 20,NOT PI,,"Stand by please",, 40 GO SUB 2020 50 RANDOMIZE 60 LET c$="" 70 LET r=INT (RND*52)*2+1 80 LET x$=a$(r TO )+a$( TO r-1) 90 FOR l=1 TO 18 100 LET r=INT (RND*(LEN x$/2))*2+1 110 LET c$=c$+x$(r TO r+1) 120 LET x$=x$( TO r-1)+x$(r+2 TO ) 130 NEXT l 140 PRINT AT 21,NOT PI;"Ready Press Enter", 150 INPUT r$ 160 CLS 170 LET a=0 180 GO SUB 430 190 RETURN 200 REM Sort Hi-Lo 210 LET r=1 220 FOR l=1 TO 7 STEP 2 230 IF CODE k$(l)200 THEN RETURN 940 IF v>100 THEN GO TO 1190 950 IF v>50 THEN GO TO 1330 960 IF k$(2)=k$(4) AND k$(2)=k$(6) AND k$(2)=k$(8) OR k$(2)=k$(4) AND k$(2)=k$(6) AND k$(2)=k$(10) OR k$(2)=k$(4) AND k$(2)=k$(8) AND k$(2)=k$(10) OR k$(4)=k$(6) AND k$(4)=k$(8) AND k$(4)=k$(10) THEN GO TO 1420 970 IF k$(2)=k$(4) AND k$(2)=k$(6) OR k$(2)=k$(4) AND k$(2)=k$(8) OR k$(2)=k$(4) AND k$(2)=k$(10) OR k$(2)=k$(6) AND k$(2)=k$(8) OR k$(2)=k$(4) AND k$(2)=k$(10) OR k$(2)=k$(6) AND k$(2)=k$(10) OR k$(4)=k$(6) AND k$(4)=k$(8) OR k$(4)=k$(8) AND k$(4)=k$(10) OR k$(6)=k$(8) AND k$(6)=k$(10) OR k$(6)=k$(4) AND k$(6)=k$(10) THEN GO TO 1020 980 IF CODE k$(SGN PI)=CODE k$(PI)+1 AND CODE k$(PI)=CODE k$(5)+1 OR CODE k$(PI)=CODE k$(5)+1 AND CODE k$(5)=CODE k$(7)+1 OR CODE k$(5)=CODE k$(7)+1 AND CODE k$(7)=CODE k$(9)+1 THEN GO TO 1110 990 LET k$(PI TO )=c$( TO 8) 1000 LET t=4 1010 RETURN 1020 IF k$(2)=k$(4) AND k$(2)=k$(6) OR k$(2)=k$(4) AND k$(2)=k$(8) OR k$(2)=k$(4) AND k$(2)=k$(10) OR k$(2)=k$(6) AND k$(2)=k$(10) OR k$(2)=k$(6) AND k$(2)=k$(8) OR k$(2)=k$(10) THEN LET g$=k$(2) 1030 IF k$(4)=k$(6) AND k$(4)=k$(8) OR k$(4)=k$(6) AND k$(4)=k$(10) OR k$(4)=k$(8) AND k$(4)=k$(10) THEN LET g$=k$(4) 1040 IF k$(6)=k$(8) AND k$(6)=k$(10) OR k$(6)=k$(8) AND k$(6)=k$(10) THEN LET g$=k$(6) 1050 FOR l=2 TO 10 STEP 2 1060 IF k$(l)<>g$ THEN LET k$(l-1 TO l)=c$( TO 2) 1070 LET c$=c$(PI TO ) 1080 NEXT l 1090 LET t=2 1100 RETURN 1110 IF CODE k$(SGN PI)=CODE k$(PI)+1 AND CODE k$(PI)=CODE k$(5)+1 AND CODE k$(5)=CODE k$(7)+1 OR CODE k$(PI)=CODE k$(5)+1 AND CODE k$(5)=CODE k$(7)+1 AND CODE k$(7)=CODE k$(9)+1 THEN GO TO 1500 1120 IF CODE k$(SGN PI)=CODE k$(PI)+1 THEN LET o$(7 TO 10)=c$( TO 4) 1130 IF CODE k$(PI)=CODE k$(5)+1 AND CODE k$(5)=CODE k$(7)+1 THEN LET o$(9 TO 10)=c$(PI TO 4) 1140 IF CODE k$(PI)=CODE k$(5)+1 AND CODE k$(5)=CODE k$(7)+1 THEN LET o$( TO 2)=c$( TO 2) 1150 IF CODE k$(7)=CODE k$(9)+1 THEN LET o$( TO 4)=c$( TO 4) 1160 LET t=2 1170 LET k$=o$ 1180 RETURN 1190 IF v>150 THEN GO TO 1260 1200 IF k$(SGN PI)=k$(PI) AND k$(5)=k$(7) THEN LET o$(9 TO )=c$( TO 2) 1210 IF k$(SGN PI)=k$(PI) AND k$(7)=k$(9) THEN LET o$(5 TO 6)=c$( TO 2) 1220 IF k$(PI)=k$(5) AND k$(7)=k$(9) THEN LET o$( TO 2)=c$( TO 2) 1230 LET t=1 1240 LET k$=o$ 1250 RETURN 1260 IF k$(SGN PI)=k$(PI) AND k$(SGN PI)=k$(5) THEN LET o$(7 TO )=c$( TO 4) 1270 IF k$(PI)=k$(5) AND k$(PI)=k$(7) THEN LET o$( TO 2)=c$( TO 2) 1280 IF k$(PI)=k$(5) AND k$(PI)=k$(7) THEN LET o$(9 TO )=c$(PI TO 4) 1290 IF k$(5)=k$(7) AND k$(5)=k$(9) THEN LET o$( TO 4)=c$( TO 4) 1300 LET t=2 1310 LET k$=o$ 1320 RETURN 1330 IF k$(SGN PI)=k$(PI) THEN LET o$(5 TO )=c$( TO 6) 1340 IF k$(PI)=k$(5) THEN LET o$( TO 2)=c$( TO 2) 1350 IF k$(PI)=k$(5) THEN LET o$(7 TO 10)=c$(PI TO 6) 1360 IF k$(5)=k$(7) THEN LET o$( TO 4)=c$( TO 4) 1370 IF k$(5)=k$(7) THEN LET o$(9 TO )=c$(5 TO 6) 1380 IF k$(7)=k$(9) THEN LET o$( TO 6)=c$( TO 6) 1390 LET t=3 1400 LET k$=o$ 1410 RETURN 1420 IF k$(2)=k$(4) OR k$(2)=k$(6) THEN LET v$=k$(2) 1430 IF k$(2)<>k$(4) AND k$(4)=k$(6) THEN LET v$=k$(4) 1440 FOR l=2 TO 10 STEP 2 1450 IF k$(l)<>v$ THEN LET k$(l-1 TO l)=c$( TO 2) 1460 LET c$=c$(PI TO ) 1470 NEXT l 1480 LET t=1 1490 RETURN 1500 IF CODE k$(SGN PI)=CODE k$(PI)+1 AND CODE k$(PI)=CODE k$(5)+1 AND CODE k$(5)=CODE k$(7)+1 THEN LET o$(9 TO )=c$( TO 2) 1510 IF CODE k$(PI)=CODE k$(5)+1 AND CODE k$(5)=CODE k$(7)+1 AND CODE k$(7)=CODE k$(9)+1 THEN LET o$( TO 2)=c$( TO 2) 1520 LET k$=o$ 1530 LET t=1 1540 RETURN 1550 REM Betting Routine 1560 LET c=0 1570 IF mv>200 THEN LET c=mv/50 1580 IF mv>200 THEN GO TO 1680 1590 LET x=RND 1600 IF x>.9 THEN LET c=8 1610 IF c=8 THEN GO TO 1680 1620 IF x>.45 OR btg<3 THEN LET c=2 1630 IF c=2 THEN GO TO 1680 1640 LET y=y+btg 1650 LET wl=5 1660 GO SUB 1940 1670 GO TO 3190 1680 FOR l=1 TO c 1690 PRINT AT 19,NOT PI;"I See you and raise you $";btg, 1700 PRINT AT 21,NOT PI;"Enter your bet",, 1710 GO SUB 2020 1720 INPUT i 1730 IF y<2*btg OR i=0 OR i=btg OR i=2*btg THEN GO TO 1760 1750 GO TO 1720 1760 LET wl=wl+i 1770 LET y=y-i 1780 IF y3 AND RND>=.6 THEN GO TO 3170 1840 NEXT l 1850 GO SUB 1940 1860 PRINT AT 19,NOT PI;"I see you....",, 1870 RETURN 1880 PRINT AT 19,NOT PI;"So you see me....", 1930 RETURN 1940 REM Delay Loop 1950 FOR p=1 TO 20 1960 NEXT p 1970 RETURN 1980 GO SUB 1940 1990 PRINT AT 19,NOT PI;"You will have to see me....", 2000 GO SUB 1940 2010 RETURN 2020 PRINT AT 21,18;"You have $";y 2030 RETURN 2040 REM Start of Program 2050 LET a$="2\b3\b4\b5\b6\b7\b8\b9\ba\bb\bc\bd\be\b2\a3\a4\a5\a6\a7\a8\a9\aa\ab\ac\ad\ae\a2e3e4e5e6e7e8e9eaebecedeee2f3f4f5f6f7f8f9fafbfcfdfef" 2070 DIM m$(2,10) 2080 DIM y$(2,10) 2090 LET bt=0 2100 LET y=250 2110 PRINT AT 9,4;" Timex/Sinclair poker " 2120 REM Instructions ? 2130 PRINT AT 20,NOT PI;"Do you require details ?(y OR n)" 2140 IF INKEY$<>"" THEN GO TO 2140 2150 IF INKEY$="" THEN GO TO 2150 2160 LET s$=INKEY$ 2170 IF s$="y" THEN GO SUB 3300 2180 GO SUB 29 2190 REM Deal hands 2200 FOR l=1 TO 9 STEP 2 2210 LET m$(1,l TO l+1)=c$( TO 2) 2220 LET y$(1,l TO l+1)=c$(PI TO 4) 2230 LET c$=c$(5 TO ) 2240 NEXT l 2250 LET k$=y$(SGN PI) 2260 GO SUB 200 2270 LET y$(SGN PI)=k$ 2280 GO SUB 320 2290 LET y$(2)=k$ 2300 REM Initial Stake 2310 LET y=y-5 2320 LET b=1 2330 GO SUB 480 2340 LET k$=m$(SGN PI) 2350 REM Numbers under cards 2360 PRINT AT 7,PI;"1 2 3 4 5" 2370 GO SUB 200 2380 REM Discard which cards ? 2390 PRINT AT 19,NOT PI;"Swap which card?(ie. Press 2 ForNo. 2 Etc. and/or P to Pass )", 2400 FOR l=1 TO 4 2410 IF INKEY$<>"" THEN GO TO 2410 2420 IF INKEY$="" THEN GO TO 2420 2430 LET t$=INKEY$ 2440 IF t$="p" THEN GO TO 2510 2450 IF t$<"1" OR t$>"5" THEN GO TO 2410 2460 PRINT AT 7,VAL t$*6-3;"*" 2470 LET t=VAL t$*2-1 2480 LET y$(1,t TO t+1)=c$( TO 2) 2490 LET c$=c$(PI TO ) 2500 NEXT l 2510 PRINT AT 19,NOT PI,,,,TAB 10;" Dealing ", 2520 LET k$=y$(SGN PI) 2530 GO SUB 200 2540 LET y$(SGN PI)=k$ 2550 GO SUB 320 2560 LET y$(2)=k$ 2570 LET b=1 2580 GO SUB 480 2590 PRINT AT 7,NOT PI,, 2600 PRINT AT 21,NOT PI;"Bet till now $5",, 2610 GO SUB 2020 2620 LET k$=y$(SGN PI) 2630 GO SUB 540 2640 LET yv=v 2650 LET k$=m$(SGN PI) 2660 GO SUB 540 2670 GO SUB 900 2680 PRINT AT 19,NOT PI,,,,AT 19,NOT PI;"Dealer Takes ";t;" card"+("s" AND t<>1) 2690 LET m$(SGN PI)=k$ 2700 GO SUB 200 2710 LET m$(SGN PI)=k$ 2720 GO SUB 320 2730 LET m$(2)=k$ 2740 LET a=10 2750 GO SUB 430 2760 LET k$=m$(SGN PI) 2770 GO SUB 540 2780 LET mv=v 2790 REM Betting Begins 2800 REM PRINT AT 21,0;"Your Bet ?",, 2810 GO SUB 2020 2820 INPUT btg 2830 LET btg=INT btg 2840 IF NOT btg THEN GO TO 3150 2850 IF btg>y OR btg>25 THEN PRINT AT 21,NOT PI,, 2860 PRINT AT 21,NOT PI;("You do not have that much..." AND btg>y)+("Limit is $25" AND btg>25) 2870 IF btg>y OR btg>25 THEN GO SUB 2020 2880 IF btg>y OR btg>25 THEN GO TO 2820 2890 IF btg=y OR y-btgmv)+("Tough Luck, I Win" AND mv>yv)+("It is a Draw..." AND mv=yv) 3050 REM adjust money 3060 IF yv>mv THEN LET y=y+wl*2 3070 IF yv=mv THEN LET y=y+wl 3080 GO SUB 2020 3090 GO SUB 1940 3100 GO SUB 1940 3110 IF y>2000 THEN GO TO 3220 3120 IF y<6 THEN GO TO 3270 3130 GO TO 2180 3140 REM various remarks 3150 PRINT AT 19,NOT PI;"So Your Chicken..... ?", 3160 GO TO 3080 3170 LET wl=wl-i 3180 LET y=y+i 3190 PRINT AT 19,NOT PI;"I am out............", 3200 LET y=y+wl*2 3210 GO TO 3080 3220 GO SUB 1940 3230 GO SUB 1940 3240 CLS 3250 PRINT AT 10,NOT PI;"Well That beats me. I am going home. Bye-bye for now." 3260 STOP 3270 CLS 3280 PRINT AT 10,NOT PI;"It appears you have no more cash thanks and bye-bye." 3290 STOP 3300 CLS 3310 PRINT '" This is a game of draw poker played by you against the Timex/sinclair." 3320 PRINT '" You will be dealt with five cards, and then be asked which ones you wish to discard. You may discard a maximum of 4 cards" 3330 PRINT '" On each deal your total will automatically be debited with $5. This is your starting stake." 3340 PRINT '" The maximum initial bet is $25. There after you must all- ways double or see. To throw in your cards enter a 0." 3350 PRINT AT 20,2;"Good luck....." 3355 PAUSE 300 3360 RETURN 4000 SAVE "poker" LINE 1 ```