Collapsing Deck

Type
Game
Category
Patience (solitaire) card game
Author
A. R. (Allen) Miller
Published in
Antic, June/July 1990 (Vol. 9, No. 2)
Year
1990
Language
Atari BASIC
Requirements
48K RAM, Atari BASIC, disk drive (per the magazine); keyboard only
Text screen headed COLLAPSING DECK showing all 52 cards in rows of eight as inverse suit symbols and values, with a command menu at the bottom

About the program

Collapsing Deck was the "Bonus Game" in the June/July 1990 Antic. Allen Miller, a maintenance manager at an industrial plant near Cincinnati who had owned an Atari since 1983, wrote it after a friend showed him the game running on a PC and asked whether there was a Commodore version. Miller wrote it in Atari BASIC and gave his friend a copy to translate into Commodore BASIC. (The title page in the program says 1989.)

The rules are simple. You deal cards into a row one at a time. Whenever a card matches the card immediately to its left, or the card three places to its left, in either suit or value, you can move it on top of that card, closing the gap. The aim is to squeeze the whole deck down to one pile. Miller admitted he'd managed it only once.

What you need

Any Atari 8-bit with Atari BASIC; the magazine asked for 48K and a disk drive, though the program itself is small. It's played entirely from the keyboard.

Typing it in

The disk version has no TYPO II checksum codes. Line 240 holds the four suit symbols: {inv}{CTRL-;}{CTRL-,}{CTRL-.}{CTRL-P}{/inv} means inverse CTRL-semicolon (spade), CTRL-comma (heart), CTRL-period (diamond) and CTRL-P (club). Turn inverse on with the Atari key, then hold CTRL and press each key. The card values in V$ are inverse too, two characters each, so "10" fits the same space as "A ". The other {inv} text is just inverse labels and REMs.

How to play

RUN it. After "SHUFFLING DECK", two cards are dealt and a ^ cursor sits under the last one. The command menu at the bottom stays on screen:

Key Command
1 Back one: move the card above the cursor onto the card on its left
3 Back three: move it onto the card three places left
N Deal the next card
A Deal all the remaining cards
L Move the cursor to the last card
< / > Move the cursor left or right
E End the game and score it

A move is only allowed if the two cards share a suit or a value; otherwise you get a raspberry. The panel on the right counts the cards still in the deck. When you press E, the program looks for a move you've missed and sends you back to check, or else shows your result. It rates you from "none better!" for one pile down to "novice!".

How it works

  • Cards as numbers. Each card is stored as suit × 100 + value (line 340), so INT(DK(I)/100) gives the suit and the remainder gives the value. Collapsing a card is then just array shuffling: line 620 shifts everything down by one, and line 700 drops the card three places back and closes the gap.
  • A fixed grid. Line 260 precomputes 56 screen positions (eight columns, seven rows) in PT(), and the whole row is reprinted after every move.
  • Shuffling by rejection. Line 310 picks a random suit and value and tries again if that card has already been used. (As published, it rounded with +0.5, so clubs and kings came up half as often per try and tended to be dealt late; the listing here uses INT(RND(0)*4)+1 and INT(RND(0)*13)+1, which makes the shuffle fair.)
  • The referee. When you press E, lines 920–970 compare every card with its neighbour, and lines 990–1040 compare every card with the one three places along. If either finds a legal move, you're sent back to look again. As published, both checks were broken (see "Changes from the published listing"), so the program could congratulate you while a move was still open.

Variations to try

  • Allow only suit matches, or only value matches, for a harder game.

Changes from the published listing

Line As published Now Why
310 X=INT(RND(0)*4+0.5):Y=INT(RND(0)*13+0.5):… X=INT(RND(0)*4)+1:Y=INT(RND(0)*13)+1:… Rounding gave 0–4 and 0–13, with the ends half as likely; the 0s were thrown away, so clubs and kings came up less often and the shuffle was biased.
920 FOR I=1 TO ED-1 FOR I=1 TO ED Each card is compared with the one before it, so the loop stopped one short and never compared the last two cards.
980 IF E<4 THEN 1110 IF ED<4 THEN 1110 E is never set, so the three-apart check was always skipped.
1000 DK(I-1) (twice) DK(I+3) (twice) The three-apart check compared neighbours (copied from line 920) instead of cards three places apart.

Listing

100 REM **********************
110 REM *  COLLAPSING  DECK  *
120 REM *   BY A. R. MILLER  *
140 REM **********************
150 REM (c)1990, ANTIC PUBLISHING,INC.
160 REM {inv}TITLE PAGE{/inv}
170 GRAPHICS 1+16:POSITION 1,4:? #6;"{inv}*******************{/inv}"
180 POSITION 1,5:? #6;"{inv}*{/inv} COLLAPSING DECK {inv}*{/inv}"
190 POSITION 1,6:? #6;"{inv}*{/inv}   a. r. miller  {inv}*{/inv}"
200 POSITION 1,7:? #6;"{inv}*{/inv}       1989      {inv}*{/inv}"
210 POSITION 1,8:? #6;"{inv}*******************{/inv}"
220 REM {inv}SET UP{/inv}
230 DIM DK(54),CD(4,13),PT(2,56),F$(4),V$(26),L$(2):OPEN #1,4,0,"K:"
240 F$="{inv}{CTRL-;}{CTRL-,}{CTRL-.}{CTRL-P}{/inv}":V$="{inv}A 2 3 4 5 6 7 8 9 10J Q K {/inv}"
250 REM {inv}SET UP POINTERS{/inv}
260 I=1:FOR Y=4 TO 16 STEP 2:FOR X=0 TO 35 STEP 5:PT(1,I)=X:PT(2,I)=Y:I=I+1:NEXT X:NEXT Y
270 REM {inv}SHUFFLE DECK{/inv}
280 FOR I=1 TO 53:DK(I)=0:NEXT I:GRAPHICS 1+16:POSITION 3,6:? #6;"SHUFFLING DECK"
290 FOR X=1 TO 4:FOR Y=1 TO 13:CD(X,Y)=0:NEXT Y:NEXT X
300 FOR I=1 TO 52
310 X=INT(RND(0)*4)+1:Y=INT(RND(0)*13)+1:IF CD(X,Y) THEN 310
320 IF X<1 OR X>4 THEN 310
330 IF Y<1 OR Y>13 THEN 310
340 CD(X,Y)=1:DK(I)=X*100+Y:NEXT I:KC=2:KP=2:ED=52
350 REM {inv}MAIN PRINTING LOOP{/inv}
360 GRAPHICS 0:POSITION 0,1:? "{inv}***********COLLAPSING  DECK***********{/inv}";
370 POSITION 0,19:? "{inv}............... COMMANDS .............{/inv}";
380 POSITION 1,20:? "{inv}1{/inv} BACK ONE";:POSITION 1,21:? "{inv}3{/inv} BACK THREE";
390 POSITION 15,20:? "{inv}N{/inv} NEXT CARD";:POSITION 15,21:? "{inv}A{/inv} ALL CARDS";
400 POSITION 1,22:? "{inv}E{/inv} END GAME";:POSITION 15,22:? "{inv}L{/inv} MOVE TO END"
410 POSITION 1,23:? "{inv}<{/inv} MOVE LEFT";:POSITION 15,23:? "{inv}>{/inv} MOVE RIGHT"
420 POSITION 32,20:? "{inv}CARDS{/inv}":POSITION 32,21:? "{inv}LEFT{/inv}":POSITION 33,22:? ED-KC
430 FOR I=1 TO KC:F=INT(DK(I)/100):V=(DK(I)-F*100)
440 POSITION PT(1,I),PT(2,I):? F$(F,F);V$(2*V-1,2*V);:NEXT I
450 POSITION PT(1,KP)+1,PT(2,KP)+1:? "{inv}^{/inv}";:POKE 752,1
460 GET #1,Z:REM {inv}DO WHAT?{/inv}
470 IF Z=49 THEN 570:REM {inv}BACK ONE CARD{/inv}
480 IF Z=51 THEN 660:REM {inv}BACK THREE CARDS{/inv}
490 IF Z=78 OR Z=110 THEN 860:REM {inv}NEXT CARD{/inv}
500 IF Z=65 OR Z=97 THEN 890:REM {inv}ALL CARDS{/inv}
510 IF Z=69 OR Z=101 THEN 920:REM {inv}END GAME{/inv}
520 IF Z=76 OR Z=108 THEN 810:REM {inv}MOVE TO LAST CARD{/inv}
530 IF Z=60 THEN 740:REM {inv}MOVE LEFT{/inv}
540 IF Z=62 THEN 780:REM {inv}MOVE RIGHT{/inv}
550 FOR I=1 TO 30:SOUND 1,29,10,10:SOUND 1,243,10,10:NEXT I:SOUND 1,0,0,0:GOTO 460
560 REM {inv}BACK ONE CARD{/inv}
570 IF KP=1 THEN 550:REM {inv}YOU CANNOT DO THAT{/inv}
580 F=INT(DK(KP)/100):V=DK(KP)-F*100:F1=INT(DK(KP-1)/100):V1=DK(KP-1)-F1*100
590 IF F=F1 THEN 620
600 IF V=V1 THEN 620
610 GOTO 550:REM {inv}YOU CANNOT DO THAT{/inv}
620 FOR I=KP-1 TO ED-1:DK(I)=DK(I+1):NEXT I:KP=KP-1:KC=KC-1:ED=ED-1
630 IF ED=1 THEN 920:REM {inv}GO TO END OF GAME{/inv}
640 GOTO 360
650 REM {inv}BACK THREE CARDS{/inv}
660 IF KP<4 THEN 550:REM {inv}YOU CANNOT DO THAT{/inv}
670 F=INT(DK(KP)/100):V=DK(KP)-F*100:F1=INT(DK(KP-3)/100):V1=DK(KP-3)-F1*100:IF F=F1 THEN 700
680 IF V=V1 THEN 700
690 GOTO 550:REM {inv}YOU CANNOT DO THAT{/inv}
700 DK(KP-3)=DK(KP):FOR I=KP TO ED-1:DK(I)=DK(I+1):NEXT I:DK(ED)=0:KP=KP-3:KC=KC-1:ED=ED-1
710 IF ED=1 THEN 920:REM {inv}GO TO END OF GAME{/inv}
720 GOTO 360
730 REM {inv} MOVE LEFT{/inv}
740 IF KP=1 THEN 550:REM {inv}YOU CANNOT DO THAT{/inv}
750 POSITION PT(1,KP)+1,PT(2,KP)+1:? "  ";:SOUND 1,200,10,10:SOUND 1,0,0,0:KP=KP-1
760 POSITION PT(1,KP)+1,PT(2,KP)+1:? "^";:SOUND 1,200,10,10:SOUND 1,0,0,0:GOTO 460
770 REM {inv} MOVE RIGHT{/inv}
780 IF KP=KC THEN 550:REM {inv}YOU CANNOT DO THAT{/inv}
790 POSITION PT(1,KP)+1,PT(2,KP)+1:? "  ";:SOUND 1,200,10,10:SOUND 1,0,0,0:KP=KP+1
800 POSITION PT(1,KP)+1,PT(2,KP)+1:? "^";:SOUND 1,200,10,10:SOUND 1,0,0,0:GOTO 460
810 REM {inv} MOVE TO LAST CARD{/inv}
820 IF KP=KC THEN SOUND 1,200,10,10:SOUND 1,0,0,0:GOTO 460
830 POSITION PT(1,KP)+1,PT(2,KP)+1:? "  ";:SOUND 1,200,10,10:SOUND 1,0,0,0:KP=KC
840 POSITION PT(1,KP)+1,PT(2,KP)+1:? "^";:SOUND 1,200,10,10:SOUND 1,0,0,0:GOTO 460
850 REM {inv} NEXT CARD {/inv}
860 IF KC=ED THEN 550:REM {inv}YOU CANNOT DO THAT{/inv}
870 KC=KC+1:GOTO 360
880 REM {inv} ALL CARDS{/inv}
890 IF KC=ED THEN 550:REM {inv}YOU CANNOT DO THAT{/inv}
900 KC=ED:GOTO 360
910 REM {inv}END GAME{/inv}
920 Z=0:FOR I=1 TO ED:F=INT(DK(I)/100):V=DK(I)-F*100:F1=INT(DK(I-1)/100):V1=DK(I-1)-F1*100
930 IF F=F1 THEN 960
940 IF V=V1 THEN 960
950 GOTO 970
960 Z=1:I=ED
970 NEXT I:IF Z=1 THEN 1060
980 IF ED<4 THEN 1110:REM {inv}SKIP{/inv}
990 FOR I=1 TO ED-3
1000 F=INT(DK(I)/100):V=DK(I)-F*100:F1=INT(DK(I+3)/100):V1=DK(I+3)-F1*100:IF F=F1 THEN 1030
1010 IF V=V1 THEN 1030
1020 GOTO 1040
1030 Z=1:I=ED-2
1040 NEXT I:IF Z=1 THEN 1060
1050 GOTO 1110:REM {inv}FINAL SCORE{/inv}
1060 GRAPHICS 1+16:POSITION 3,4:? #6;"PLEASE RECHECK"
1070 POSITION 5,5:? #6;"YOUR HAND":POSITION 4,6:? #6;"I HAVE FOUND"
1080 POSITION 2,7:? #6;"AT LEAST ONE MORE":POSITION 7,8:? #6;"PLAY!!"
1090 FOR I=1 TO 50:SOUND 1,99,10,10:SOUND 1,0,0,0:NEXT I:FOR QQ=1 TO 400:NEXT QQ:GOTO 360
1100 REM {inv}END OF GAME{/inv}
1110 GRAPHICS 1+16:POSITION 1,2:? #6;"YOU HAVE SUCCEEDED":POSITION 1,3:? #6;"COLLAPSING THE"
1120 POSITION 4,4:? #6;"DECK DOWN TO":POSITION 9,5:? #6;ED:POSITION 7,6:? #6;"CARDS"
1130 IF ED=1 THEN POSITION 4,8:? #6;"none better!":GOTO 1240
1140 IF ED<3 THEN POSITION 5,8:? #6;"fantastic":GOTO 1240
1150 IF ED<5 THEN POSITION 7,8:? #6;"great!":GOTO 1240
1160 IF ED<7 THEN POSITION 4,8:? #6;"you're good":GOTO 1240
1170 IF ED<9 THEN POSITION 6,8:? #6;"not bad":GOTO 1240
1180 IF ED<11 THEN POSITION 0,8:? #6;"You've played before":GOTO 1240
1190 IF ED<15 THEN POSITION 1,8:? #6;"you've got promise":GOTO 1240
1200 IF ED<20 THEN POSITION 4,8:? #6;"keep trying":GOTO 1240
1210 IF ED<25 THEN POSITION 7,8:? #6;"rookie!":GOTO 1240
1220 IF ED<30 THEN POSITION 3,8:? #6;"are you sick?":GOTO 1240
1230 POSITION 7,8:? #6;"novice!"
1240 FOR I=1 TO 300:NEXT I:POSITION 0,10:? #6;"DO YOU WANT TO PLAY":POSITION 7,11:? #6;"AGAIN?";
1250 POKE 752,1:GET #1,Z
1260 IF Z=89 OR Z=121 THEN 280:REM {inv}YES{/inv}
1270 IF Z=78 OR Z=110 THEN POSITION 0,10:? #6;"you CAN'T STAND     ANOTHER CHALLENGE?":REM {inv}END{/inv}
1280 FOR I=1 TO 400:NEXT I:END
1290 GOTO 1250

Download

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

Credits