5 Card Showdown Poker

This file is part of and Timex Sinclair Public Domain Library Tape 1007. Download the collection to get this file.
Date: 198x
Type: Program
Platform(s): TS 1000

This program implements a 5-card draw poker hand dealer, randomly selecting and displaying five playing cards from a virtual deck. The deck is represented as a 4×13 two-dimensional array where suits are rows and card values are columns; a dealt card is flagged by setting its cell to −1, preventing duplicates. Card ranks K=1 through K=13 map to Ace, numeric values 2–10, Jack, Queen, and King via a chain of IF/GOTO branches, while suits J=1–4 map to Clubs, Spades, Hearts, and Diamonds. After each hand, the user can redeal from the same deck or reset the array and start with a freshly shuffled deck.


Program Analysis

Program Structure

The program is organized into three logical regions:

  1. Main loop (lines 10–55): Initializes or resets the deck array, deals five cards by calling a subroutine, then prompts the user to reuse or reset the deck.
  2. Deal subroutine (lines 100–153): Picks a random card, checks for duplicates, marks the card as used, then falls through to rank and suit printing branches.
  3. Rank/suit printing (lines 200–335): Dedicated PRINT statements for each rank and suit, connected by GOTO chains.

Deck Representation

The deck is modeled as D(4,13), a 4-row (suit) by 13-column (rank) array. A value of 0 indicates an available card; -1 marks a dealt card. This compact sentinel approach avoids the need for a separate dealt-card list. Lines 50–54 reset the array by writing 0 back to every cell before a new deck is used.

Card Selection and Duplicate Prevention

The subroutine at line 100 uses INT(13*RND)+1 for rank and INT(RND*4)+1 for suit. If the chosen cell is already -1, the subroutine loops back to line 100 via GOTO, implementing rejection sampling. This is simple but can become slow late in the deck as collisions increase; for a 5-card hand from 52 cards it is entirely practical.

Rank and Suit Dispatch via IF/GOTO Chains

Rather than using computed GOTO or data tables (not available in this BASIC dialect), rank printing is handled by 13 sequential IF K=n THEN GOTO lines (131–143). Similarly, suit printing uses four IF J=n THEN GOTO lines (150–153). This verbose but straightforward idiom was common practice when string arrays or ON…GOTO were unavailable or unfamiliar.

K valueRank printedTarget line
1ACE200
2–10numeric (K itself)210
11JACK220
12QUEEN230
13KING240
J valueSuit printedTarget line
1OF CLUBS300
2OF SPADES310
3OF HEARTS320
4OF DIAMONDS330

PRINT Formatting

Rank labels (lines 200–245) are printed with a trailing semicolon, suppressing the newline so the suit label on the next PRINT continues on the same line. The suit lines (300–330) include a leading space (e.g. " OF CLUBS") to separate rank from suit visually. Numeric ranks at line 210 print the value of K directly with PRINT K;, which for values 2–10 produces the correct numeral but will include a trailing space due to how BASIC formats numbers — this is a minor cosmetic quirk.

User Interaction and Deck Management

After five cards are displayed, lines 32–55 offer two choices: pressing Y re-enters the deal loop at line 20 without resetting the array (continuing from the same partly-depleted deck), or pressing N at the second prompt stops execution. Any other input at line 41 causes the deck to be zeroed and a new deal to begin. The logic is slightly asymmetric: the first prompt re-uses the deck on Y, while the second prompt halts on N and implicitly resets for any other key — a small usability inconsistency.

Unreachable Lines

Lines 340–360 (CLEAR, SAVE, RUN) are never reached during normal execution, as line 41 either STOPs or falls through to line 50. These lines appear to be a save/autostart block appended to the program and do not affect runtime behaviour.

Bugs and Anomalies

  • Line 210 prints K as a number rather than a string, so the output for, say, the 7 of Hearts will be 7 OF HEARTS (with an extra space from numeric formatting) rather than 7 OF HEARTS.
  • The program deals cards but performs no hand evaluation — it is purely a card-display tool despite the “SHOWDOWN POKER” title in the REM.
  • If the same deck is reused enough times (more than 52 cards dealt), the rejection-sampling loop at line 100 will loop forever as no undealt cards remain. There is no guard against this.

Content

Appears On

Assembled by Tim Ward from many sources. Contains programs 10294-10335.

Related Products

Related Articles

Related Content

Image Gallery

5 Card Showdown Poker

Source Code

   5 REM 5 CARD SHOWDOWN POKER
  10 DIM D(4,13)
  20 FOR H=1 TO 5
  25 GOSUB 100
  30 NEXT H
  31 PRINT 
  32 PRINT "SAME DECK: PRESS Y  YES, N NO"
  36 INPUT A$
  37 IF A$="Y" THEN GOTO 20
  38 PRINT "NEW DECK PRESS Y YES "
  39 PRINT 
  40 INPUT A$
  41 IF A$="N" THEN STOP 
  50 FOR J=1 TO 4
  51 FOR K=1 TO 13
  52 LET D(J,K)=0
  53 NEXT K
  54 NEXT J
  55 GOTO 20
 100 LET K=INT (13*RND)+1
 110 LET J=INT (RND*4)+1
 120 IF D(J,K)=-1 THEN GOTO 100
 130 LET D(J,K)=-1
 131 IF K=1 THEN GOTO 200
 132 IF K=2 THEN GOTO 210
 133 IF K=3 THEN GOTO 210
 134 IF K=4 THEN GOTO 210
 135 IF K=5 THEN GOTO 210
 136 IF K=6 THEN GOTO 210
 137 IF K=7 THEN GOTO 210
 138 IF K=8 THEN GOTO 210
 139 IF K=9 THEN GOTO 210
 140 IF K=10 THEN GOTO 210
 141 IF K=11 THEN GOTO 220
 142 IF K=12 THEN GOTO 230
 143 IF K=13 THEN GOTO 240
 150 IF J=1 THEN GOTO 300
 151 IF J=2 THEN GOTO 310
 152 IF J=3 THEN GOTO 320
 153 IF J=4 THEN GOTO 330
 200 PRINT "ACE ";
 205 GOTO 150
 210 PRINT K;
 215 GOTO 150
 220 PRINT "JACK ";
 225 GOTO 150
 230 PRINT "QUEEN ";
 235 GOTO 150
 240 PRINT "KING ";
 245 GOTO 150
 300 PRINT " OF CLUBS"
 306 RETURN 
 310 PRINT " OF SPADES"
 316 RETURN 
 320 PRINT " OF HEARTS"
 326 RETURN 
 330 PRINT " OF DIAMONDS"
 335 RETURN 
 340 CLEAR 
 350 SAVE "1030%8"
 360 RUN 

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

People

No people associated with this content.

Scroll to Top