home *** CD-ROM | disk | FTP | other *** search
/ Commodore Disk User Volume 3 #7 / Commodore_Disk_User_Vol.3_7_1990_-.d64 / maze.basic (.txt) < prev    next >
Commodore BASIC  |  2022-10-26  |  2KB  |  96 lines

  1. 10 rem basic maze program
  2. 100 poke 53280,0:poke 53281,11
  3. 110 print"[147][205]aze [208]rogram"
  4. 120 print"[183][183][183][183][183][183][183][183][183][183][183][183]"
  5. 130 print"[212]his is a [194][193][211][201][195] equivalent of the"
  6. 140 print"machine code maze generator. [193]lthough"
  7. 150 print" not identical, it uses a very similar"
  8. 160 print" algorithm and method of storing data."
  9. 170 print"[196]imensions:"
  10. 180 print"[205]aximum: 18,10"
  11. 190 print"[205]inimum: 1,1"
  12. 200 print"[214]isible [195]haracters 33-132, 161-255"
  13. 210 input"[196]imensions:   18,10[157][157][157][157][157][157][157]";h,v
  14. 215 if h<1 or v<1 or h>18 or v>10 then print"[196]imensions out of range !":goto 210
  15. 220 input"[195]haracter:    255[157][157][157][157][157]";c
  16. 225 if c<33 or c>255 then print" [212]ry a different character.":goto 220
  17. 230 print"[147][212]his will take around";int(h*v/3+1);"seconds."
  18. 240 ti$="000000"
  19. 997 :
  20. 998 :
  21. 999 rem main loop
  22. 1000 gosub 10000 : rem setup variables
  23. 1010 gosub 5000  : rem print time
  24. 1020 if dc>0 then gosub 2010
  25. 1030 m%(r,s)=m%(r,s) or 4
  26. 1040 dc=t(rnd(1)*t)
  27. 1050 if t>0 then p=p+1:p%(p)=dc
  28. 1060 if dc=1 then s=s-1:m%(r,s)=m%(r,s) or 1:goto 1110
  29. 1070 if dc=2 then m%(r,s)=m%(r,s) or 1:s=s+1:goto 1110
  30. 1080 if dc=3 then r=r-1:m%(r,s)=m%(r,s) or 2:goto 1110
  31. 1090 if dc=4 then m%(r,s)=m%(r,s) or 2:r=r+1:goto 1110
  32. 1100 gosub 3010:goto 1120: rem deadend!
  33. 1110 m%(r,s)=m%(r,s) or o
  34. 1120 if p>0 then 1010
  35. 1130 gosub 4010: rem finished, print out     board.
  36. 1140 poke 198,0: rem clear keyboard
  37. 1150 get k$:if k$="" then 1150
  38. 1160 run
  39. 1999 :
  40. 2000 rem check available directions
  41. 2010 t(0)=0:t=0
  42. 2020 if s>0 then if m%(r,s-1)=0 then t(t)=1:t=t+1
  43. 2030 if s<v then if m%(r,s+1)=0 then t(t)=2:t=t+1
  44. 2040 if r>0 then if m%(r-1,s)=0 then t(t)=3:t=t+1
  45. 2050 if r<h then if m%(r+1,s)=0 then t(t)=4:t=t+1
  46. 2060 return
  47. 2999 :
  48. 3000 rem backtrack thru maze
  49. 3010 g=1
  50. 3020 q=p%(p):gosub 5000 : rem repeat...
  51. 3030 if q=1 then s=s+1  : rem down
  52. 3040 if q=2 then s=s-1  : rem up
  53. 3050 if q=3 then r=r+1  : rem right
  54. 3060 if q=4 then r=r-1  :rem left
  55. 3070 gosub 2010
  56. 3080 p=p-1:if p=0 then g=0
  57. 3090 if t>0 then g=0
  58. 3100 if g then 3020     : rem until g=0
  59. 3110 return
  60. 3999 :
  61. 4000 rem print maze
  62. 4010 m%(h,v)=m%(h,v) or 1
  63. 4020 print"[147]":gosub 5000
  64. 4030 printc$;" ";
  65. 4040 for i=1 to h:printc$;c$;:next:printc$
  66. 4050 for j=0 to v
  67. 4060 print c$;
  68. 4070 for i=0 to h
  69. 4080 if m%(i,j) and 2 then print"  ";:goto 4100
  70. 4090 print" ";c$;
  71. 4100 next i:print
  72. 4110 for i=0 to h
  73. 4120 if m%(i,j) and 1 then printc$;" ";:goto 4140
  74. 4130 printc$;c$;
  75. 4140 next i:print c$
  76. 4150 next j
  77. 4160 return
  78. 5000 print"[212]ime:";ti$
  79. 5010 return
  80. 10000 dim p%((h+1)*(v+1)),m%(h,v),t%(3)
  81. 10010 dc=1:c$=chr$(c)
  82. 10020 return
  83. 20000 rem variables
  84. 20010 rem m%(h,v)-maze data
  85. 20020 rem p%(p)  -maze movements
  86. 20030 rem p      -position in p%(-)
  87. 20040 rem h,v    -horiz vert dimensions
  88. 20050 rem r,s    -position in m%(-,-)
  89. 20060 rem i,j    -loop counters
  90. 20070 rem c$     -character
  91. 20080 rem dc     -direction chosen 1-4
  92. 20090 rem t      -no. of different
  93. 20100 rem                directions
  94. 20110 rem t(t)   -different directions
  95. 20120 rem         available
  96.