home *** CD-ROM | disk | FTP | other *** search
/ Compute! Gazette 1985 November / 1985-11.d64 / backgammon (.txt) < prev    next >
Commodore BASIC  |  2022-09-20  |  3KB  |  112 lines

  1. 100 ct=55296:poke 53280,0:poke 53281,0
  2. 110 l$="                                       ":a=rnd(0)
  3. 120 print"[147][159]"tab(14)"backgammon":printtab(14)"[163][163][163][163][163][163][163][163][163][163]"
  4. 130 input" will i go first  y[157][157][157]";mf$
  5. 140 dimb(25):dimr(3):deffnr(x)=int(rnd(x)*6)+1
  6. 150 deffnp(x)=ct-((x-(x>6))*40+y)*(x<13)-((26-(x+(x<19)))*40-y-1)*(x>12)
  7. 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
  8. 170 forx=1to24:readb(x):nextx
  9. 180 print"[147]               backgammon               ";:forx=1to12
  10. 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);
  11. 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   ";
  12. 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] ";
  13. 220 print"[146][158]player [209]    computer [209]"
  14. 230 forx=1to24:ifb(x)=0then270
  15. 240 z=abs(b(x)):ifz>10thenz=10
  16. 250 fory=1toz
  17. 260 pokefnp(x),86.5-sgn(b(x))/2:nexty
  18. 270 nextx:x=1:z=ct+310
  19. 280 ifx<7andx<=b(0)thenpokez,86:z=z-1:x=x+1:goto280
  20. 290 x=1:z=ct+289
  21. 300 ifx<7andx<=-pbthenpokez,87:z=z+1:x=x+1:goto300
  22. 310 gosub1180:gosub1150:print"[159]";
  23. 320 ifleft$(mf$,1)="n"thenprint"player ";:goto340
  24. 330 print"computer ";
  25. 340 print"roll";:if f$="dr"ort$="draw"then360
  26. 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)
  27. 360 forx=0to3:ifr(x)>0thenprint" ";chr$(r(x)+48);"[146]";
  28. 370 nextx:print
  29. 380 ifleft$(mf$,1)="n"then830
  30. 390 print"thinking...[145]"
  31. 400 ob=0:forz=0to18:ifb(z)>0then420
  32. 410 nextz:ob=1
  33. 420 h=0:hp=0:hr=0:fory=0to3:x=0:ifr(y)=0then580
  34. 430 e=0
  35. 440 ifb(x)<1orr(y)+x>25then570
  36. 450 ifx=0andb(x)>0thene=e+128
  37. 460 ifx+r(y)=25thene=e+64
  38. 470 ifb(x)=1andb(x+r(y))=1thene=e+32
  39. 480 ifb(x)<>2andb(x+r(y))>0thene=e+16
  40. 490 ifb(x+r(y))=-1thene=e+8
  41. 500 ifx<19thene=e+4
  42. 510 ifb(x+r(y))<-1or(ob=0and(x+r(y))=25)then570
  43. 520 e=e+1:ify=3orx+r(y)=25orb(x+r(y))>0then560
  44. 530 z=y+1
  45. 540 qa=0:ifr(z)>0andx+r(y)-r(z)>-1andx+r(y)-r(z)<25then qa=1
  46. 545 ifqa=1thenifb(x+r(y)-r(z))>0thene=e+2:goto560
  47. 550 z=z+1:ifz<4then540
  48. 560 ifh<ethenh=e:hr=r(y):hp=x
  49. 570 x=x+1:ifx<25then430
  50. 580 nexty
  51. 590 ifh<128andb(0)>0then680
  52. 600 ifh>0then700
  53. 610 lr=7:fory=0to3
  54. 620 if r(y)<lrandr(y)>1thenlr=r(y):ln=y
  55. 630 nexty:iflr=7then680
  56. 640 forx=0to25-lr:ifb(x)>0then680
  57. 650 nextx:x=26-lr
  58. 660 ifb(x)>0thenr(ln)=25-x:goto400
  59. 670 x=x+1:ifx<25then660
  60. 680 print"      can not move - press a key[146]":mf$="n"
  61. 690 geta$:on-(a$="")goto690:goto310
  62. 700 forx=0to3:ifr(x)<>hrthennextx
  63. 710 r(x)=0
  64. 720 ifb(hp)<11andhp>0theny=b(hp):pokefnp(hp),0
  65. 730 b(hp)=b(hp)-1:z$=chr$(hp+hr+64):ifhp+hr>24thenz$="off"
  66. 740 x$=chr$(hp+64):ifhp=0thenx$="bar"
  67. 750 print"move from ";x$;" to ";z$
  68. 760 ifb(hp+hr)=-1thenpb=pb-1:b(hp+hr)=0:ifpb>-7thenpokect+288-pb,87
  69. 770 ifhp=0andb(0)<8thenpokect+310-b(0),0
  70. 780 y=b(hp+hr)+1:b(hp+hr)=y
  71. 790 ifhp+hr<25andy<11thenpokefnp(hp+hr),86:goto810
  72. 800 ifb(25)=15thengosub1150:print"i win.":goto 1190
  73. 810 forx=0to3:ifr(x)>0then390
  74. 820 nextx:print""spc(14)"press a key":mf$="n":goto690
  75. 830 f$="@":print"move from";:ifpb<0thenprint" bar":hp=25:f$="y":goto880
  76. 840 inputf$:f$=left$(f$,2):iff$="no"thenmf$="":goto310
  77. 850 iff$="dr"then180
  78. 860 iff$<"a"orf$>"x"then1140
  79. 870 hp=asc(f$)-64:ifb(hp)>=0then1140
  80. 880 t$="@":input"[157][157][157][157][157][157][157][157]to";t$:hp=asc(f$)-64:hr=asc(f$)-asc(t$)
  81. 890 ift$="no"thenmf$="":goto310
  82. 900 ift$="draw"then180
  83. 910 x=0:ift$="off"thenhr=hp
  84. 920 printl$;"[145]";
  85. 930 forx=0to3:ifhr<>r(x)thennextx:on-(hr<>hp)goto1140
  86. 940 ob=x:ifhr<>hpthen990
  87. 950 z=hp+1:forob=0to3:ifr(ob)=hpthenz=7:goto970
  88. 960 ifr(ob)<hpthennextob:goto1140
  89. 970 forx=zto24:ifb(x)<0then1140
  90. 980 nextx
  91. 990 ifb(hp-hr)>1andhp<>hrthen1140
  92. 1000 qa=0:ifb(hp-hr)>0andhp<>hrthenb(hp-hr)=0:b(0)=b(0)+1:qa=1
  93. 1010 ifqa=1andb(0)<7thenpokect+311-b(0),86
  94. 1020 y=-pb:m=7:z=ct+288+y:pb=pb+1
  95. 1030 ifhp<25thenpb=pb-1:y=-b(hp):b(hp)=b(hp)+1:z=fnp(hp):m=11
  96. 1040 ify<mthenpokez,0
  97. 1050 ifhp=hrthen1100
  98. 1060 y=b(hp-hr)-1:b(hp-hr)=y:ifb(hp-hr)>10then1120
  99. 1070 y=-y:z=fnp(hp-hr)
  100. 1080 ify<11thenpokez,87
  101. 1090 goto 1120
  102. 1100 po=po+1
  103. 1110 ifpo=15thengosub1150:print"you win.":goto 1190
  104. 1120 r(ob)=0:forx=0to3:ifr(x)>0then830
  105. 1130 nextx:mf$="":goto310
  106. 1140 print"illegal move[157][157][157][157][157][157][157][157][157][157][157][157][145]";l$;"[145]":goto830
  107. 1150 poke214,16:print
  108. 1160 forx=1to5:printl$:nextx:printl$;
  109. 1170 poke214,16:print:return
  110. 1180 print""spc(14)"           ":return
  111. 1190 input"play again (y/n)";a$:ifleft$(a$,1)="y"thenrun
  112.