home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Compute! Gazette 1985 November
/
1985-11.d64
/
backgammon
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2022-09-20
|
3KB
|
112 lines
100 ct=55296:poke 53280,0:poke 53281,0
110 l$=" ":a=rnd(0)
120 print"[147][159]"tab(14)"backgammon":printtab(14)"[163][163][163][163][163][163][163][163][163][163]"
130 input" will i go first y[157][157][157]";mf$
140 dimb(25):dimr(3):deffnr(x)=int(rnd(x)*6)+1
150 deffnp(x)=ct-((x-(x>6))*40+y)*(x<13)-((26-(x+(x<19)))*40-y-1)*(x>12)
160 data 2,0,0,0,0,-5,0,-3,0,0,0,5,-5,0,0,0,3,0,5,0,0,0,0,-2
170 forx=1to24:readb(x):nextx
180 print"[147] backgammon ";:forx=1to12
190 printchr$(64+x);"[146][144][209][209][209][209][209][209][209][209][209][209][209][209][209][209][209][209][209][209][209][209][209][209][209][209][209][209][209][209][209][209][209][209][209][209][209][209][209][209]";chr$(89-x);
200 ifx=6thenprint" bar [146][144][209][209][209][209][209][209][209][209][209][209][209][209][209][209][209][209][209][209][209][209][209][209] bar ";
210 nextx:print" [146][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175] ";
220 print"[146][158]player [209] computer [209]"
230 forx=1to24:ifb(x)=0then270
240 z=abs(b(x)):ifz>10thenz=10
250 fory=1toz
260 pokefnp(x),86.5-sgn(b(x))/2:nexty
270 nextx:x=1:z=ct+310
280 ifx<7andx<=b(0)thenpokez,86:z=z-1:x=x+1:goto280
290 x=1:z=ct+289
300 ifx<7andx<=-pbthenpokez,87:z=z+1:x=x+1:goto300
310 gosub1180:gosub1150:print"[159]";
320 ifleft$(mf$,1)="n"thenprint"player ";:goto340
330 print"computer ";
340 print"roll";:if f$="dr"ort$="draw"then360
350 r(0)=fnr(x):r(1)=fnr(x):r(2)=0:r(3)=0:ifr(0)=r(1)thenr(2)=r(1):r(3)=r(1)
360 forx=0to3:ifr(x)>0thenprint" ";chr$(r(x)+48);"[146]";
370 nextx:print
380 ifleft$(mf$,1)="n"then830
390 print"thinking...[145]"
400 ob=0:forz=0to18:ifb(z)>0then420
410 nextz:ob=1
420 h=0:hp=0:hr=0:fory=0to3:x=0:ifr(y)=0then580
430 e=0
440 ifb(x)<1orr(y)+x>25then570
450 ifx=0andb(x)>0thene=e+128
460 ifx+r(y)=25thene=e+64
470 ifb(x)=1andb(x+r(y))=1thene=e+32
480 ifb(x)<>2andb(x+r(y))>0thene=e+16
490 ifb(x+r(y))=-1thene=e+8
500 ifx<19thene=e+4
510 ifb(x+r(y))<-1or(ob=0and(x+r(y))=25)then570
520 e=e+1:ify=3orx+r(y)=25orb(x+r(y))>0then560
530 z=y+1
540 qa=0:ifr(z)>0andx+r(y)-r(z)>-1andx+r(y)-r(z)<25then qa=1
545 ifqa=1thenifb(x+r(y)-r(z))>0thene=e+2:goto560
550 z=z+1:ifz<4then540
560 ifh<ethenh=e:hr=r(y):hp=x
570 x=x+1:ifx<25then430
580 nexty
590 ifh<128andb(0)>0then680
600 ifh>0then700
610 lr=7:fory=0to3
620 if r(y)<lrandr(y)>1thenlr=r(y):ln=y
630 nexty:iflr=7then680
640 forx=0to25-lr:ifb(x)>0then680
650 nextx:x=26-lr
660 ifb(x)>0thenr(ln)=25-x:goto400
670 x=x+1:ifx<25then660
680 print" can not move - press a key[146]":mf$="n"
690 geta$:on-(a$="")goto690:goto310
700 forx=0to3:ifr(x)<>hrthennextx
710 r(x)=0
720 ifb(hp)<11andhp>0theny=b(hp):pokefnp(hp),0
730 b(hp)=b(hp)-1:z$=chr$(hp+hr+64):ifhp+hr>24thenz$="off"
740 x$=chr$(hp+64):ifhp=0thenx$="bar"
750 print"move from ";x$;" to ";z$
760 ifb(hp+hr)=-1thenpb=pb-1:b(hp+hr)=0:ifpb>-7thenpokect+288-pb,87
770 ifhp=0andb(0)<8thenpokect+310-b(0),0
780 y=b(hp+hr)+1:b(hp+hr)=y
790 ifhp+hr<25andy<11thenpokefnp(hp+hr),86:goto810
800 ifb(25)=15thengosub1150:print"i win.":goto 1190
810 forx=0to3:ifr(x)>0then390
820 nextx:print""spc(14)"press a key":mf$="n":goto690
830 f$="@":print"move from";:ifpb<0thenprint" bar":hp=25:f$="y":goto880
840 inputf$:f$=left$(f$,2):iff$="no"thenmf$="":goto310
850 iff$="dr"then180
860 iff$<"a"orf$>"x"then1140
870 hp=asc(f$)-64:ifb(hp)>=0then1140
880 t$="@":input"[157][157][157][157][157][157][157][157]to";t$:hp=asc(f$)-64:hr=asc(f$)-asc(t$)
890 ift$="no"thenmf$="":goto310
900 ift$="draw"then180
910 x=0:ift$="off"thenhr=hp
920 printl$;"[145]";
930 forx=0to3:ifhr<>r(x)thennextx:on-(hr<>hp)goto1140
940 ob=x:ifhr<>hpthen990
950 z=hp+1:forob=0to3:ifr(ob)=hpthenz=7:goto970
960 ifr(ob)<hpthennextob:goto1140
970 forx=zto24:ifb(x)<0then1140
980 nextx
990 ifb(hp-hr)>1andhp<>hrthen1140
1000 qa=0:ifb(hp-hr)>0andhp<>hrthenb(hp-hr)=0:b(0)=b(0)+1:qa=1
1010 ifqa=1andb(0)<7thenpokect+311-b(0),86
1020 y=-pb:m=7:z=ct+288+y:pb=pb+1
1030 ifhp<25thenpb=pb-1:y=-b(hp):b(hp)=b(hp)+1:z=fnp(hp):m=11
1040 ify<mthenpokez,0
1050 ifhp=hrthen1100
1060 y=b(hp-hr)-1:b(hp-hr)=y:ifb(hp-hr)>10then1120
1070 y=-y:z=fnp(hp-hr)
1080 ify<11thenpokez,87
1090 goto 1120
1100 po=po+1
1110 ifpo=15thengosub1150:print"you win.":goto 1190
1120 r(ob)=0:forx=0to3:ifr(x)>0then830
1130 nextx:mf$="":goto310
1140 print"illegal move[157][157][157][157][157][157][157][157][157][157][157][157][145]";l$;"[145]":goto830
1150 poke214,16:print
1160 forx=1to5:printl$:nextx:printl$;
1170 poke214,16:print:return
1180 print""spc(14)" ":return
1190 input"play again (y/n)";a$:ifleft$(a$,1)="y"thenrun