home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / REXMAZ.ZIP / REXXMAZE.CMD
OS/2 REXX Batch file  |  1992-09-11  |  9KB  |  353 lines

  1. /* Draws a maze using the IBM PC graphics characters */
  2. /*                                                   */
  3. /* Written by James L. Dean                          */
  4. /*            406 40th Street                        */
  5. /*            New Orleans, LA 70124-1532             */
  6. /*                                                   */
  7. CLS
  8. TRUE='1'
  9. FALSE='0'
  10. SAY '                                 Maze Generator'
  11. SAY ' '
  12. SAY ' '
  13. SAY ' '
  14. num_columns=0
  15. DO WHILE ((num_columns < 2) | (num_columns > 39))
  16.   CALL CHAROUT,'Number of columns (2 to 39)? '
  17.   num_columns=LINEIN()
  18.   IF VERIFY(num_columns,'0123456789') \= 0 THEN
  19.     DO
  20.       num_columns=0
  21.       SAY 'Error:  the number of columns must be numeric!'
  22.     END
  23.   ELSE
  24.     DO
  25.       IF ((num_columns < 2) | (num_columns > 39)) THEN
  26.         SAY 'Error:  the number of columns must be between 2 and 39, inclusively!'
  27.     END
  28. END
  29. x_max=2*num_columns
  30. SAY ' '
  31. num_rows=0
  32. DO WHILE ((num_rows < 2) | (num_rows > 20))
  33.   CALL CHAROUT,'Number of rows (2 to 20)? '
  34.   num_rows=LINEIN()
  35.   IF VERIFY(num_rows,'0123456789') \= 0 THEN
  36.     DO
  37.       num_rows=0
  38.       SAY 'Error:  the number of rows must be numeric!'
  39.     END
  40.   ELSE
  41.     DO
  42.       IF ((num_rows < 2) | (num_rows > 20)) THEN
  43.         SAY 'Error:  the number of rows must be between 2 and 20, inclusively!'
  44.     END
  45. END
  46. y_max=2*num_rows
  47. SAY ' '
  48. CALL CHAROUT,'Random number seed? '
  49. seed=LINEIN()
  50. r_n_index_1=1
  51. DO WHILE ((r_n_index_1 <= 8) & (r_n_index_1 <= LENGTH(seed)))
  52.   r_n.r_n_index_1=1+C2D(SUBSTR(seed,r_n_index_1,1))//29
  53.   r_n_index_1=r_n_index_1+1
  54. END
  55. DO WHILE (r_n_index_1 <= 8)
  56.   r_n.r_n_index_1=13
  57.   r_n_index_1=r_n_index_1+1
  58. END
  59. delta_x.1.1=-1
  60. delta_y.1.1=0
  61. delta_x.2.1=0
  62. delta_y.2.1=1
  63. delta_x.3.1=1
  64. delta_y.3.1=0
  65. delta_x.4.1=0
  66. delta_y.4.1=-1
  67. delta_index_2=0
  68. delta_index_1a=1
  69. DO WHILE (delta_index_1a <= 4)
  70.   delta_index_1b=1
  71.   DO WHILE (delta_index_1b <= 4)
  72.     IF delta_index_1a \= delta_index_1b THEN
  73.       DO
  74.         delta_index_1c=1
  75.         DO WHILE (delta_index_1c <= 4)
  76.           IF ((delta_index_1a \= delta_index_1c) & (delta_index_1b \= delta_index_1c)) THEN
  77.             DO
  78.               delta_index_1d=1
  79.               DO WHILE (delta_index_1d <= 4)
  80.                 IF ((delta_index_1a \= delta_index_1d) & (delta_index_1b \= delta_index_1d) & (delta_index_1c \= delta_index_1d)) THEN
  81.                   DO
  82.                     delta_index_2=delta_index_2+1
  83.                     delta_x.delta_index_1a.delta_index_2=delta_x.1.1
  84.                     delta_y.delta_index_1a.delta_index_2=delta_y.1.1
  85.                     delta_x.delta_index_1b.delta_index_2=delta_x.2.1
  86.                     delta_y.delta_index_1b.delta_index_2=delta_y.2.1
  87.                     delta_x.delta_index_1c.delta_index_2=delta_x.3.1
  88.                     delta_y.delta_index_1c.delta_index_2=delta_y.3.1
  89.                     delta_x.delta_index_1d.delta_index_2=delta_x.4.1
  90.                     delta_y.delta_index_1d.delta_index_2=delta_y.4.1
  91.                   END
  92.                 delta_index_1d=delta_index_1d+1
  93.               END
  94.             END
  95.           delta_index_1c=delta_index_1c+1
  96.         END
  97.       END
  98.     delta_index_1b=delta_index_1b+1
  99.   END
  100.   delta_index_1a=delta_index_1a+1
  101. END
  102. x_out=0
  103. DO WHILE (x_out <= x_max)
  104.   y_out=0
  105.   DO WHILE (y_out <= y_max)
  106.     page.y_out.x_out='W'
  107.     y_out=y_out+1
  108.   END
  109.   x_out=x_out+1
  110. END
  111. sum=0
  112. digit_num=1
  113. DO WHILE (digit_num <= 3)
  114.   digit=r_n.1
  115.   r_n_index_1=1
  116.   r_n_index_2=2
  117.   DO WHILE (r_n_index_2 <= 8)
  118.     tem_int_1=r_n.r_n_index_2
  119.     r_n.r_n_index_1=tem_int_1
  120.     digit=digit+tem_int_1
  121.     IF digit > 29 THEN
  122.       digit=digit-29
  123.     r_n_index_1=r_n_index_2
  124.     r_n_index_2=r_n_index_2+1
  125.   END
  126.   r_n.8=digit
  127.   sum=29*sum+digit
  128.   digit_num=digit_num+1
  129. END
  130. x=2*(sum//num_columns)+1
  131. sum=0
  132. digit_num=1
  133. DO WHILE (digit_num <= 3)
  134.   digit=r_n.1
  135.   r_n_index_1=1
  136.   r_n_index_2=2
  137.   DO WHILE (r_n_index_2 <= 8)
  138.     tem_int_1=r_n.r_n_index_2
  139.     r_n.r_n_index_1=tem_int_1
  140.     digit=digit+tem_int_1
  141.     IF digit > 29 THEN
  142.       digit=digit-29
  143.     r_n_index_1=r_n_index_2
  144.     r_n_index_2=r_n_index_2+1
  145.   END
  146.   r_n.8=digit
  147.   sum=29*sum+digit
  148.   digit_num=digit_num+1
  149. END
  150. y=2*(sum//num_rows)+1
  151. page.y.x=' '
  152. stack_head=0
  153. finished=FALSE
  154. DO WHILE (\ finished)
  155.   delta_index_1=1
  156.   too_big=TRUE
  157.   DO WHILE (too_big)
  158.     delta_index_2=r_n.1
  159.     r_n_index_1=1
  160.     r_n_index_2=2
  161.     DO WHILE (r_n_index_2 <= 8)
  162.       tem_int_1=r_n.r_n_index_2
  163.       r_n.r_n_index_1=tem_int_1
  164.       delta_index_2=delta_index_2+tem_int_1
  165.       IF delta_index_2 > 29 THEN
  166.         delta_index_2=delta_index_2-29
  167.       r_n_index_1=r_n_index_2
  168.       r_n_index_2=r_n_index_2+1
  169.     END
  170.     r_n.8=delta_index_2
  171.     IF delta_index_2 <= 24 THEN
  172.       too_big=FALSE
  173.   END
  174.   passage_found=FALSE
  175.   search_complete=FALSE
  176.   DO WHILE (\ search_complete)
  177.     DO WHILE ((delta_index_1 <= 4) & (\ passage_found))
  178.       x_next=x+2*delta_x.delta_index_1.delta_index_2
  179.       IF x_next <= 0 THEN
  180.         delta_index_1=delta_index_1+1
  181.       ELSE
  182.         IF x_next >= x_max THEN
  183.           delta_index_1=delta_index_1+1
  184.         ELSE
  185.           DO
  186.             y_next=y+2*delta_y.delta_index_1.delta_index_2
  187.             IF y_next <= 0 THEN
  188.               delta_index_1=delta_index_1+1
  189.             ELSE
  190.               IF y_next >= y_max THEN
  191.                 delta_index_1=delta_index_1+1
  192.               ELSE
  193.                 IF page.y_next.x_next = 'W' THEN
  194.                   passage_found=TRUE
  195.                 ELSE
  196.                   delta_index_1=delta_index_1+1
  197.           END
  198.     END
  199.     IF (\ passage_found) THEN
  200.       DO
  201.         IF (stack_head > 0) THEN
  202.           DO
  203.             delta_index_1=stack.index_1.stack_head
  204.             delta_index_2=stack.index_2.stack_head
  205.             x=x-2*delta_x.delta_index_1.delta_index_2
  206.             y=y-2*delta_y.delta_index_1.delta_index_2
  207.             stack_head=stack_head-1
  208.             delta_index_1=delta_index_1+1
  209.           END
  210.       END
  211.     search_complete=((passage_found) | ((stack_head = 0) & (delta_index_1 > 4)))
  212.   END
  213.   IF passage_found THEN
  214.     DO
  215.       stack_head=stack_head+1
  216.       stack.index_1.stack_head=delta_index_1
  217.       stack.index_2.stack_head=delta_index_2
  218.       page.y_next.x_next=' '
  219.       IF x = x_next THEN
  220.         DO
  221.           y_wall_1=(y+y_next)%2
  222.           page.y_wall_1.x_next=' '
  223.         END
  224.       ELSE
  225.         DO
  226.           x_wall_1=(x+x_next)%2
  227.           page.y_next.x_wall_1=' '
  228.         END
  229.       x=x_next
  230.       y=y_next
  231.     END
  232.   IF stack_head = 0 THEN
  233.     finished=TRUE
  234. END
  235. page.0.1=' '
  236. x_minus_1=x_max-1
  237. page.y_max.x_minus_1=' '
  238. CLS
  239. line='b3'x
  240. x=1
  241. DO WHILE (x < x_max)
  242.   IF page.0.x = 'W' THEN
  243.     line=line||'c4'x
  244.   ELSE
  245.     line=line||' '
  246.   x=x+1
  247.   IF x < x_max THEN
  248.     DO
  249.       IF page.1.x = 'W' THEN
  250.         line=line||'c2'x
  251.       ELSE
  252.         line=line||'c4'x
  253.       x=x+1
  254.     END
  255. END
  256. line=line||'bf'x
  257. SAY line
  258. line=''
  259. y=2
  260. DO WHILE (y < y_max)
  261.   IF page.y.1 = 'W' THEN
  262.     line=line||'c3'x
  263.   ELSE
  264.     line=line||'b3'x
  265.   x=1
  266.   DO WHILE (x < x_max)
  267.     IF page.y.x = 'W' THEN
  268.       line=line||'c4'x
  269.     ELSE
  270.       line=line||' '
  271.     x=x+1
  272.     IF x < x_max THEN
  273.       DO
  274.         x_minus_1=x-1
  275.         x_plus_1=x+1
  276.         y_minus_1=y-1
  277.         y_plus_1=y+1
  278.         IF page.y.x_minus_1 = 'W' THEN
  279.           IF page.y_minus_1.x = 'W' THEN
  280.             IF page.y_plus_1.x = 'W' THEN
  281.               IF page.y.x_plus_1 = 'W' THEN
  282.                 line=line||'c5'x
  283.               ELSE
  284.                 line=line||'b4'x
  285.             ELSE
  286.               IF page.y.x_plus_1 = 'W' THEN
  287.                 line=line||'c1'x
  288.               ELSE
  289.                 line=line||'d9'x
  290.           ELSE
  291.             IF page.y_plus_1.x = 'W' THEN
  292.               IF page.y.x_plus_1 = 'W' THEN
  293.                 line=line||'c2'x
  294.               ELSE
  295.                 line=line||'bf'x
  296.             ELSE
  297.               line=line||'c4'x
  298.         ELSE
  299.           IF page.y_minus_1.x = 'W' THEN
  300.             IF page.y_plus_1.x = 'W' THEN
  301.               IF page.y.x_plus_1 = 'W' THEN
  302.                 line=line||'c3'x
  303.               ELSE
  304.                 line=line||'b3'x
  305.             ELSE
  306.               IF page.y.x_plus_1 = 'W' THEN
  307.                 line=line||'c0'x
  308.               ELSE
  309.                 line=line||'b3'x
  310.           ELSE
  311.             IF page.y_plus_1.x = 'W' THEN
  312.               IF page.y.x_plus_1 = 'W' THEN
  313.                 line=line||'da'x
  314.               ELSE
  315.                 line=line||'b3'x
  316.             ELSE
  317.               IF page.y.x_plus_1 = 'W' THEN
  318.                 line=line||'c4'x
  319.               ELSE
  320.                 line=line||' '
  321.         x=x_plus_1
  322.       END
  323.   END
  324.   x_minus_1=x_max-1
  325.   IF page.y.x_minus_1 = 'W' THEN
  326.     line=line||'b4'x
  327.   ELSE
  328.     line=line||'b3'x
  329.   y=y+2
  330.   SAY line
  331.   line=''
  332. END
  333. line=line||'c0'x
  334. x=1
  335. DO WHILE (x < x_max)
  336.   IF page.y_max.x = 'W' THEN
  337.     line=line||'c4'x
  338.   ELSE
  339.     line=line||' '
  340.   x=x+1
  341.   IF x < x_max THEN
  342.     DO
  343.       y_minus_1=y_max-1
  344.       IF page.y_minus_1.x = 'W' THEN
  345.         line=line||'c1'x
  346.       ELSE
  347.         line=line||'c4'x
  348.       x=x+1
  349.     END
  350. END
  351. line=line||'b3'x
  352. SAY line
  353.