10 '___initialization 20 MAXFILES=2:DEFINTA-Z:DEFUSR1=342:DIMD(52):DIMP1(52):DIMP2(52):DIMTA(52):DIMDU(52) 30 MU=1:BL=1 40 IFBL<>0THENCALLNETBLOAD("http://www.gr8bit.ru:80/software/basic/durak/durak0.dat") 50 COLOR15,1,1:SCREEN 2,2:OPEN"grp:"AS#1:RESTORE380:A$="":FORI=0TO7:READA:A$=A$+CHR$(A):NEXTI:FORI=0TO23:A$=A$+CHR$(0):NEXTI:SPRITE$(0)=A$ 60 RESTORE2120:FORI=1TO2:A$="":FORJ=0TO31:READA:A$=A$+CHR$(A):NEXTJ:SPRITE$(I)=A$:NEXTI 70 RESTORE2120:FORI=3TO4:A$="":FORJ=0TO15:READA:A$=CHR$(A)+A$:NEXTJ:B$="":FORJ=0TO15:READA:B$=CHR$(A)+B$:NEXTJ:SPRITE$(I)=A$+B$:NEXTI 80 RESTORE2140:FORI=5TO7:A$="":FORJ=0TO31:READA:A$=A$+CHR$(A):NEXTJ:SPRITE$(I)=A$:NEXTI 90 '___main startup screen 95 CLS 100 RESTORE 390:L=0:C=RND(-TIME) 120 READ A:IFA=-1THEN150 130 C=RND(1)*4:IFC=4THENC=3 140 GOSUB300:GOTO120 150 READ A:IFA=-2THEN170ELSE160 160 L=L+A*8:GOTO120 170 PSET(64,80),1:PRINT#1,"DURAK (The Fool)":PSET(20,90),1:PRINT#1,"Russian strategic card game" 180 PSET(32,128),1:PRINT#1,"Single player":PSET(32,144),1:PRINT#1,"Play with network opponent":P=0:S=0 190 PSET(32,160),1:PRINT#1,"Game instructions" 200 LINE(0,180)-(255,180),2:PSET(4,184),1:PRINT#1,"Eugeny Brychkov 2018 for GR8NET" 210 '___main menu selection 220 A=USR1(0):ONINTERVAL=10GOSUB360:IFMU=1THENCALLNETPLAYBUFA(2,&H7938,448596!):CALLNETPLAYBUFP(8,8000) 230 INTERVALON 240 A$=INKEY$:IFA$=""THEN240 250 A=ASC(A$):IFA=31THENP=(P+1)MOD3:GOTO350 260 IFA=30THENP=(P+2)MOD3:GOTO350 270 IFA<>32THEN240 280 INTERVALOFF:ONINTERVAL=100GOSUB370:IFMU=1THENCALLNETPLAYBUFR 290 PUTSPRITE0,(0,224),0,0:ONPGOTO440,1670:GOTO450 300 Z=C*34+20952:P=Z\8192:M=24576+Z-P*8192 310 CALLNETBITOV(P,M,0,A*8+L) 320 Z=(C+4)*34+20952:P=Z\8192:M=24576+Z-P*8192 330 CALLNETBITOV(P,M,0,&H2000+A*8+L) 340 RETURN 350 S=1:INTERVALOFF:ONINTERVAL=10GOSUB360:INTERVALON:GOSUB360:GOTO240 360 PUTSPRITE0,(20,127+P*16),S*10,0:S=1-S:IFMU=1THENCALLNETPLAYBUFC 370 RETURN 380 DATA 24,28,254,255,255,254,28,24 390 DATA 1,33,65,97,129,161,193,0,1,2,35,68,100,132,163,194,193,192,-1,7 400 DATA 0,32,64,96,128,160,193,194,163,131,99,67,35,3,-1,6 410 DATA 0,32,64,96,128,160,192,1,2,35,67,98,97,130,163,195,-1,6 420 DATA 2,33,64,96,128,160,192,35,68,100,132,164,196,129,130,131,-1,7 430 DATA 0,32,64,96,128,160,192,4,35,66,97,130,163,196,-1,-2 440 GOTO220:A$=INPUT$(1):STOP 450 '___play with yourself:options 460 LINE(0,0)-(255,175),1,BF:PSET(80,0):PRINT#1,"Game options":PSET(81,0):PRINT#1,"Game options" 470 V=64:RESTORE1510:GOSUB1470:V=384:GOSUB1470:PSET(152,48),1:PRINT#1,"52-card deck":PSET(152,128),1:PRINT#1,"36-card deck":P=0:A=USR1(0) 480 LINE(150,46+P*80)-(250,58+P*80),10,B:LINE(150,46+(1-P)*80)-(250,58+(1-P)*80),0,B 490 A$=INKEY$:IFA$=""THEN490 500 A=ASC(A$):IFA=31ORA=30THENP=1-P:GOTO480 510 IFA<>32THEN490 520 '___play with yourself:dealing 530 LINE(0,0)-(255,175),1,BF:CALLNETBITOV(57,29068,0,256):CALLNETBITOV(58,26510,0,8448) 540 IFP=0THENNC=51ELSENC=35 550 IFMU=1THENCALLNETPLAYBUFA(58,32144,157502!):ONINTERVAL=40GOSUB1460:CALLNETPLAYBUFP(8,8000) 560 INTERVALON:A=USR1(0):FORG=0TO1 570 GOSUB1590:GOSUB1410:IFA<>0THEN610 580 Q=(NC+1)\4:Q1=16-Q-1:V=160+Q1:FORI=0TO3:FORJ=0TOQ-1:A=D(J+I*Q):GOSUB1530:V=V+2:NEXTJ:V=(V\32+2)*32+Q1:NEXTI:GOSUB1410:IFA<>0THEN610 590 V=160+Q1:FORI=0TO3:FORJ=0TOQ-1:A=52:GOSUB1530:V=V+2:NEXTJ:V=(V\32+2)*32+Q1:NEXTI:GOSUB1410:IFA<>0THEN610 600 NEXT G 610 INTERVALOFF:ONINTERVAL=100GOSUB370:A=USR1(0) 620 '___game screen display 630 GOSUB1590:PR=NC+1:P1=6:P2=6:TA=0:PL=0:'cards in prikup, player1 and 2, and on table, player1 starts 640 FORI=0TO5:P1(I)=D(PR-I-1):NEXTI:FORI=0TO5:P2(I)=D(PR-I-7):NEXTI:KO=D(0):PR=PR-12 650 PL=0 660 CLS:CALLNETBITOV(57,29068,0,256):CALLNETBITOV(58,26510,0,8448):IFPR>0THENA=KO:V=291:GOSUB1530 670 PSET(4,52),6:PRINT#1,"2":PSET(4,132),6:PRINT#1,"1" 680 IFPR>1THENA=53:V=354:GOSUB1530 690 GOSUB1280 700 '___check for turn end condition 710 IFTA=0THEN820:'no cards on table yet 720 IFPL=0THENFORI=0TOP1-1:DU(I)=P1(I):NEXTI:XS=P1ELSEFORI=0TOP2-1:DU(I)=P2(I):NEXTI:XS=P2 730 IF(TAAND1)=1THEN770:'defender's move starts 740 IFXS=0THENGOSUB1190:GOTO660:'attacker is out of cards 750 FORI=0TOTA-1:A=TA(I):FORJ=0TOXS-1:IF(AMOD13)=(DU(J)MOD13)THEN820 760 NEXTJ:NEXTI:COLOR10:LINE(8,96)-(71,115),1,BF:LINE(8,96)-(71,115),10,B:PSET(16,98),1:PRINT#1,"Attack":PSET(20,106),1:PRINT#1,"ended":COLOR15:A$=INPUT$(1):GOTO1130 770 KM=KO\13:KV=KOMOD13:A=TA(TA-1):AM=A\13:AO=AMOD13:FORI=0TOXS-1:MM=DU(I)\13:MO=DU(I)MOD13 780 IFAM=KMTHENIF(MM=KM)AND(MO>AO)THEN820ELSE810 790 IFMM=KMTHEN820 800 IF(AM=MM)AND(MO>AO)THEN820 810 NEXTI:COLOR10:LINE(8,96)-(71,115),1,BF:LINE(8,96)-(71,115),10,B:PSET(12,98),1:PRINT#1,"Defence":PSET(16,106),1:PRINT#1,"failed":COLOR15:A$=INPUT$(1):GOTO1150 820 '___check for end of the game condition 830 IFPR<>0THEN870 840 IFP1=0ANDP2=0THENLINE(8,96)-(71,115),1,BF:LINE(8,96)-(71,115),10,B:PSET(24,104),1:PRINT#1,"DRAW":COLOR15:A$=INPUT$(1):GOTO90 850 IFP1=0THENCOLOR10:LINE(8,96)-(71,115),1,BF:LINE(8,96)-(71,115),10,B:PSET(16,98),1:PRINT#1,"WINNER":PSET(12,106),1:PRINT#1,"Player1":COLOR15:A$=INPUT$(1):GOTO90 860 IFP2=0THENCOLOR10:LINE(8,96)-(71,115),1,BF:LINE(8,96)-(71,115),10,B:PSET(16,98),1:PRINT#1,"WINNER":PSET(12,106),1:PRINT#1,"Player2":COLOR15:A$=INPUT$(1):GOTO90 870 Q=0:IFPL=0THENXS=S1:XD=D1:XP=P1ELSEXS=S2:XD=D2:XP=P2 880 PE=0:PUTSPRITE5,(0,224),1,5:PUTSPRITE6,(0,224),7,6:IFTA=0THEN900 890 PE=1:IF(TAAND1)=0THENPUTSPRITE5,(32,96),1,5:PUTSPRITE6,(32,96),7,6:ELSEPUTSPRITE5,(32,96),1,7:PUTSPRITE6,(32,96),13,6 900 IFQ=-1THENPUTSPRITE1,(38,105),1,1:PUTSPRITE2,(38,105),11,2:GOTO920 910 IFPL=1THENPUTSPRITE1,((XS+XD*Q)*8-2,40),1,1:PUTSPRITE2,((XS+XD*Q)*8-2,40),11,2ELSEPUTSPRITE1,((XS+XD*Q+2)*8-18,134),1,3:PUTSPRITE2,((XS+XD*Q+2)*8-18,134),11,4 920 A=USR1(0) 930 A$=INKEY$:IFA$=""THEN930 940 A=ASC(A$):IFA=28THENQ=Q+1:IFQ>XP-1THENIFPE=1THENQ=-1ELSEQ=0 950 IFA=29THENQ=Q-1:IF((PE=0)AND(Q<0))OR((PE=1)AND(Q<-1))THENQ=XP-1 960 IFA<>32THEN900 970 PUTSPRITE1,(0,224),1,1:PUTSPRITE2,(0,224),1,2:PUTSPRITE5,(0,224),1,5:PUTSPRITE6,(0,224),7,6 980 IF(TAAND1)=1THEN1060 990 '_check for appropriate attack card 1000 IFQ=-1THEN1130ELSEIFPL=0THENA=P1(Q)ELSEA=P2(Q) 1010 IFTA=0THEN1040 1020 AO=AMOD13:FORI=0TOTA-1:IF(TA(I)MOD13)=AOTHEN1040 1030 NEXTI:GOTO1090:'not valid attack card 1040 TA(TA)=A:TA=TA+1:GOSUB1250:PL=1-PL:GOTO660 1050 '___defender's move 1060 IFQ=-1THEN1150ELSEIFPL=0THENA=P1(Q)ELSEA=P2(Q):'take cards 1070 MO=TA(TA-1):MM=MO\13:MA=A\13:IFMA=MMTHEN1100:'check for card's value 1080 KM=KO\13:IFMA=KMTHEN1110:'trump beats card 1090 FORI=0TO19:COLOR,,14:COLOR,,1:NEXTI:GOTO880:'can not defend with this card 1100 IF(MOMOD13)>(AMOD13)THEN1090 1110 TA(TA)=A:TA=TA+1:GOSUB1250:PL=1-PL:GOTO660:'defended 1120 '___attack ended 1130 TA=0:GOSUB1190:PL=1-PL:GOTO660 1140 '___defence failed 1150 IFPL=0THENFORI=0TOTA-1:P1(P1)=TA(I):P1=P1+1:NEXTI:GOTO1170 1160 FORI=0TOTA-1:P2(P2)=TA(I):P2=P2+1:NEXTI 1170 TA=0:PL=1-PL:GOSUB1190:GOTO660:'previous attacker attacks again 1180 '___take cards from prikup,pl=player taking first 1190 GOSUB 1200:PL=1-PL:GOSUB1200:PL=1-PL:RETURN 1200 IFPL=0THENIFP1<6THENFORI=P1TO5:GOSUB1230:IFA=-1THEN1220ELSEP1(I)=A:P1=P1+1:NEXTI 1210 IFPL=1THENIFP2<6THENFORI=P2TO5:GOSUB1230:IFA=-1THEN1220ELSEP2(I)=A:P2=P2+1:NEXTI 1220 RETURN 1230 IFPR=0THENA=-1:RETURNELSEA=D(PR-1):PR=PR-1:RETURN 1240 '___remove card,q=card to remove,pl=player 1250 IFPL=0THENFORI=QTOP1-1:P1(I)=P1(I+1):NEXTI:P1=P1-1:RETURN 1260 FORI=QTOP2-1:P2(I)=P2(I+1):NEXTI:P2=P2-1:RETURN 1270 '___display cards 1280 IFP1<>0THEND1=30/P1:S1=(P1\2)*D1:IF(P1AND1)=1THENS1=S1+2 1290 IFP2<>0THEND2=30/P2:S2=(P2\2)*D2:IF(P2AND1)=1THENS2=S2+2 1300 S1=16-S1:S2=16-S2 1310 IFP1<>0THENFORI=0TOP1-1:A=P1(I):V=576+S1+I*D1:GOSUB1530:NEXTI 1320 IFP2<>0THENFORI=0TOP2-1:A=P2(I):V=S2+I*D2:GOSUB1530:NEXTI 1330 IFTA=0THEN1400 1340 IFTA<25THENXS=256+7:XD=96:XM=32:GOTO1370 1350 IFTA<37THENXS=256-32+7:XD=64:XM=0:GOTO1370 1360 XS=256-64+7:XD=64:XM=0 1370 V=XS:FORI=0TOTA-1:A=TA(I):IF(IAND1)=0THENV=V-XM+2ELSEV=V+XM+1 1380 GOSUB1530:IF(IMOD12)=11THENXS=XS+XD:V=XS 1390 NEXTI 1400 RETURN 1410 '___key or end of music 1420 IFINKEY$<>""THEN1450 1430 IFMU=1THENCALLNETPLAYBUFS(A):IFA=-1THEN1450 1440 A=0:RETURN 1450 A=-1:RETURN 1460 IFMU=1THENCALLNETPLAYBUFC:RETURN 1470 FORY=0TO7:READA:GOSUB1530:IFY=3THEN1480ELSE1490 1480 PSET(64,V\4),1:PRINT#1,"...":V=V-88:GOTO1500 1490 V=V+33 1500 NEXTY:RETURN 1510 DATA 0,14,28,42,9,23,37,51,4,18,32,46,9,23,37,51 1520 '___print card, A=card#,V=target char pos 1530 Z=A*&HC2:P=Z\8192:M=Z-P*8192 1540 CALLNETBITOV(P,&H6000+M,0,V*8) 1550 Z=(A+54)*&HC2:P=Z\8192:M=Z-P*8192 1560 CALLNETBITOV(P,&H6000+M,0,&H2000+V*8) 1570 RETURN 1580 '___deal,nc=number of cards-1,output:d() 1590 A=RND(-TIME):P=NC:IFNC=51THENFORI=0TONC:P1(I)=I:NEXTI:GOTO1610 1600 Z=0:FORI=0TO3:FORJ=4TO12:P1(Z)=I*13+J:Z=Z+1:NEXTJ:NEXTI 1610 Z=0:FORI=0TONC:A=RND(1)*(P+1):IFA=P+1THENA=P 1620 D(Z)=P1(A):Z=Z+1:P1(A)=P1(P):P=P-1:'IFA>PTHEN1120 1630 IFP=-1THEN1650 1640 NEXTI 1650 RETURN 1660 '___game instructions 1670 LINE(0,0)-(255,175),2,BF:CALLNETBITOV(2,30224,0,8192):CALLNETBITOV(2,29416,0,0) 1680 LINE(1,40)-(1,135),10:LINE(5,40)-(5,135),10:CALLNETBITOV(2,30426,0,8192+4352):CALLNETBITOV(2,29618,0,4352) 1690 LINE(40,174)-(215,174),10:LINE(40,170)-(215,170),10:CALLNETBITOV(2,30628,0,8192+4568):CALLNETBITOV(2,29820,0,4568) 1700 LINE(254,136)-(254,40),10:LINE(250,136)-(250,40),10:CALLNETBITOV(2,30830,0,8192+216):CALLNETBITOV(2,30022,0,216) 1710 LINE(215,1)-(40,1),10:LINE(215,5)-(40,5),10 1720 PSET(49,20),2:PRINT#1,"(Source: Wikipedia)":P=0 1730 RESTORE1890 1740 READA:IFA=PTHEN1760 1750 READA$:IFA$=""THEN1740ELSE1750 1760 READA$:PSET(48,10),2:PRINT#1,A$:PSET(49,10),2:PRINT#1,A$:L=40 1770 READA$:IFA$=""THEN1790 1780 PSET(10,L),2:PRINT#1,A$:L=L+8:GOTO 1770 1790 A=USR1(0) 1800 A=ASC(INPUT$(1)):IFA=27THEN1880 1810 IFA=31THEN1840 1820 IFA=30THEN1860 1830 GOTO1800 1840 P=P+1:IFP=11THENP=0 1850 LINE(48,10)-(215,17),2,BF:LINE(6,40)-(249,135),2,BF:LINE(40,136)-(215,167),2,BF:GOTO1730 1860 P=P-1:IFP<0THENP=10 1870 GOTO1850 1880 LINE(0,0)-(255,175),1,BF:GOTO100 1890 DATA 0,"General info (1 vs 1)","Durak is a card game that is","popular in post-Soviet states."," ","The object of the game is to","get rid of all one's cards." 1900 DATA "At the end of the game, the","last player with cards in","their hand is the durak.","" 1910 DATA 1,"Setup 1/2","The deck is shuffled, and each","player receives six cards.","The bottom card of the","remaining deck is laid open","on the table. This determines" 1920 DATA "the trump suit. The remainder","of the deck is then placed on","top of the revealed card at a","90 degree angle, so that it","remains visible, forming a" 1930 DATA "draw pile called the prikup","('talon').","" 1940 DATA 2,"Setup 2/2","The revealed card remains","part of the talon and is drawn","as the last card. Cards","discarded due to successful" 1950 DATA "defenses are placed in a","discard pile next to the","talon.","" 1960 DATA 3,"Gameplay","The player with the lowest","trump is the first attacker.","Another player is the" 1970 DATA "defender. After each turn play","proceeds to the defender. If","the attack succeeds, the","defender loses their turn and","the attacker continues to" 1980 DATA "attack. If the attack fails,","the defender becomes the next","attacker.","" 1990 DATA 4,"Attack","The attacker opens the turn","by playing one card face up on","the table as an attacking","card. The defender has to","immediately attempt defense in","response to the initial" 2000 DATA "attack. Ace is the highest","rank and six (two for 52-card","game) is the lowest. Trumps","always beat non-trump cards","regardless of rank (ex. trump","six beats a non-trump ace).","" 2010 DATA 5,"Defense (1/4)","The defender attempts to beat","the attacking cards by playing","higher-valued defending cards","from their hand. One card is","played to defend against each","attacking card, and it must be" 2020 DATA "in the attacking card's suit","or the trump suit. The","defending cards are placed on","top of the attacking cards so","that players can keep track of","which card is defending"," against which.","" 2030 DATA 6,"Defense (2/4)","At any point during a defense,","attacker can add extra","attacking cards, provided that","for each new attacking card,","there is already a card of the","same rank on the table (either" 2040 DATA "defending or attacking), and","the total number of attacking","cards does not exceed the","number of cards in the","defender's hand. The defender","must also defend against"," these new cards.","" 2050 DATA 7,"Defense (3/4)","At any point during the turn,","a defender unwilling or unable","to beat all attacking cards","may abandon the defense by","picking up all the cards on","the table. This ends the turn." 2060 DATA "The failed defender loses","their turn to attack; hence","the attacked attacks again.","" 2070 DATA 8,"Defense (4/4)","If, however, the defender has","beaten all attacking cards,","the defender has triumphed.","The turn ends, all cards on","the table are placed in the","discard pile, and the" 2080 DATA "successful defender opens the","next turn as the new attacker.","No players may examine the","discard pile at any point.","" 2090 DATA 9,"End of turn","At the end of each turn,","whether or not the defense was","successful, each player draws","until they have six cards in","their hand or the talon is","exhausted. The attacker draws" 2100 DATA "as many cards as necessary","first, and then the defender.","Once the talon is empty, play","continues without further","drawing. Players who exhaust","their hands leave the game.","" 2110 DATA 10,"Winning and losing","The last person left with","cards in their hand is the","loser (the fool or 'durak').","" 2120 DATA 4,11,10,10,10,10,10,56,32,32,16,16,8,8,4,7,0,0,192,176,168,168,40,8,8,8,8,8,16,16,32,224 2130 DATA 4,15,15,15,15,15,15,63,63,63,31,31,15,15,7,7,0,0,192,240,248,240,240,240,240,240,240,240,224,224,192,192 2140 DATA 7,8,48,32,64,128,128,144,188,159,159,71,35,48,8,7,224,16,12,36,50,121,121,241,225,225,193,194,4,12,16,224 2150 DATA 7,15,63,63,127,255,255,255,255,255,255,127,63,63,15,7,224,240,252,252,254,255,255,255,255,255,255,254,252,252,240,224 2160 DATA 7,8,48,36,78,143,135,131,135,143,158,72,32,48,8,7,224,16,12,36,114,241,225,193,225,241,113,34,4,12,16,224