Crazy Eights

Type
Game
Category
Card game against the computer
Author
Princeton Chan
Published in
Antic, April 1985 (Vol. 3, No. 12), bonus game
Year
1985
Language
Atari BASIC
Requirements
Any Atari 8-bit, Atari BASIC
A GRAPHICS 0 card table: five white cards along the top (3 of clubs, queen of spades, 8 of clubs, queen of clubs, 7 of diamonds), striped bars, and a blue text window showing the jack of hearts on the pile, DECK:41 COMPUTER:5 and a menu

About the program

Princeton Chan, a freshman at Lowell High School in San Francisco, wrote this version of the well-known card game for Antic's April 1985 issue. The article also explained how the program makes its "intelligent" decisions. It runs on any Atari, whatever its memory size.

The rules are the usual ones. Each player gets five cards, and the first to get rid of all their cards wins. You may discard a card that matches the top of the pile in rank or in suit. Eights are wild: you can play one at any time and name the suit that must follow. If you can't play, you draw from the deck. You can hold up to 18 cards, and you may pass only when you hold 18 or the deck has run out. Chan warned that the Atari is "very quick and skillful" at this game.

What you need

Atari BASIC and nothing else.

Typing it in

Most special characters are inverse video ({inv}…{/inv}, Atari key), used to draw the white cards and their ranks. There are single {CLEAR} (ESC then SHIFT-CLEAR), {CTRL-,}, {CTRL-.}, {CTRL-;} and {CTRL-P} characters, which are the suit symbols: heart, diamond, spade and club. Hold CTRL and press the key. Lines 140–180 are machine code and character data, so check them carefully. Antic asked readers to check the listing with TYPO II and SAVE it before running.

How to play

Choose from the menu by number: draw from the deck, put a card on the pile, or pass. To name a card, type just the first two letters of its rank and suit. KI is enough for KING, and EI for EIGHT (don't type the digit 8). The counters show how many cards are left in the deck and in the computer's hand.

How it works

  • The computer's strategy (lines 730–830) is short, as Chan showed. It scans its hand for a card matching the top card's rank or suit, or an eight. If it finds a second playable card, it picks one of the two at random. If it plays an eight, it chooses a suit at random from those it holds. If nothing matches, it draws until something does, or passes when it can't draw. The article admitted the strategy "could have been made more complex". The computer wins on speed and accuracy.
  • Cards are blocks of inverse spaces printed at a position, with the rank (subroutines 900–1020) and the suit pips (1040–1130) printed on top.
  • The table. A 28-byte routine in CHAR$ (line 120) copies the ROM font to RAM. Line 130 then redefines two characters as stripes (bytes 85 and 170), and line 190 fills the screen with them as the table pattern. An 11-byte display-list interrupt at 1536 turns the background blue for the bottom of the screen, and a player draws the frame around the pile.

Listing

10 REM CRAZY EIGHTS
20 REM BY PRINCETON CHAN
30 REM ANTIC MAGAZINE
60 GRAPHICS 0:POKE 752,1:DIM CARD(52),CARD1(52),HAND1(18),HAND2(18),TYPE1(18),TYPE2(18),CHOICE$(2),CHAR$(28)
65 FOR X=1 TO 18:HAND1(X)=0:NEXT X
70 RESTORE :DL=PEEK(560)+PEEK(561)*256:POKE 710,0:POKE 512,0:POKE 513,6:POKE 54286,192:POKE 559,0
80 FOR L=0 TO 10:READ D:POKE 1536+L,D:NEXT L
90 PMBASE=PEEK(106)-8:CHBASE=PMBASE-4:POKE 54279,PMBASE:POKE 53248,52:POKE 53256,3
100 POKE 704,0:PMBASE=PMBASE*256:FOR L=PMBASE+512 TO PMBASE+1024:POKE L,0:NEXT L
110 FOR L=PMBASE+597 TO PMBASE+622:READ D:POKE L,D:NEXT L
120 POKE 203,0:POKE 204,CHBASE:POKE 756,CHBASE:FOR L=1 TO 28:READ D:CHAR$(L)=CHR$(D):NEXT L:L=USR(ADR(CHAR$))
130 CHBASE=CHBASE*256:FOR L=CHBASE+776 TO CHBASE+791:READ D:POKE L,D:NEXT L
140 DATA 72,169,148,141,10,212,141,24,208,104,64
150 DATA 254,254,254,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,254,254,254
160 DATA 104,169,0,133,205,168,169,224,133,206,177,205,145,203,200,208,249,230,204,230,206,165,206,201,228
170 DATA 208,239,96
180 DATA 85,85,85,85,85,85,85,85,170,170,170,170,170,170,170,170
190 FOR L=1 TO 23:FOR L1=2 TO 38 STEP 2:POSITION L1,L:? "ab";:NEXT L1:NEXT L
200 POSITION 14,10:? "{inv}CRAZY EIGHTS{/inv}":POSITION 15,12:? "{inv}CREATED BY{/inv}":POSITION 13,14:? "{inv}PRINCETON CHAN{/inv}":POKE 559,46
210 COUNT1=0:COUNT2=0:COUNT=4:DECK=52:POKE 82,8
220 FOR L=1 TO 52:CARD(L)=0:CARD1(L)=0:NEXT L:FOR L=1 TO 13:HAND1(L)=0:HAND2(L)=0:TYPE1(L)=0
230 TYPE2(L)=0:NEXT L
240 FOR L=1 TO 13:FOR L1=1 TO 4
250 A=INT(RND(0)*52)+1:IF CARD(A)<>0 THEN 250
260 CARD(A)=L:CARD1(A)=COUNT:COUNT=COUNT-1:NEXT L1:COUNT=4:NEXT L
270 ? "{CLEAR}":FOR L=5 TO 11 STEP 6:FOR L1=1 TO 38 STEP 2:POSITION L1,L:? "ab";:NEXT L1:NEXT L
280 FOR L1=1 TO 5:COUNT1=COUNT1+1:HAND1(L1)=CARD(DECK):TYPE1(L1)=CARD1(DECK):DECK=DECK-1
290 VALUE=COUNT1:GOSUB 1210:VALUE=HAND1(L1):VALUE1=TYPE1(L1):GOSUB 850:NEXT L1
300 FOR L1=1 TO 5:COUNT2=COUNT2+1:HAND2(L1)=CARD(DECK):TYPE2(L1)=CARD1(DECK):DECK=DECK-1:NEXT L1
310 TOP=CARD(DECK):TOP1=CARD1(DECK):X=2:Y=18:VALUE=TOP:VALUE1=TOP1:GOSUB 850:DECK=DECK-1
320 POKE 53277,3:POKE DL+21,130
330 POSITION 8,17:? "DECK:";DECK,"COMPUTER:";COUNT2;" ":GOSUB 1420:IF COUNT2=0 THEN 1550
340 ? "IT IS NOW YOUR TURN":? "{inv}1{/inv}-DRAW FROM DECK":? "{inv}2{/inv}-PUT CARD IN PILE":? "{inv}3{/inv}-PASS"
350 POKE 694,0:POKE 702,64:POKE 764,255
355 OPEN #1,4,0,"K:":GET #1,CHOICE:CLOSE #1:IF CHOICE<49 OR CHOICE>51 THEN 350
360 GOSUB 1420:ON CHOICE-48 GOTO 370,420,720
370 IF COUNT1=18 THEN ? "YOU CAN ONLY HAVE UP TO 18":? "CARDS YOUR HAND":GOSUB 1430:GOTO 330
380 IF DECK<=0 THEN ? "THERE ARE NO MORE CARDS TO DRAW":GOSUB 1430:DECK=0:GOTO 330
390 COUNT1=COUNT1+1:FOR L1=1 TO 18:IF HAND1(L1)<>0 THEN NEXT L1
400 VALUE=L1:GOSUB 1210:VALUE=CARD(DECK):VALUE1=CARD1(DECK):GOSUB 850:HAND1(L1)=CARD(DECK):TYPE1(L1)=CARD1(DECK)
410 DECK=DECK-1:GOTO 330
420 ? "PLEASE ENTER IN THE CARD'S RANK":INPUT CHOICE$
430 IF CHOICE$="AC" THEN PILE=1:GOTO 570
440 IF CHOICE$="TW" THEN PILE=2:GOTO 570
450 IF CHOICE$="TH" THEN PILE=3:GOTO 570
460 IF CHOICE$="FO" THEN PILE=4:GOTO 570
470 IF CHOICE$="FI" THEN PILE=5:GOTO 570
480 IF CHOICE$="SI" THEN PILE=6:GOTO 570
490 IF CHOICE$="SE" THEN PILE=7:GOTO 570
500 IF CHOICE$="EI" THEN PILE=8:GOTO 570
510 IF CHOICE$="NI" THEN PILE=9:GOTO 570
520 IF CHOICE$="TE" THEN PILE=10:GOTO 570
530 IF CHOICE$="JA" THEN PILE=11:GOTO 570
540 IF CHOICE$="QU" THEN PILE=12:GOTO 570
550 IF CHOICE$="KI" THEN PILE=13:GOTO 570
560 ? "THERE IS NO SUCH CARD":GOSUB 1430:GOTO 330
570 GOSUB 1460:IF CHOICE<>155 THEN 330
580 GOSUB 1420:? "PLEASE ENTER IN THE TYPE OF":? "CARD":INPUT CHOICE$:GOSUB 1470
590 IF CHOICE$="" THEN ? "THERE IS NO SUCH THING":GOSUB 1430:GOTO 330
600 GOSUB 1460:IF CHOICE<>155 THEN 330
610 FOR L1=1 TO 18:IF HAND1(L1)<>PILE OR TYPE1(L1)<>PILE1 THEN NEXT L1:GOTO 710
620 IF PILE<>TOP AND PILE1<>TOP1 AND PILE<>8 THEN ? "YOU CANNOT PUT THIS CARD DOWN":GOSUB 1430:GOTO 330
630 IF PILE=8 THEN 680
640 COUNT1=COUNT1-1:VALUE=L1:GOSUB 1210:FOR L=0 TO 4:POSITION X,Y+L:? "     ":NEXT L
650 X=2:Y=18:VALUE=HAND1(L1):VALUE1=TYPE1(L1):GOSUB 850:TOP=HAND1(L1):TOP1=TYPE1(L1)
660 HAND1(L1)=0:TYPE1(L1)=0:IF COUNT1=0 THEN 1540
670 GOTO 730
680 GOSUB 1420:? "WHAT TYPE OF CARD DO YOU WANT":INPUT CHOICE$:GOSUB 1470
690 IF CHOICE$="" THEN ? "THERE IS NO SUCH THING":GOSUB 1430:GOTO 680
700 TYPE1(L1)=PILE1:GOTO 640
710 ? "YOU DO NOT HAVE SUCH A CARD":GOSUB 1430:GOTO 330
720 IF COUNT1<18 AND DECK>0 THEN ? "YOU NEED TO HAVE 18 CARDS TO":? "PASS":GOSUB 1430:GOTO 330
730 GOSUB 1420:GOSUB 1430:? "IT IS THE COMPUTER'S TURN"
740 FOR L1=1 TO 18:IF HAND2(L1)<>TOP AND TYPE2(L1)<>TOP1 AND HAND2(L1)<>8 THEN NEXT L1:GOTO 800
745 FOR L=L1 TO 18:IF HAND2(L)<>TOP AND TYPE2(L)<>TOP1 AND HAND2(L)<>8 THEN NEXT L1:GOTO 750
746 IF INT(RND(0)*2)+1=1 THEN L1=L
750 IF HAND2(L1)=8 THEN 780
760 X=2:Y=18:VALUE=HAND2(L1):VALUE1=TYPE2(L1):GOSUB 850:TOP=HAND2(L1):TOP1=TYPE2(L1):HAND2(L1)=0:TYPE2(L1)=0
770 POSITION 8,20:? "I HAVE PLACED DOWN ONE OF MY":? "CARDS":COUNT2=COUNT2-1:GOSUB 1430:GOTO 330
780 PILE1=INT(RND(0)*4)+1:FOR L=1 TO 18:IF TYPE2(L)<>PILE1 OR TYPE2(L)=8 THEN NEXT L:GOTO 780
790 TYPE2(L1)=PILE1:GOTO 760
800 IF DECK<=0 THEN FOR L=1 TO 18:IF HAND1(L)<>TOP AND TYPE1(L)<>TOP1 AND HAND1(L)<>8 THEN NEXT L:GOTO 1530
810 IF DECK<=0 OR COUNT2=18 THEN ? "I WILL HAVE TO PASS":GOSUB 1430:DECK=0:GOTO 330
820 POSITION 8,19:? "I WILL DRAW A CARD":FOR L=1 TO 18:IF HAND2(L)<>0 THEN NEXT L
830 COUNT2=COUNT2+1:HAND2(L)=CARD(DECK):TYPE2(L)=CARD1(DECK):GOSUB 1430:DECK=DECK-1:GOTO 730
850 FOR L=0 TO 4:POSITION X,Y+L:SOUND 0,PEEK(20),10,15:SOUND 1,PEEK(20),10,15:SOUND 2,PEEK(53770),10,15
860 FOR D=1 TO 10:NEXT D:? "{inv}     {/inv}":NEXT L:FOR L=0 TO 2:SOUND L,0,0,0:NEXT L
870 POSITION X,Y:ON VALUE GOSUB 900,910,920,930,940,950,960,970,980,990,1000,1010,1020
880 POSITION X+4,Y+4:ON VALUE GOSUB 900,910,920,930,940,950,960,970,980,1030,1000,1010,1020
890 ON VALUE GOSUB 1040,1050,1060,1070,1080,1090,1100,1110,1120,1130,1040,1040,1040:RETURN
900 ? "{inv}A{/inv}":RETURN
910 ? "{inv}2{/inv}":RETURN
920 ? "{inv}3{/inv}":RETURN
930 ? "{inv}4{/inv}":RETURN
940 ? "{inv}5{/inv}":RETURN
950 ? "{inv}6{/inv}":RETURN
960 ? "{inv}7{/inv}":RETURN
970 ? "{inv}8{/inv}":RETURN
980 ? "{inv}9{/inv}":RETURN
990 ? "{inv}10{/inv}":RETURN
1000 ? "{inv}J{/inv}":RETURN
1010 ? "{inv}Q{/inv}":RETURN
1020 ? "{inv}K{/inv}":RETURN
1030 POSITION X+3,Y+4:? "{inv}10{/inv}":RETURN
1040 GOSUB 1140:RETURN
1050 NMB=1:NMB1=3:STEP=2:COL=2:GOSUB 1150:RETURN
1060 NMB=1:NMB1=3:STEP=1:COL=2:GOSUB 1150:RETURN
1070 NMB=1:NMB1=3:STEP=2:COL=1:GOSUB 1150:COL=3:GOSUB 1150:RETURN
1080 NMB=1:NMB1=3:STEP=2:COL=1:GOSUB 1150:COL=3:GOSUB 1150:GOSUB 1140:RETURN
1090 NMB=1:NMB1=3:STEP=1:COL=1:GOSUB 1150:COL=3:GOSUB 1150:RETURN
1100 NMB=1:NMB1=3:STEP=1:COL=1:GOSUB 1150:COL=3:GOSUB 1150:GOSUB 1140:RETURN
1110 NMB=1:NMB1=3:STEP=1:COL=1:GOSUB 1150:COL=3:GOSUB 1150:GOSUB 1050:RETURN
1120 NMB=1:NMB1=3:STEP=1:COL=1:GOSUB 1150:COL=3:GOSUB 1150:GOSUB 1060:RETURN
1130 NMB=1:NMB1=3:STEP=1:COL=1:GOSUB 1150:COL=3:GOSUB 1150:GOSUB 1050:NMB=0:NMB1=4:STEP=4:COL=2:GOSUB 1150:RETURN
1140 POSITION X+2,Y+2:GOSUB 1160:RETURN
1150 FOR L=NMB TO NMB1 STEP STEP:POSITION X+COL,Y+L:GOSUB 1160:NEXT L:RETURN
1160 ON VALUE1 GOTO 1170,1180,1190,1200
1170 ? "{inv}{CTRL-,}{/inv}":RETURN
1180 ? "{inv}{CTRL-.}{/inv}":RETURN
1190 ? "{inv}{CTRL-P}{/inv}":RETURN
1200 ? "{inv}{CTRL-;}{/inv}":RETURN
1210 IF VALUE<7 THEN ON VALUE GOTO 1240,1250,1260,1270,1280,1290
1220 IF VALUE<13 THEN ON VALUE-6 GOTO 1300,1310,1320,1330,1340,1350
1230 ON VALUE-12 GOTO 1360,1370,1380,1390,1400,1410
1240 X=2:Y=0:RETURN
1250 X=8:Y=0:RETURN
1260 X=14:Y=0:RETURN
1270 X=20:Y=0:RETURN
1280 X=26:Y=0:RETURN
1290 X=32:Y=0:RETURN
1300 X=2:Y=6:RETURN
1310 X=8:Y=6:RETURN
1320 X=14:Y=6:RETURN
1330 X=20:Y=6:RETURN
1340 X=26:Y=6:RETURN
1350 X=32:Y=6:RETURN
1360 X=2:Y=12:RETURN
1370 X=8:Y=12:RETURN
1380 X=14:Y=12:RETURN
1390 X=20:Y=12:RETURN
1400 X=26:Y=12:RETURN
1410 X=32:Y=12:RETURN
1420 FOR L=18 TO 22:POSITION 8,L:? "                               ":NEXT L:POSITION 8,18:RETURN
1430 POKE 20,0
1440 IF PEEK(20)<>60 THEN 1440
1450 RETURN
1460 ? "PRESS RETURN IF YOU ARE SURE":POKE 764,255:OPEN #1,4,0,"K:":GET #1,CHOICE:CLOSE #1:RETURN
1470 IF CHOICE$="HE" THEN PILE1=1:RETURN
1480 IF CHOICE$="DI" THEN PILE1=2:RETURN
1490 IF CHOICE$="CL" THEN PILE1=3:RETURN
1500 IF CHOICE$="SP" THEN PILE1=4:RETURN
1510 CHOICE$="":RETURN
1530 ? "LOOKS LIKE THAT WE HAVE A TIE":GOTO 1560
1540 GOSUB 1420:? "CONGRATULATIONS, YOU WON":GOTO 1560
1550 ? "SORRY THAT YOU LOST. TRY AGAIN"
1560 GOSUB 1430:? "PRESS {inv}START{/inv} TO BEGIN A NEW GAME":FOR L=255 TO 0 STEP -1:POKE 712,L:NEXT L
1570 IF PEEK(53279)<>6 THEN POKE 704,PEEK(20):GOTO 1570
1580 RUN
1590 POKE 559,1:RESTORE :DL=PEEK(560)+PEEK(561)*256:POKE DL+21,130:POKE 710,0

Download

The original program from the Antic disk, to LOAD or ENTER instead of typing it: CRAZY8.BAS.

Credits