4K/1K Blackjack

Author(s): Wayne Root
Publication: Syntax
Pub Details: Syntax/Syntax ZX80 v3 n1 (Volume 3, Issue 1)
Date: January 1982
Pages: 16

In this 4K/1K ZX80 version of 21 you play one-on-one against the computer-dealer. It deals you two cards face up. To take another card, hit NL; to hold, press SPACE NL. The ZX80 then plays out its hand and shows if you win or lose.

You can only play 5 cards, and you cannot convert aces from 11s to 1s. The computer masks its down card and score until it plays. To play again, hit NL; to exit, hit SPACE NL. Line functions appear after semicolons in each line.

  10 DIM P(5)  ;your hand
20 DIM C(5) ;computer's hand
30 DIM D(10) ;deck of cards
40 LET Q=0 ;position of card ;in your hand
50 LET U=0 ;position of card ;in computer's hand
60 LET V=1 ;ZX80's turn? 0=yes
70 FOR J=3 TO 5
80 LET C(J)=0 ;clears cards 3,4,5
90 LET P(J)=0 ;of last hand
100 NEXT J
110 GO SUB 360 ;shuffle
120 GO SUB 500 ;deal your card 1
130 GO SUB 550 ;deal ZX80's card 1
140 GO SUB 500 ;deal your card 2
150 GO SUB 550 ;deal ZX80's card 2
160 GO TO 200
170 INPUT A$ ;want a card?
180 IF NOT A$="" THEN GO TO 230 ;yes hit NL, no hit space NL
190 GO SUB 500 ;deal you a card
200 IF S>21 THEN GO TO 300 ;lose?
210 IF S=21 THEN GO TO 230 ;if 21 ;then ZX80's turn
220 GO TO 170
230 LET V=0 ;now ZX80's turn
240 GO SUB 600 ;show hidden card
250 GO TO 270
260 GO SUB 550 ;deal ZX80's card
270 IF T<17 THEN GO TO 260 ;ZX80's ;total <17?
280 IF T>21 THEN GO TO 340 ;ZX80
290 IF T<S THEN GO TO 340 ;loses?
300 PRINT "LOSE"
310 INPUT A$ ;play again?
320 IF NOT A$="" THEN STOP
330 GO TO 40 ;restart
340 PRINT "WIN"
350 GO TO 310
360 FOR J=1 TO 10 ;shuffle routine
370 LET X=RND(52) ;random card ;choice
380 FOR W=1 TO 10
390 IF X=D(W) THEN GO TO 370 ;that
400 NEXT W ;card already picked?
410 GO TO 430
420 LET X=X-13 ;card point value
430 IF X>13 THEN GO TO 420
440 IF X>10 THEN LET X=10 ;face ;cards=10
450 IF X=1 THEN LET X=11 ;aces=11
460 LET D(J)=X ;place card in deck
470 NEXT J
480 LET K=0 ;card position in deck
490 RETURN
500 LET K=K+1 ;next position
510 LET Q=Q+1 ;next position in ;your hand
520 LET P(Q)=D(K) ;from deck to ;your hand
530 GO SUB 600 ;print
540 RETURN
550 LET K=K+1 ;next deck position
560 LET U=U+1 ;next position in ;ZX80's hand
570 LET C(U)=D(K) ;from deck to ;ZX80's hand
580 GO SUB 600 ;print
590 RETURN
600 CLS ;print subroutine
610 LET S=0 ;clear your total
620 LET T=0 ;clear ZX80's total
630 FOR Z=1 TO 5
640 IF V=Z THEN GO TO 670 ;if not ;ZX80's turn, mask card 1
650 PRINT P(Z),C(Z) ;print cards
660 GO TO 680
670 PRINT P(Z),C(Z) ;masked card 1
680 PRINT
690 LET S=S+P(Z) ;add your score
700 LET T=T+C(Z) ;add ZX80's score
710 NEXT Z
720 IF V=1 THEN GO TO 750 ;not ;ZX80's turn yet
730 PRINT S,T ;print totals
740 GO TO 760
750 PRINT S,CHR$(15) ;mask ZX80's
760 PRINT ;score
770 RETURN
Syntactic Sum: 8075, 4K

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