Dealers

Author(s): Frank Terranella
Publication: Timex Sinclair User
Pub Details: Timex Sinclair User n5 (Volume 1, Issue 5)
Date: October 1983
Pages: 29
Cartoon card dealer fanning cards that spell DEALERS
Cartoon card dealer fanning cards that spell DEALERS

THE program is really a subroutine. It will deal a deck of 52 cards at random without repeating a card.

The first part of the program (lines 1000 to 1080) loads the names of the 13 different cards into a string variable C$. This could have been done by 13 LET statements such as LET C$(1) = “ACE” and LET C$(2) = “DEUCE” and so on, but this little routine is my substitute for a READ/DATA statement in Sinclair BASIC. Put all your data in A$ with no spaces between items, and put the number of characters in each item as a two-digit number in B$. Thus, the first two-digit number in B$ is 03, signalling the fact that the first data item in A$ is three letters long. By setting up data in these strings you can consecutively load data into C$. This mimics a READ/DATA statement.

The second part of the program is a random number generator. This routine will generate any number of random integers without repeating an integer. Those who have used the RND function know how frustrating it is when the machine randomly comes up with the same number three times in a row. This program allows no repeats. By changing the number 52 in lines 1110, 1120 and 1130 to any number you wish, the program will count up to that number in random order. The higher the number, the longer the program will take. I must warn you that the machine is slow at this, even in FAST mode.

Lines 1290 to 1350 are a simple print loop assigning suits to the cards and printing them on the screen. You’ll get a 5 error when the screen fills. If you hit CONT, you’ll get more cards. The print loop is just to show you that the program works. It’s up to you to think up applications for the computerized dealer. For instance, you could delete lines 1290 and 1350 and put in a new line 1290 which brings you into your main program. Then you could use a GOSUB 1300 to deal a card. Remember to advance the value of X after each card is dealt and remember to put in a RETURN command at 1350.

May the cards be with you.

Submitted by Frank Terranella of Sloatsburg, N.Y. (T/S1000,1500,ZX81 16K).

1000 REM CARDS
1001 FAST
1005 LET A$="ACEDEUCETHREEFOURFIVESIXSEVENEIGHTNINETENJACKQUEENKING"
1010 LET B$="03050504040305050403040504"
1020 LET A=1
1030 LET N=0
1035 DIM C$(13,5)
1040 FOR B=1 TO (LEN B$/2)
1050 LET C$(B)=A$(N+1 TO VAL B$(A TO A+1)+N)
1060 LET N=VAL B$(A TO A+1)+N
1070 LET A=A+2
1080 NEXT B
1100 REM RANDOM ROUTINE
1110 DIM A(52)
1120 FOR X=1 TO 52
1130 LET A(X)=INT (RND*52)+1
1140 IF X>1 THEN GOTO 1200
1160 NEXT X
1200 LET Y=X-1
1210 IF A(X)<>A(Y) THEN GOTO 1230
1220 GOTO 1130
1230 LET Y=Y-1
1240 IF Y=0 THEN NEXT X
1250 IF X<=52 THEN GOTO 1210
1289 SLOW
1290 FOR X=1 TO 52
1300 IF A(X)<=13 THEN PRINT C$(A(X));" OF SPADES"
1310 IF A(X)>=14 AND A(X)<=26 THEN PRINT C$(A(X)-13);" OF DIAMONDS"
1320 IF A(X)>=27 AND A(X)<=39 THEN PRINT C$(A(X)-26);" OF CLUBS"
1330 IF A(X)>=40 AND A(X)<=52 THEN PRINT C$(A(X)-39);" OF HEARTS"
1350 NEXT X

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