home *** CD-ROM | disk | FTP | other *** search
/ Compute! Gazette 1991 November / 1991-11.d64 / 1-3-5-7 (.txt) < prev    next >
Commodore BASIC  |  2022-09-20  |  4KB  |  183 lines

  1. 0 clr
  2. 50 rem copyright 1991 - compute publications intl ltd - all rights reserved
  3. 100 gosub1750:gosub1210
  4. 110 gosub1530:gosub300
  5. 120 print pl$(op,pl);"'s move":print
  6. 130 on (op*2)+pl gosub420,590,590,420,420,420,590,590,590,690
  7. 140 gm$(mv)=bd$+" "+chr$(r+64)+chr$(n+48)
  8. 150 mv=mv+1:pl=abs(pl-3)
  9. 160 gosub860:gosub300
  10. 170 if eg=0 then120
  11. 180 nm=mv-1
  12. 190 rem
  13. 200 rem announce winner
  14. 210 rem
  15. 220 print "and the winner is..."
  16. 230 print:print pl$(op,abs(pl-3))
  17. 240 gosub940
  18. 250 get k$:if op=4 and k$<>"_" then110
  19. 260 op=0
  20. 270 print "      = press return to continue =";
  21. 280 get k$:if k$<>chr$(13) then280
  22. 290 goto110
  23. 300 rem
  24. 310 rem display board
  25. 320 rem
  26. 330 print chr$(147)
  27. 340 print:print
  28. 350 for i=1 to 4
  29. 360 n=val(mid$(bd$,i,1))
  30. 370 print chr$(i+64);") ";left$("[221][221][221][221][221][221][221]",n)
  31. 380 print
  32. 390 next i
  33. 400 print
  34. 410 return
  35. 420 rem
  36. 430 rem get human's move
  37. 440 rem
  38. 450 print "row: ";
  39. 460 get k$:if k$<"a" or k$>"d" then460
  40. 470 r=asc(k$)-64
  41. 480 x=val(mid$(bd$,r,1))
  42. 490 if val(bd$)=int(10^(4-r)*x) then x=x-1
  43. 500 if x=0 then460
  44. 510 print k$:r=asc(k$)-64
  45. 520 print "number to remove: ";
  46. 530 get k$:if k$<"1" or k$>chr$(x+48) then530
  47. 540 print k$:n=val(k$)
  48. 550 print "       = press return to accept =";
  49. 560 get k$:if k$="" then560
  50. 570 if k$<>chr$(13) then gosub300:print pl$(op,pl);"'s move":print:goto420
  51. 580 return
  52. 590 rem
  53. 600 rem get computer's move
  54. 610 rem
  55. 620 bd=val(bd$):mv$=wm$(bd)
  56. 630 if mv$="" then690
  57. 640 r=asc(mid$(mv$,1,1))-64:n=val(mid$(mv$,2,1))
  58. 650 print "row:";chr$(64+r)
  59. 660 print "number to remove:";n
  60. 670 if op<>4 then for i=1 to 1000:next i
  61. 680 return
  62. 690 rem
  63. 700 rem get random move
  64. 710 rem
  65. 720 a$=""
  66. 730 for i=1 to 4
  67. 740 r$=mid$(bd$,i,1)
  68. 750 if r$<>"0" then a$=a$+chr$(i+48)
  69. 760 next i
  70. 770 if len(a$)=1 then r=val(a$):goto790
  71. 780 r=val(mid$(a$,int(rnd(1)*len(a$))+1,1))
  72. 790 x=val(mid$(bd$,r,1))
  73. 800 if val(bd$)=int(10^(4-r)*x) then x=x-1
  74. 810 n=int(rnd(1)*x)+1
  75. 820 print "row:";chr$(64+r)
  76. 830 print "number to remove:";n
  77. 840 if op<>4 then for i=1 to 1000:next i
  78. 850 return
  79. 860 rem
  80. 870 rem execute move and check for win
  81. 880 rem
  82. 890 cn=val(mid$(bd$,r,1))
  83. 900 cn=cn-n
  84. 910 bd$=mid$(bd$,1,r-1)+chr$(cn+48)+mid$(bd$,r+1,4)
  85. 920 if bd$="1000" or bd$="0100" or bd$="0010" or bd$="0001" then eg=1
  86. 930 return
  87. 940 rem
  88. 950 rem learn from game
  89. 960 rem
  90. 970 rem    reward winning moves
  91. 980 mv=mv-1:if mv=0 then return
  92. 990 bd=val(left$(gm$(mv),4))
  93. 1000 mv$=right$(gm$(mv),2)
  94. 1010 f=0:a$=wm$(bd):if a$="" then a$=mv$:goto1080
  95. 1020 for i=1 to len(a$) step 2
  96. 1030 if mid$(a$,i,2)=mv$ then f=i
  97. 1040 next i
  98. 1050 if f=0 then a$=mv$+a$:goto1080
  99. 1060 if f=1 then1080
  100. 1070 a$=left$(a$,f-3)+mv$+mid$(a$,f-2,2)+mid$(a$,f+2)
  101. 1080 wm$(bd)=a$
  102. 1090 rem    punish losing moves
  103. 1100 mv=mv-1:if mv=0 then return
  104. 1110 bd=val(left$(gm$(mv),4))
  105. 1120 mv$=right$(gm$(mv),2)
  106. 1130 f=0:a$=wm$(bd):if a$="" then970
  107. 1140 for i=1 to len(a$) step 2
  108. 1150 if mid$(a$,i,2)=mv$ then f=i
  109. 1160 next i
  110. 1170 if f=0 then970
  111. 1180 if f+1=len(a$) then wm$(bd)=left$(wm$(bd),f-1):goto970
  112. 1190 wm$(bd)=left$(a$,f-1)+mid$(a$,f+2,2)+mv$+mid$(a$,f+4)
  113. 1200 goto970
  114. 1210 rem
  115. 1220 rem load experince
  116. 1230 rem
  117. 1240 print chr$(147)
  118. 1250 print "load previous game experience? ";
  119. 1260 get k$:if k$<>"y" and k$<>"n" then1260
  120. 1270 if k$="n" then print "no":for i=1 to 500:next i:goto1350
  121. 1280 print "yes":print:input "filename";a$:if a$="" then1350
  122. 1290 open 15,8,15
  123. 1300 open 1,8,2,a$+".ai,s,r"
  124. 1310 input#15,e,e$
  125. 1320 if e thenprint"* ";e$;" *":for i=1to2500:next i:close1:close15:goto1210
  126. 1330 input#1,bd:input#1,mv$:wm$(bd)=mv$:if st=0 then1330
  127. 1340 close 1:close 15
  128. 1350 return
  129. 1360 rem
  130. 1370 rem save experience
  131. 1380 rem
  132. 1390 print chr$(147)
  133. 1400 print "save game experience? ";
  134. 1410 get k$:if k$<>"y" and k$<>"n" then1410
  135. 1420 if k$="n" then print "no":goto1520
  136. 1430 print "yes":print:input "filename";a$:if a$="" then1520
  137. 1440 open 15,8,15,"s0:"+a$+".ai"
  138. 1450 open 1,8,2,a$+".ai,s,w"
  139. 1460 input#15,e,e$
  140. 1470 if e thenprint"* ";e$;" *":for i=1to2500:next i:close1:close15:goto1360
  141. 1480 for i=1 to 1357
  142. 1490 if wm$(i)<>"" then print#1,i:print#1,wm$(i)
  143. 1500 next i
  144. 1510 close 1:close 15
  145. 1520 return
  146. 1530 rem
  147. 1540 rem prepare for new game
  148. 1550 rem
  149. 1560 bd$="1357"
  150. 1570 for i=1 to nm:gm$(i)="":next i
  151. 1580 mv=1
  152. 1590 eg=0
  153. 1600 if op=4 then wf=abs(wf-3):pl=wf:goto1740
  154. 1610 pl=1
  155. 1620 wf=1
  156. 1630 print chr$(147);"       1-3-5-7      "
  157. 1640 print
  158. 1650 print:print "  1) human moves first"
  159. 1660 print:print "  2) computer moves first"
  160. 1670 print:print "  3) human vs human"
  161. 1680 print:print "  4) computer vs computer"
  162. 1690 print:print "  5) auto-learn mode"
  163. 1700 print:print "  6) quit"
  164. 1710 get k$:if k$<"1" or k$>"6" then1710
  165. 1720 if k$="6" then gosub1360:print:print "thanks for playing":end
  166. 1730 op=val(k$)-1
  167. 1740 return
  168. 1750 rem
  169. 1760 rem initialize program
  170. 1770 rem
  171. 1780 x=rnd(-ti)
  172. 1790 dim wm$(1357)
  173. 1800 dim gm$(15)
  174. 1810 dim pl$(4,2)
  175. 1820 restore
  176. 1830 for op=0 to 4:for pl=1 to 2:read pl$(op,pl):next pl:next op
  177. 1840 return
  178. 1850 data the human,the computer
  179. 1860 data the computer,the human
  180. 1870 data human1,human2
  181. 1880 data computer1,computer2
  182. 1890 data the computer,mr. random
  183.