Two-handed cribbage against the computer, played to 121 with full-size cards drawn in UDGs. Each deal takes thirteen cards from a shuffled pack: six for each player and the cut. While you study your hand, the computer tries all fifteen ways of discarding two of its six cards and keeps the four that rate best, adding or subtracting the value of the discards depending on whose box it is. You then choose your two with the number keys and confirm with Y. A jack cut scores 2 for the dealer, and play to 31 follows, with G for Go and points for fifteen, 31, pairs, runs and last card. The show then counts each hand and the box for fifteens, pairs, runs, flushes and his nobs on a ME/YOU scoreboard, and the deal alternates until someone passes 120. A table of games won is kept between games.
The REM in line 0 reads “CRIBBAGE BY P.ERENTZ” and the title screen reads “by P.A.Erentz”. Two pages of instructions explain the scoring and the box.
Program Analysis
Structure
- Lines 10–130: setup, including the UDG pointer (line 4990) and the instructions (line 4900).
- Lines 140–450: the shuffle and deal. The computer’s six cards are sorted by rank and yours are drawn with the keys 1–6 above them.
- Lines 460–1120: the computer chooses its discards.
- Lines 1130–1340: you choose your discards, and both pairs go into the box.
- Lines 1560–2970: the cut and the play to 31. The computer’s choice of card is at lines 1840–2420 and yours at lines 2650–2970.
- Lines 2980–3290: the show, counting the non-dealer’s hand first, then the dealer’s hand and the box.
- Lines 3310–3570: runs and pairs during play. Lines 4220–4890: scoring a five-card hand. Lines 3760–3910: drawing a card.
Shuffle and Deal
Cards are numbered 1–52, with DEF FN s giving the suit and DEF FN r the rank. Lines 200–260 take thirteen cards one at a time from a shrinking array, each picked at random from those left, which is all a single deal needs.
Choosing Discards
For each of the fifteen pairs, lines 560–950 score the four cards kept with fixed weights: a flush 4.2, a fifteen 2.3 or 2.4, a run of four 5.2, a pair 2.17, plus smaller amounts for near-runs, cards totalling 5 and jacks that might score nobs. Lines 970–1070 score the two discards the same way, and the result is added when the box is the computer’s and subtracted when it is yours. The best split is kept in m().
The Play
When playing a card, the computer gives each legal card a value: points it would score now from fifteen, 31, pairs and runs, less penalties for leaving the count at 5 or 21 or setting up a run or pair for you. On a lead it prefers fours, avoids fives and keeps back cards that combine with the rest of its hand. Runs during play are found by copying the cards played into p(), sorting the most recent ones, and testing ever shorter sequences until one is consecutive.
Counting the Show
The routine at line 4220 sorts the five cards by rank, then tests all ten three-card and all five four-card combinations for runs and fifteens and all ten pairs of cards for fifteens. It handles double runs and full houses, gives 2 for a jack cut and 1 for his nobs, and in the box (lines 3120 and 3260) counts a flush only when all five cards match.
Notable Techniques
- The 21 UDGs (suit symbols, card edges and corners, a one-character 10, and pieces of the court-card faces) are stored as text in the REM at line 5010. Line 5000 points the UDG system variable at 23675–23676 to that REM, using the address of the next line from NXTLIN (23637) plus 6, worked out with
VALon an expression held in a string. - Card faces come from DATA lines 3790–3910 that hold string expressions such as
"u "+s$(s)+" u". These are evaluated when READ, so the current suit symbol is inserted, and anA$item repeats the previous line. PIstands in for the constant 3 in subscripts andATrows, which saves memory compared with a stored number.p$holds the control codes forPAPER 7andINK 0and is printed in front of text to set its colours.- The scoreboard counts up one point at a time with a beep per point.
Potential Issues
- When you press G for Go, line 2710 checks whether you could still play using the card’s rank (11–13 for court cards) rather than its value of 10. With the count at 19–21 and a court card in hand that would still fit, a Go is accepted although a card could be played.
- Line 2260 sets
r2=0where the matching lines use 1, so that small bonus in the computer’s choice of card can be added more than once. It appears to affect only how the computer weighs its cards.
This program came from an Oliger (JLO SAFE) disk in the SNUG library set and was converted to load from tape: the Oliger slash was removed from SAVE / in line 5020. It was tested in ZEsarUX on a stock TS2068 through the instructions, the deal and the “Which two do you want in the box” prompt.
Source Code
0 REM CRIBBAGE BY P.ERENTZ
10 DEF FN h(x)=INT (x/256): DEF FN l(x)=x-256*FN h(x)
20 GO SUB 4990: GO SUB 4900: RANDOMIZE
30 LET gm=0: LET gy=gm
40 LET bo=INT (RND*2)
50 DIM b$(2)
60 LET l$="OK I've chosen. Which two do youwant in the box"
70 LET me=0: LET yo=me
80 DEF FN s(z)=INT ((z-1)/13)
90 DEF FN r(z)=z-13*FN s(z)
100 DIM s$(6): DIM s(6): DIM f(6): DIM r(6): DIM b(6)
110 LET s$="bdac"
120 DIM a(5): DIM m(6)
130 LET bx=bo
140 BORDER 6: PAPER 6: INK 1: CLS
150 IF bx=0 THEN PRINT AT 8,6;p$;" My box, my deal "
160 IF bx=1 THEN PRINT AT 8,6;p$;"Your box, your deal"
170 PRINT AT 10,10; FLASH 1; PAPER 5; INK 1;"SHUFFLING"
180 DIM c(53): DIM d(13)
190 FOR i=1 TO 52: LET c(i)=i: NEXT i
200 FOR i=52 TO 40 STEP -1
210 LET r=INT (i*RND+1)
220 LET d(53-i)=c(r)
230 FOR j=r TO i-1
240 LET c(j)=c(j+1)
250 NEXT j
260 NEXT i
270 BORDER 4: PAPER 4
280 CLS
290 FOR i=1 TO 5
300 FOR j=6 TO i+1 STEP -1
310 IF FN r(d(j))>FN r(d(j-1)) THEN LET d1=d(j-1): LET d(j-1)=d(j): LET d(j)=d1
320 NEXT j
330 NEXT i
340 PAPER 6: INK 0: GO SUB 4060
350 PAPER 7: PRINT AT 6,0;"Please study your hand whilst I choose my two cards for";: IF bx=0 THEN PRINT FLASH 1;" my box "
360 IF bx=1 THEN PRINT FLASH 1;" your box"
370 PAPER 6: LET x=11
380 FOR i=7 TO 12
390 LET s=1+INT ((d(i)-1)/13)
400 LET y=5*i-34
410 LET c(i)=d(i)-s*13+13
420 PRINT AT 10,y+2;p$;i-6
430 LET c=INT ((s-1)/2)*2
440 PAPER 7: INK c: RESTORE 3780+10*c(i): GO SUB 3770
450 NEXT i
460 LET hi=0
470 FOR i=1 TO 5
480 FOR j=6 TO i+1 STEP -1
490 LET aa=1: FOR k=1 TO 6
500 IF k=i THEN GO TO 530
510 IF k=j THEN GO TO 530
520 LET c(aa)=d(k): LET aa=aa+1
530 NEXT k
540 LET c(5)=d(i)
550 LET c(6)=d(j)
560 FOR k=1 TO 6
570 LET s(k)=FN s(c(k))
580 LET r(k)=FN r(c(k))
590 LET f(k)=r(k)
600 IF r(k)>10 THEN LET f(k)=10
610 NEXT k
620 LET p=0
630 IF s(1)=s(2) THEN IF s(2)=s(PI) THEN IF s(PI)=s(4) THEN LET p=p+4.2
640 IF f(1)+f(2)+f(PI)+f(4)=15 THEN LET p=p+2.4: GO TO 690
650 IF f(1)+f(2)+f(PI)=15 THEN LET p=p+2.3
660 IF f(1)+f(2)+f(4)=15 THEN LET p=p+2.3
670 IF f(1)+f(PI)+f(4)=15 THEN LET p=p+2.3
680 IF f(2)+f(PI)+f(4)=15 THEN LET p=p+2.3
690 FOR k=1 TO 4
700 IF r(k)=11 THEN LET p=p+.25
710 NEXT k
720 IF r(1)=r(2)+1 THEN IF r(2)=r(4)+1 THEN LET p=p+11.7: GO TO 890
730 IF r(1)=r(PI)+1 THEN IF r(PI)=r(4)+1 THEN LET p=p+11.7: GO TO 890
740 IF r(1)=r(2)+1 THEN IF r(2)=r(PI)+1 THEN IF r(PI)=r(4)+1 THEN LET p=p+5.2: GO TO 890
750 IF r(2)=r(PI)+1 THEN IF r(PI)=r(4)+1 THEN LET p=p+3.7: GO TO 890
760 IF r(1)=r(2)+1 THEN IF r(2)=r(PI)+1 THEN LET p=p+3.7: GO TO 890
770 IF r(1)=r(4) THEN LET p=p+12: GO TO 890
780 IF r(1)=r(PI) THEN LET p=p+6.13: GO TO 830
790 IF r(2)=r(4) THEN LET p=p+6.13: GO TO 830
800 IF r(1)=r(2) THEN LET p=p+2.17
810 IF r(2)=r(PI) THEN LET p=p+2.17
820 IF r(PI)=r(4) THEN LET p=p+2.17
830 FOR l=1 TO 3
840 IF r(l)<>1 THEN IF r(l)<>12 THEN IF r(l)=r(l+1)+1 THEN LET p=p+.7
850 IF r(l)=2 AND r(l+1)=1 THEN LET p=p+.25
860 IF r(l)=13 AND r(l+1)=12 THEN LET p=p+.25
870 IF r(l)=r(l+1)+2 THEN LET p=p+.25
880 NEXT l
890 FOR l=1 TO 3
900 FOR k=4 TO l+1 STEP -1
910 IF f(k)+f(l)<15 AND f(k)+f(l)>5 THEN LET p=p+.17
920 IF f(k)+f(l)=15 THEN LET p=p+2.3
930 IF f(k)+f(l)=5 THEN LET p=p+.5
940 NEXT k
950 NEXT l
960 LET q=0
970 IF r(5)=r(6) THEN IF r(5)>5 THEN LET q=q+2.6
980 IF r(5)=r(6) THEN IF r(5)<6 THEN LET q=q+2.3
990 IF r(5)-r(6)=1 THEN LET q=q+.7
1000 IF r(5)-r(6)=2 THEN LET q=q+.25
1010 IF s(5)=s(6) THEN LET q=q+.15
1020 IF f(5)+f(6)=15 THEN LET q=q+2.5
1030 IF f(5)+f(6)=5 THEN LET q=q+.5
1040 IF f(5)=5 THEN LET q=q+.5
1050 IF f(6)=5 THEN LET q=q+.5
1060 IF r(5)=11 THEN LET q=q+.25
1070 IF r(6)=11 THEN LET q=q+.25
1080 IF bx=1 THEN LET p=p-q
1090 IF bx=0 THEN LET p=p+q
1100 IF p>hi THEN LET hi=p: FOR k=1 TO 6: LET m(k)=c(k): NEXT k
1110 NEXT j
1120 NEXT i
1130 INPUT ;: PRINT #1;p$;l$;" ?"
1140 PAUSE 0: LET b$(1)=INKEY$: IF b$(1)<"1" OR b$(1)>"6" THEN GO TO 1140
1150 PRINT #1;AT 2,16;p$;b$(1);" and ?"
1160 PRINT AT 10,5*VAL b$(1)-2;p$; FLASH 1;b$(1)
1170 PAUSE 0: LET b$(2)=INKEY$: IF b$(2)<"1" OR b$(2)>"6" THEN GO TO 1170
1180 IF b$(1)=b$(2) THEN GO TO 1170
1190 PRINT #1;AT 2,22;p$;b$(2),
1200 PRINT AT 10,5*VAL b$(2)-2;p$; FLASH 1;b$(2)
1210 PAUSE 50
1220 INPUT ;: PRINT #1; INK 0;"Press Y to continue,N to choose again."
1230 PAUSE 0: LET y$=INKEY$
1240 IF y$="n" THEN PRINT AT 10,5*VAL b$(1)-2;p$; FLASH 0;b$(1): PRINT AT 10,5*VAL b$(2)-2;p$;b$(2): GO TO 1130
1250 IF y$="y" THEN GO TO 1270
1260 GO TO 1230
1270 IF b$(1)="6" THEN LET c$=b$(1): LET b$(1)=b$(2): LET b$(2)=c$
1280 IF b$(2)="5" THEN LET c$=b$(2): LET b$(2)=b$(1): LET b$(1)=c$
1290 PAPER 4: CLS
1300 LET j=VAL b$(1)+6
1310 LET d=d(j): LET d(j)=d(11): LET d(11)=d
1320 LET j=VAL b$(2)+6
1330 LET d=d(j): LET d(j)=d(12): LET d(12)=d
1340 LET x=0: LET y=23: PAPER 6: INK x: GO SUB 4060
1350 PRINT AT PI,31-LEN STR$ yo; PAPER 7;yo
1360 LET x=18
1370 PRINT AT 19,0;p$;"YOUR"'"HAND"
1380 FOR i=7 TO 10
1390 LET s=1+INT ((d(i)-1)/13)
1400 LET y=3*i-16
1410 LET c(i)=d(i)-s*13+13
1420 LET c=INT ((s-1)/2)*2
1430 IF c(i)=1 THEN LET a$="A"
1440 IF c(i)>1 AND c(i)<10 THEN LET a$=STR$ c(i)
1450 IF c(i)=10 THEN LET a$="e"
1460 IF c(i)=11 THEN LET a$="J"
1470 IF c(i)=12 THEN LET a$="Q"
1480 IF c(i)=13 THEN LET a$="K"
1490 PRINT AT x-1,y+1; PAPER 4; INK 0;i-6
1500 PAPER 7: INK c
1510 PRINT AT x,y;"ptq"
1520 PRINT AT x+1,y;"u";a$;"u"
1530 PRINT AT x+2,y;"u";s$(s);"u"
1540 PRINT AT x+3,y;"rts"
1550 NEXT i
1560 PRINT AT 13,28;p$;"THE";AT 14,28;"CUT"
1570 GO SUB 3300
1580 IF r=11 THEN PRINT AT 8,3;p$; FLASH 1;"2 FOR HIS NOB!": PAUSE 150: PRINT AT 8,3; PAPER 4;" "
1590 IF r=11 AND bx=0 THEN LET me=me+2: LET ps=2: GO SUB 4140
1600 IF r=11 AND bx=1 THEN LET yo=yo+2: LET ps=2: GO SUB 4150
1610 FOR i=1 TO 4
1620 LET s(i)=FN s(m(i))+1
1630 LET r(i)=FN r(m(i))
1640 IF r(i)<11 THEN LET f(i)=r(i)
1650 IF r(i)>10 THEN LET f(i)=10
1660 NEXT i
1670 LET pr=0: LET rn=pr: LET myg=pr: LET yog=pr: LET cp=1: LET sc=pr: LET mc=4: LET yc=mc
1680 DIM n(12): DIM q(8): DIM p(8)
1690 IF bx=0 THEN GO TO 2620
1700 LET x=0
1710 IF me>120 OR yo>120 THEN GO TO 3600
1720 IF mc=0 THEN IF yog=0 THEN LET myg=1: GO TO 2620
1730 LET cpl=0: FOR i=1 TO 4
1740 IF n(i)=1 THEN GO TO 1780
1750 LET r=r(i): LET f=f(i)
1760 IF sc+f>31 THEN GO TO 1780
1770 LET cpl=cpl+1
1780 NEXT i
1790 IF cpl=0 THEN IF yog=1 AND yc>0 THEN PRINT AT 8,0; INK 0;"GO for 1 ": LET me=me+1: LET ps=1: GO SUB 4140: GO SUB 3920: GO TO 2620
1800 IF cpl=0 THEN IF yog=1 THEN PRINT AT 8,0; INK 0;"GO for 1 ": LET me=me+1: LET ps=1: GO SUB 4140: GO SUB 3920: GO TO 1710
1810 IF cpl=0 THEN IF yc=0 AND yog=0 THEN PRINT AT 8,0; INK 0;"GO ": PAUSE 100: PRINT AT 8,0;"1 for you ": LET yo=yo+1: LET ps=1: GO SUB 4150: GO SUB 3920: GO TO 1710
1820 IF cpl=0 THEN IF yc=0 THEN PRINT AT 8,0; INK 0;"GO for 1 ": LET me=me+1: LET ps=1: GO SUB 4140: GO SUB 3920: GO TO 1710
1830 IF cpl=0 THEN PRINT AT 8,2; INK 0;" GO ": LET myg=1: GO TO 2620
1840 LET ps=0: LET hi=-100
1850 FOR i=1 TO 4
1860 LET v=0
1870 IF n(i)=1 THEN GO TO 2420
1880 LET s=s(i): LET r=r(i): LET f=f(i)
1890 IF sc+f>31 THEN GO TO 2420
1900 IF cpl=1 THEN GO TO 2410
1910 IF sc=0 THEN GO TO 2290
1920 IF cp>1 THEN LET q(cp)=r: GO SUB 3530: IF pr>0 THEN LET v=v+pr-.1: GO TO 1940
1930 IF cp>2 THEN LET q(cp)=r: LET rn=0: GO SUB 3310: LET v=v+rn
1940 IF f+sc=15 THEN LET v=v+2
1950 IF f+sc=5 THEN LET v=v-1
1960 IF f+sc=31 THEN LET v=v+2
1970 IF f+sc=21 THEN LET v=v-1
1980 IF f+f+sc=15 THEN LET v=v-1
1990 IF f+f+sc=31 THEN LET v=v-1
2000 IF r=13 THEN IF q(cp-1)=12 THEN IF sc<12 THEN LET v=v-0.9: IF sc=11 THEN LET v=v-1: GO TO 2190
2010 IF r=2 THEN IF q(cp-1)=1 THEN IF sc<27 THEN LET v=v-0.9: IF sc=26 THEN LET v=v-1: GO TO 2190
2020 IF r=2 THEN GO TO 2090
2030 IF r=13 THEN GO TO 2100
2040 IF r-q(cp-1)=1 THEN IF sc+f+r-2<32 THEN LET v=v-1.1: IF sc+f+r-2=31 THEN LET v=v-1: GO TO 2190
2050 IF r=12 THEN IF q(cp-1)=13 THEN IF sc<12 THEN LET v=v-.9: IF sc=11 THEN LET v=v-1: GO TO 2190
2060 IF r=1 THEN IF q(cp-1)=2 THEN IF sc<28 THEN LET v=v-0.9: IF sc=27 THEN LET v=v-1: GO TO 2190
2070 IF r=12 THEN GO TO 2110
2080 IF r=1 THEN GO TO 2130
2090 IF q(cp-1)-r=1 THEN IF sc+f+r-1<32 THEN LET v=v-1.1: IF sc+r+f-1=31 THEN LET v=v-1: GO TO 2190
2100 IF r=13 THEN IF q(cp-1)=11 THEN IF sc<12 THEN LET v=v-.9: IF sc=11 THEN LET v=v-1: GO TO 2190
2110 IF r=12 THEN IF q(cp-1)=10 THEN IF sc<12 THEN LET v=v-.9: IF sc=11 THEN LET v=v-1: GO TO 2190
2120 IF r>11 THEN GO TO 2190
2130 IF r-q(cp-1)=2 THEN IF sc+f+r-1<32 THEN LET v=v-0.9: IF sc+f+r-1=31 THEN LET v=v-1
2140 IF r=11 THEN IF q(cp-1)=13 THEN IF sc<12 THEN LET v=v-.9: IF sc=11 THEN LET v=v-1: GO TO 2190
2150 IF r=10 THEN IF q(cp-1)=12 THEN IF sc<12 THEN LET v=v-.9: IF sc=11 THEN LET v=v-1: GO TO 2190
2160 IF r=11 THEN GO TO 2190
2170 IF r=10 THEN GO TO 2190
2180 IF q(cp-1)-r=2 THEN IF sc+f+r+1<32 THEN LET v=v-0.9: IF sc+f+r+1=31 THEN LET v=v-1
2190 IF f<>5 THEN LET v=v+r/100
2200 LET r1=0: LET r2=r1: LET r3=r1
2210 FOR j=1 TO 4
2220 IF n(j)=1 THEN GO TO 2270
2230 IF i=j THEN GO TO 2270
2240 IF r3=0 THEN IF r(i)=r(j) THEN IF sc+3*f(i)<32 THEN LET v=v+.6: LET r3=1: IF sc+3*f(i)=31 THEN LET v=v+.2
2250 IF r1=0 THEN IF sc+10+f+f(j)=31 THEN LET v=v+.5: LET r1=1
2260 IF r2=0 THEN IF sc+f+f(j)=31 THEN LET v=v+.5: LET r2=0
2270 NEXT j
2280 GO TO 2410
2290 IF r=4 THEN LET v=v+yc*0.08
2300 LET v=v+f(i)/1000
2310 IF r=5 THEN LET v=v-yc*1
2320 LET r1=0: LET r2=r1: LET r3=r1
2330 FOR j=1 TO 4
2340 IF n(j)=1 THEN GO TO 2400
2350 IF i=j THEN GO TO 2400
2360 IF r1=0 THEN IF r(i)-r(j)=1 THEN IF r(i)>5 THEN LET v=v+(5-yc)*.1: LET r1=1
2370 IF yc=0 THEN IF f(i)+f(j)=15 THEN LET v=v+2
2380 IF r2=0 THEN IF f(i)+f(j)=5 THEN LET v=v+.5: LET r2=1
2390 IF r3=0 THEN IF r(i)=r(j) THEN LET v=v+.12*yc: LET r3=1
2400 NEXT j
2410 IF v>hi THEN LET hi=v: LET a=s: LET b=r: LET e=f: LET d=i: IF cpl>1 THEN LET rn1=rn: LET pr1=pr
2420 NEXT i
2430 LET sc=sc+e: LET n(d)=1: LET mc=mc-1: LET q(cp)=b: LET x=0: LET y=(3-mc)*5: LET s=a: RESTORE 3780+10*b: GO SUB 3760
2440 IF cpl=1 THEN IF cp>2 THEN LET rn=0: GO SUB 3310: LET ps=ps+rn
2450 IF cpl=1 THEN IF cp>1 THEN LET pr=0: GO SUB 3530: LET ps=ps+pr
2460 IF cpl>1 THEN IF cp>2 THEN LET ps=ps+rn1
2470 IF cpl>1 THEN IF cp>1 THEN LET ps=ps+pr1
2480 IF sc=15 THEN LET ps=ps+2
2490 IF sc=31 THEN LET ps=ps+2
2500 LET cp=cp+1
2510 IF sc<31 THEN IF mc=0 AND yc=0 THEN LET ps=ps+1: GO TO 2530
2520 IF sc<31 THEN IF mc=0 AND yog=1 THEN LET ps=ps+1
2530 INK 0: PRINT AT 8,0;" ": PRINT AT 8,0;sc;: IF ps>0 THEN PRINT ;" for ";ps;" "
2540 IF ps>0 THEN LET me=me+ps: GO SUB 4140
2550 IF mc=0 THEN IF yc=0 THEN GO TO 2980
2560 IF sc<31 AND yog=1 THEN IF mc=0 THEN GO SUB 3920: GO TO 2620
2570 IF sc<31 AND yog=1 THEN GO TO 1710
2580 IF sc<31 AND yc>0 THEN GO TO 2620
2590 IF sc<31 THEN LET yog=1: GO TO 1710
2600 IF sc=31 AND yc>0 THEN GO SUB 3920: GO TO 2620
2610 IF sc=31 THEN GO SUB 3920: GO TO 1710
2620 IF me>120 OR yo>120 THEN GO TO 3600
2630 IF mc=0 AND yc=0 THEN GO TO 2980
2640 IF yc=0 THEN LET yog=1: GO TO 1710
2650 PRINT #0; PAPER 4; INK 0;"Your turn-which card? (G for GO)": PAUSE 0
2660 LET w$=INKEY$: INPUT "": PAUSE 1
2670 IF w$<>"g" THEN IF w$<>"1" THEN IF w$<>"2" THEN IF w$<>"3" THEN IF w$<>"4" THEN GO TO 2650
2680 IF w$<>"g" THEN GO TO 2750
2690 FOR i=7 TO 10
2700 IF n(i)=1 THEN GO TO 2720
2710 IF sc+FN r(d(i))<32 THEN GO TO 2650
2720 NEXT i
2730 IF myg=0 THEN LET yog=1: PRINT AT 8,2; INK 0;" GO ": GO TO 1710
2740 IF myg=1 THEN PRINT AT 8,0; INK 0;"GO for 1 ": LET ps=1: LET yo=yo+1: GO SUB 4150: GO SUB 3920: GO TO 1710
2750 LET w=VAL w$+6
2760 IF n(w)=1 THEN GO TO 2650
2770 LET ps=0
2780 LET s=FN s(d(w))+1: LET r=FN r(d(w))
2790 LET f=r: IF f>10 THEN LET f=10
2800 IF sc+f>31 THEN GO TO 2650
2810 LET n(w)=1
2820 LET y=(w-6)*3+2: PAPER 4: GO SUB 4160
2830 LET x=10: LET y=(4-yc)*5: PAPER 7: RESTORE 3780+10*r: GO SUB 3760
2840 LET sc=sc+f: IF sc=15 OR sc=31 THEN LET ps=ps+2
2850 LET q(cp)=r
2860 IF cp>1 THEN LET pr=0: GO SUB 3530: LET ps=ps+pr: IF pr>0 THEN GO TO 2880
2870 IF cp>2 THEN LET rn=0: GO SUB 3310: LET ps=ps+rn
2880 LET cp=cp+1: LET yc=yc-1
2890 IF sc<31 THEN IF mc=0 AND yc=0 THEN LET ps=ps+1: GO TO 2910
2900 IF sc<31 THEN IF myg=1 AND yc=0 THEN LET ps=ps+1
2910 INK 0: PRINT AT 8,0;" ": PRINT AT 8,0;sc;: IF ps>0 THEN PRINT ;" for ";ps;" "
2920 IF ps>0 THEN LET yo=yo+ps: GO SUB 4150
2930 IF mc=0 THEN IF yc=0 THEN GO TO 2980
2940 IF myg=1 THEN IF sc<31 AND yc=0 THEN GO SUB 3920: GO TO 1710
2950 IF myg=1 THEN IF sc<31 THEN GO TO 2620
2960 IF sc<31 THEN GO TO 1710
2970 IF sc=31 THEN GO SUB 3920: GO TO 1710
2980 IF me>120 OR yo>120 THEN GO TO 3600
2990 PAUSE 50: GO SUB 3930: PAPER 4: CLS
3000 GO SUB 3300
3010 PAPER 6: INK 0: GO SUB 4060
3020 IF bx=0 THEN GO TO 3170
3030 FOR i=1 TO 4: LET a(i)=m(i): LET a(5)=d(13): NEXT i: LET x=5: GO SUB 4220: LET to=pr+nb+ft+rn+st: PRINT AT 4,0; INK 0;"My hand scores ";to
3040 LET ps=to: LET me=me+to
3050 GO SUB 4140: IF me>120 THEN GO TO 3580
3060 GO SUB 4980: PAPER 4: CLS
3070 GO SUB 3300
3080 PAPER 6: INK 0: GO SUB 4060
3090 LET a(1)=d(7): LET a(2)=d(8): LET a(PI)=d(9): LET a(4)=d(10): LET a(5)=d(13): LET x=5: GO SUB 4220: LET to=pr+nb+ft+rn+st: PRINT AT 4,0; INK 0;"Your hand scores ";to
3100 LET ps=to: LET yo=yo+to
3110 PAPER 6: INK 0: GO SUB 4150: IF yo>120 THEN GO TO 3590
3120 LET a(1)=d(11): LET a(2)=d(12): LET a(PI)=m(5): LET a(4)=m(6): LET a(5)=d(13): LET x=15: GO SUB 4220: LET st=5*(INT (st/5)): LET to=pr+nb+ft+rn+st: PRINT AT 14,0; INK 0;"Your box scores ";to
3130 LET ps=to: LET yo=yo+to
3140 PAPER 6: INK 0: GO SUB 4150: IF yo>120 THEN GO TO 3590
3150 GO SUB 4980
3160 LET bx=0: GO TO 140
3170 LET a(1)=d(7): LET a(2)=d(8): LET a(PI)=d(9): LET a(4)=d(10): LET a(5)=d(13): LET x=5: GO SUB 4220: LET to=pr+nb+ft+rn+st: PRINT AT 4,0; INK 0;"Your hand scores ";to
3180 LET ps=to: LET yo=yo+to
3190 PAPER 7: INK 0: GO SUB 4150: IF yo>120 THEN GO TO 3590
3200 GO SUB 4980: PAPER 4: CLS
3210 PAPER 6: INK 0: GO SUB 4060
3220 GO SUB 3300
3230 FOR i=1 TO 4: LET a(i)=m(i): LET a(5)=d(13): NEXT i: LET x=5: GO SUB 4220: LET to=pr+nb+ft+rn+st: PRINT AT 4,0; INK 0;"My hand scores ";to
3240 LET ps=to: LET me=me+to
3250 PAPER 7: GO SUB 4140: IF me>120 THEN GO TO 3580
3260 LET a(1)=d(11): LET a(2)=d(12): LET a(PI)=m(5): LET a(4)=m(6): LET a(5)=d(13): LET x=15: GO SUB 4220: LET st=5*(INT (st/5)): LET to=pr+nb+ft+rn+st: PRINT AT 14,0; INK 0;"My box scores ";to
3270 LET ps=to: LET me=me+to
3280 PAPER 7: GO SUB 4140: IF me>120 THEN GO TO 3580
3290 GO SUB 4980: LET bx=1: GO TO 140
3300 LET s=1+FN s(d(13)): LET r=FN r(d(13)): LET x=15: LET y=27: PAPER 7: RESTORE 3780+10*r: GO SUB 3760: RETURN
3310 IF ABS (q(cp)-q(cp-1))>cp-1 THEN RETURN
3320 IF ABS (q(cp)-q(cp-2))>cp-1 THEN RETURN
3330 IF ABS (q(cp-1)-q(cp-2))>cp-1 THEN RETURN
3340 IF q(cp)=q(cp-1) THEN RETURN
3350 IF q(cp)=q(cp-2) THEN RETURN
3360 IF q(cp-1)=q(cp-2) THEN RETURN
3370 LET rn=0
3380 FOR j=1 TO cp-2
3390 FOR k=1 TO 8
3400 LET p(k)=q(k)
3410 NEXT k
3420 FOR k=cp-1 TO j STEP -1
3430 FOR l=j TO k
3440 IF p(l)<p(l+1) THEN LET ap=p(l): LET p(l)=p(l+1): LET p(l+1)=ap
3450 NEXT l
3460 NEXT k
3470 LET rn=0
3480 FOR k=j TO cp-1: IF p(k)=p(k+1)+1 THEN LET rn=rn+1: NEXT k
3490 IF rn=cp-j THEN LET rn=rn+1: RETURN
3500 LET rn=0
3510 NEXT j
3520 RETURN
3530 LET pr=0
3540 IF q(cp)=q(cp-1) THEN LET pr=pr+2
3550 IF cp>2 THEN IF q(cp)=q(cp-1) THEN IF q(cp-1)=q(cp-2) THEN LET pr=pr+4
3560 IF cp>3 THEN IF q(cp)=q(cp-1) THEN IF q(cp-1)=q(cp-2) THEN IF q(cp-2)=q(cp-3) THEN LET pr=pr+6
3570 RETURN
3580 PAPER 7: INK 0: IF me>120 THEN PRINT AT 12,0; FLASH 1;"GAME OVER-I've won "'" PRESS A KEY ": PAUSE 0: LET gm=gm+1: CLS : GO TO 3630
3590 PAPER 7: INK 0: IF yo>120 THEN PRINT AT 12,0; FLASH 1;"GAME OVER-you've won"'" PRESS A KEY ": PAUSE 0: LET gy=gy+1: CLS : GO TO 3620
3600 PAPER 7: INK 0: IF me>120 THEN PRINT AT 8,0; FLASH 1;"GAME OVER-I've won "'" PRESS A KEY ": PAUSE 0: LET gm=gm+1: CLS : GO TO 3630
3610 IF yo>120 THEN PRINT AT 8,0; FLASH 1;"GAME OVER-you've won"'" PRESS A KEY ": PAUSE 0: LET gy=gy+1: CLS
3620 PRINT "You've won by ";121-me: GO TO 3640
3630 PRINT "I've won by ";121-yo
3640 PAPER 6: INK 0: PRINT AT 1,7;"ptttttttttttttttq"'AT 2,7;;"u OVERALL SCORE u"'AT PI,7;"utttttttttttttttu"
3650 PRINT AT 4,7;"u ME "; PAPER 7;" "; PAPER 6;" GAME ";: IF gm<>1 THEN PRINT AT 4,20;;"S"
3660 PRINT AT 4,23;"u": PRINT AT 5,7;"u YOU "; PAPER 7;" "; PAPER 6;" GAME ";: IF gy<>1 THEN PRINT AT 5,20;"S"
3670 PRINT AT 5,23;"u": PRINT AT 4,15-LEN (STR$ gm); PAPER 7;gm
3680 PRINT AT 5,15-LEN (STR$ gy); PAPER 7;gy
3690 PRINT AT 6,7;"rttttttttttttttts"
3700 LET bo=ABS (bo-1)
3710 PRINT AT 12,0; PAPER 8; INK 9;" Press P to play again or Press I for Instructions or Press S to STOP "
3720 LET a$=INKEY$: IF a$="i" OR a$="I" THEN GO SUB 4900: GO TO 3710
3730 IF a$="p" OR a$="P" THEN GO TO 70
3740 IF a$="s" OR a$="S" THEN STOP
3750 GO TO 3720
3760 INK INT ((s-1)/2)*2
3770 FOR k=1 TO 5: READ a$: PRINT AT x+k,y;a$: NEXT k
3780 PRINT AT x,y;"ptttq";AT x+6,y;"rttts": RETURN
3790 DATA "uA u","u u","u "+s$(s)+" u","u u","u Au"
3800 DATA "u2 u","u "+s$(s)+" u","u u","u "+S$(S)+" u","u 2u"
3810 DATA "u3 u","u "+s$(s)+" u",A$,A$,"u 3u"
3820 DATA "u4 u","u"+s$(s)+" "+s$(s)+"u","u u","u"+S$(S)+" "+S$(S)+"u","u 4u"
3830 DATA "u5 u","u"+s$(s)+" "+s$(s)+"u","u "+S$(S)+" u","u"+S$(S)+" "+S$(S)+"u","u 5u"
3840 DATA "u6 u","u"+s$(s)+" "+s$(s)+"u",A$,A$,"u 6u"
3850 DATA "u7 u","u"+S$(S)+" "+S$(S)+"u","u"+s$(s)+s$(s)+s$(s)+"u","u"+S$(S)+" "+S$(S)+"u","u 7u"
3860 DATA "u8 u","u"+s$(s)+s$(s)+s$(s)+"u","u"+S$(S)+" "+S$(S)+"u","u"+S$(S)+S$(S)+S$(S)+"u","u 8u"
3870 DATA "u9 u","u"+s$(s)+s$(s)+s$(s)+"u",A$,A$,"u 9u"
3880 DATA "ue"+S$(S)+" u","u"+s$(s)+s$(s)+s$(s)+"u","u"+S$(S)+" "+S$(S)+"u","u"+S$(S)+S$(S)+S$(S)+"u","u "+S$(S)+"eu"
3890 DATA "uJ"+s$(s)+" u","ufghu","uijku","ulmnu","u "+S$(S)+"Ju"
3900 DATA "uQ"+s$(s)+" u","ufohu","uijku","ulmnu","u "+S$(S)+"Qu"
3910 DATA "uK"+s$(s)+" u","ufghu","uijku","ulmnu","u "+S$(S)+"Ku"
3920 LET sc=0: LET yog=sc: LET myg=sc: LET cp=1: DIM p(8): DIM q(8)
3930 LET x=0
3940 FOR i=3-mc TO 0 STEP -1
3950 LET y=i*5: GO SUB 4020
3960 NEXT i
3970 LET x=10
3980 FOR i=3-yc TO 0 STEP -1
3990 LET y=i*5: GO SUB 4020
4000 NEXT i
4010 RETURN
4020 PRINT PAPER 1; INK 5;AT x,y;"ptttq"
4030 FOR k=1 TO 5: PRINT AT x+k,y; PAPER 1; INK 5;"u'.'.'.u": NEXT k
4040 PRINT PAPER 1; INK 5;AT x+6,y;"rttts"
4050 RETURN
4060 LET x=0: LET y=23: PRINT AT x,y;"ptttttttq"
4070 PRINT AT x+1,y;"uME "; PAPER 7;" "; PAPER 6;"u"
4080 PRINT AT x+2,y;"u u"
4090 PRINT AT x+3,y;"uYOU "; PAPER 7;" "; PAPER 6;"u"
4100 PRINT AT x+4,y;"rttttttts"
4110 PRINT AT 1,31-LEN STR$ me; PAPER 7;me
4120 PRINT AT PI,31-LEN STR$ yo; PAPER 7;yo
4130 RETURN
4140 FOR k=ps-1 TO 0 STEP -1: BEEP .1,-10: PRINT AT 1,31-LEN STR$ (me-k);p$;me-k: NEXT k: RETURN
4150 FOR k=ps-1 TO 0 STEP -1: BEEP .1,10: PRINT AT PI,31-LEN STR$ (yo-k);p$;yo-k: NEXT k: RETURN
4160 PRINT AT 18,y;" "
4170 PRINT AT 19,y;" "
4180 PRINT AT 20,y;" "
4190 PRINT AT 21,y;" "
4200 PRINT AT 17,y;" "
4210 RETURN
4220 LET pr=0: LET rn=pr: LET st=pr: LET ft=pr: LET nb=pr
4230 FOR i=1 TO 5
4240 LET s(i)=INT ((a(i)-1)/13)+1
4250 LET r(i)=a(i)-13*(s(i)-1)
4260 IF r(i)<11 THEN LET f(i)=r(i)
4270 IF r(i)>10 THEN LET f(i)=10
4280 NEXT i
4290 IF s(1)=s(2) THEN IF s(2)=s(PI) THEN IF s(PI)=s(4) THEN LET st=4: IF s(4)=s(5) THEN LET st=5
4300 FOR i=1 TO 4
4310 IF r(i)=11 THEN IF s(i)=s(5) THEN LET nb=1
4320 NEXT i
4330 FOR i=1 TO 4
4340 LET y=i*5-5: LET s=s(i): PAPER 7: RESTORE 3780+10*r(i): GO SUB 3760
4350 NEXT i
4360 FOR j=4 TO 1 STEP -1
4370 FOR i=1 TO j
4380 IF r(i)<r(i+1) THEN LET r=r(i): LET s=s(i): LET f=f(i): LET r(i)=r(i+1): LET s(i)=s(i+1): LET f(i)=f(i+1): LET r(i+1)=r: LET s(i+1)=s: LET f(i+1)=f
4390 NEXT i
4400 NEXT j
4410 IF r(1)=r(2)+1 THEN IF r(2)=r(PI)+1 THEN IF r(PI)=r(4)+1 THEN IF r(4)=r(5)+1 THEN LET rn=5: GO TO 4580
4420 IF r(1)=r(2)+1 THEN IF r(2)=r(PI)+1 THEN IF r(PI)=r(4)+1 THEN LET rn=rn+4
4430 IF r(1)=r(2)+1 THEN IF r(2)=r(PI)+1 THEN IF r(PI)=r(5)+1 THEN LET rn=rn+4
4440 IF r(1)=r(2)+1 THEN IF r(2)=r(4)+1 THEN IF r(4)=r(5)+1 THEN LET rn=rn+4
4450 IF r(1)=r(PI)+1 THEN IF r(PI)=r(4)+1 THEN IF r(4)=r(5)+1 THEN LET rn=rn+4
4460 IF r(2)=r(PI)+1 THEN IF r(PI)=r(4)+1 THEN IF r(4)=r(5)+1 THEN LET rn=rn+4
4470 IF rn>0 THEN GO TO 4580
4480 IF r(1)=r(2)+1 THEN IF r(2)=r(PI)+1 THEN LET rn=rn+3
4490 IF r(1)=r(2)+1 THEN IF r(2)=r(4)+1 THEN LET rn=rn+3
4500 IF r(1)=r(2)+1 THEN IF r(2)=r(5)+1 THEN LET rn=rn+3
4510 IF r(1)=r(PI)+1 THEN IF r(PI)=r(4)+1 THEN LET rn=rn+3
4520 IF r(1)=r(PI)+1 THEN IF r(PI)=r(5)+1 THEN LET rn=rn+3
4530 IF r(1)=r(4)+1 THEN IF r(4)=r(5)+1 THEN LET rn=rn+3
4540 IF r(2)=r(PI)+1 THEN IF r(PI)=r(4)+1 THEN LET rn=rn+3
4550 IF r(2)=r(PI)+1 THEN IF r(PI)=r(5)+1 THEN LET rn=rn+3
4560 IF r(2)=r(4)+1 THEN IF r(4)=r(5)+1 THEN LET rn=rn+3
4570 IF r(PI)=r(4)+1 THEN IF r(4)=r(5)+1 THEN LET rn=rn+3
4580 IF r(1)=r(4) THEN LET pr=12: GO TO 4680
4590 IF r(2)=r(5) THEN LET pr=12: GO TO 4680
4600 IF r(1)=r(PI) THEN IF r(4)=r(5) THEN LET pr=8: GO TO 4680
4610 IF r(1)=r(2) THEN IF r(PI)=r(5) THEN LET pr=8: GO TO 4680
4620 FOR i=1 TO 3
4630 IF r(i)=r(i+2) THEN LET pr=6: GO TO 4680
4640 NEXT i
4650 FOR i=1 TO 4
4660 IF r(i)=r(i+1) THEN LET pr=pr+2
4670 NEXT i
4680 IF f(1)+f(2)+f(PI)+f(4)+f(5)=15 THEN LET ft=2: GO TO 4890
4690 IF f(1)+f(2)+f(PI)+f(4)=15 THEN LET ft=ft+2
4700 IF f(1)+f(2)+f(PI)+f(5)=15 THEN LET ft=ft+2
4710 IF f(1)+f(2)+f(4)+f(5)=15 THEN LET ft=ft+2
4720 IF f(1)+f(PI)+f(4)+f(5)=15 THEN LET ft=ft+2
4730 IF f(2)+f(PI)+f(4)+f(5)=15 THEN LET ft=ft+2
4740 IF f(1)+f(2)+f(PI)=15 THEN LET ft=ft+2
4750 IF f(1)+f(2)+f(4)=15 THEN LET ft=ft+2
4760 IF f(1)+f(2)+f(5)=15 THEN LET ft=ft+2
4770 IF f(1)+f(PI)+f(5)=15 THEN LET ft=ft+2
4780 IF f(1)+f(PI)+f(4)=15 THEN LET ft=ft+2
4790 IF f(1)+f(5)+f(4)=15 THEN LET ft=ft+2
4800 IF f(2)+f(PI)+f(4)=15 THEN LET ft=ft+2
4810 IF f(2)+f(PI)+f(5)=15 THEN LET ft=ft+2
4820 IF f(2)+f(4)+f(5)=15 THEN LET ft=ft+2
4830 IF f(PI)+f(4)+f(5)=15 THEN LET ft=ft+2
4840 FOR i=1 TO 4
4850 FOR j=i+1 TO 5
4860 IF f(i)+f(j)=15 THEN LET ft=ft+2
4870 NEXT j
4880 NEXT i
4890 RETURN
4900 BORDER 7: PAPER 7: INK 9: CLS : PRINT AT 1,8; INK 2;"pttttttttttttttq";AT 2,8; INK 2;"u"; INK 2;"a"; INK 0;"b"; INK 1;" CRIBBAGE "; INK 2;"c"; INK 0;"d"; INK 2;"u";AT PI,8; INK 2;"rtttttttttttttts";AT 5,9; INK 0;"by P.A.Erentz"
4910 PRINT '"You play against the computer. Cards score twice- First in playand again in the final count. Every combination totaling 15 scores 2. Pairs score 2, trebles6, and four of a kind 12. Runs score the number of cards in therun, and need not be played in sequence. A flush only counts inthe final show of the hand."''"The scoring will be done by the computer, you will be pleased tohear!"
4920 GO SUB 4980
4930 CLS : PRINT "You contribute 2 of your 6 cardsto the 'box', an extra hand thatscores for each player in alter-ation."''"During play you select a card bypressing the number appearing above it. If you cannot play a legal card then press 'G' for 'Go'. The running total of cardsplayed must not exceed 31. If both players 'Go' than the last to play scores 1, unless exactly31 is reached, which scores 2. The total goes back to zero and play continues till all cards have been played."
4940 PRINT '"An extra card is cut which can be combined with any hand in thefinal show. If it's a Jack it scores 2. First to 121 wins."
4950 LET p$=CHR$ 17+CHR$ 7+CHR$ 16+CHR$ 0
4960 PRINT #0; FLASH 1;p$;" PRESS ANY KEY TO BEGIN",: PAUSE 0: CLS
4970 RETURN
4980 PRINT #0;" Press a Key": PAUSE 0: RETURN
4990 REM POKE UDGs
5000 LET x=VAL "(PEEK 23637+PEEK 23638*256)+6": POKE 23675,FN l(x): POKE 23676,FN h(x): RETURN
5010 REM 6***>k*k>*>>**kLRRRRL COPY COPY RETURN m!USR @ CHR$ $( : : : :ephIII.'.'l$$$' COPY DATA CODE ''mm LIST COPY
5020 CLEAR : SAVE /"Cribbage" LINE 10Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

