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

  1. 100 ct=37888+4*(peek(36866)and128):poke36879,8:a=rnd(0)
  2. 110 l$="                     "
  3. 120 print"[147][159]backgammon"
  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))*22+y)*(x<13)-((26-(x+(x<19)))*22-y-1)*(x>12)
  7. 160 data2,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      ";
  10. 190 forx=1to12: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]";chr$(89-x);
  11. 200 ifx=6thenprint" bar [146][144][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] ";
  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),6.5-sgn(b(x))/2:nexty
  18. 270 nextx:x=1:z=ct+170
  19. 280 ifx<7andx<=b(0)thenpokez,6:z=z-1:x=x+1:goto280
  20. 290 x=1:z=ct+159
  21. 300 ifx<7andx<=-pbthenpokez,7:z=z+1:x=x+1:goto300
  22. 310 gosub1130: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 ifr(z)>0andx+r(y)-r(z)>-1andx+r(y)-r(z)<25thenifb(x+r(y)-r(z))>0thene=e+2:goto560
  46. 550 z=z+1:ifz<4then540
  47. 560 ifh<ethenh=e:hr=r(y):hp=x
  48. 570 x=x+1:ifx<25then430
  49. 580 nexty
  50. 590 ifh<128andb(0)>0then680
  51. 600 ifh>0then700
  52. 610 lr=7:fory=0to3
  53. 620 if r(y)<lrandr(y)>1thenlr=r(y):ln=y
  54. 630 nexty:iflr=7then680
  55. 640 forx=0to25-lr:ifb(x)>0then680
  56. 650 nextx:x=26-lr
  57. 660 ifb(x)>0thenr(ln)=25-x:goto400
  58. 670 x=x+1:ifx<25then660
  59. 680 print"can not move[146]":mf$="n"
  60. 690 geta$:on-(a$="")goto690:goto310
  61. 700 forx=0to3:ifr(x)<>hrthennextx
  62. 710 r(x)=0
  63. 720 ifb(hp)<11andhp>0theny=b(hp):pokefnp(hp),0
  64. 730 b(hp)=b(hp)-1:z$=chr$(hp+hr+64):ifhp+hr>24thenz$="off"
  65. 740 x$=chr$(hp+64):ifhp=0thenx$="bar"
  66. 750 print"move from ";x$;" to ";z$
  67. 760 ifb(hp+hr)=-1thenpb=pb-1:b(hp+hr)=0:ifpb>-7thenpokect+158-pb,7
  68. 770 ifhp=0andb(0)<8thenpokect+170-b(0),0
  69. 780 y=b(hp+hr)+1:b(hp+hr)=y
  70. 790 ifhp+hr<25andy<11thenpokefnp(hp+hr),6:goto810
  71. 800 ifb(25)=15thengosub1130:print"i win.":goto1160
  72. 810 forx=0to3:ifr(x)>0then390
  73. 820 nextx:mf$="n":goto690
  74. 830 print"move from";:ifpb<0thenprint" bar":hp=25:f$="y":goto880
  75. 840 inputf$:f$=left$(f$,2):iff$="no"thenmf$="":goto310
  76. 850 iff$="dr"then180
  77. 860 iff$<"a"orf$>"x"then1120
  78. 870 hp=asc(f$)-64:ifb(hp)>=0then1120
  79. 880 input"[157][157][157][157][157][157][157][157]to";t$:hp=asc(f$)-64:hr=asc(f$)-asc(t$):ift$="no"thenmf$="":goto310
  80. 890 ift$="draw"then180
  81. 900 x=0:ift$="off"thenhr=hp
  82. 910 printl$;"[145]";
  83. 920 forx=0to3:ifhr<>r(x)thennextx:on-(hr<>hp)goto1120
  84. 930 ob=x:ifhr<>hpthen980
  85. 940 z=hp+1:forob=0to3:ifr(ob)=hpthenz=7:goto960
  86. 950 ifr(ob)<hpthennextob:goto1120
  87. 960 forx=zto24:ifb(x)<0then1120
  88. 970 nextx
  89. 980 ifb(hp-hr)>1andhp<>hrthen1120
  90. 990 ifb(hp-hr)>0andhp<>hrthenb(hp-hr)=0:b(0)=b(0)+1:ifb(0)<7thenpokect+171-b(0),6
  91. 1000 y=-pb:m=7:z=ct+158+y:pb=pb+1
  92. 1010 ifhp<25thenpb=pb-1:y=-b(hp):b(hp)=b(hp)+1:z=fnp(hp):m=11
  93. 1020 ify<mthenpokez,0
  94. 1030 ifhp=hrthen1080
  95. 1040 y=b(hp-hr)-1:b(hp-hr)=y:ifb(hp-hr)>10then1100
  96. 1050 y=-y:z=fnp(hp-hr)
  97. 1060 ify<11thenpokez,7
  98. 1070 goto 1100
  99. 1080 po=po+1
  100. 1090 ifpo=15thengosub1130:print"you win.":goto1160
  101. 1100 r(ob)=0:forx=0to3:ifr(x)>0then830
  102. 1110 nextx:mf$="":goto310
  103. 1120 print"illegal move[157][157][157][157][157][157][157][157][157][157][157][157][145]";:goto830
  104. 1130 poke214,16:print:poke211,0
  105. 1140 forx=1to5:printl$:nextx:printl$;
  106. 1150 poke214,16:print:poke211,0:return
  107. 1160 input"play again (y/n)";a$:ifleft$(a$,1)="y"thenrun
  108.