Author Topic: Maze Generator 8  (Read 3187 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Maze Generator 8
« on: January 16, 2021, 05:27:56 pm »
Like the others, this one doesn't find a path. And like the others it randomly puts walls and exits. But I think this is my best so far. Check out the picture to see what kind of maze it makes. Since it doesn't find a path, maybe 1/4 or so of them doesn't work, so just press the Space Bar to make a new one. I also added clipboard to it so people can copy it using the C key (not CTRL C, just C) and then paste it into their favorite graphics program to save or print. Like my other ones, it's a white background with black walls. I made a similar one I think last Summer using circles instead of boxes, but this one looks more like a regular maze.

Code: QB64: [Select]
  1. 'Maze Generator 8 - by SierraKen
  2. 'Made on January 16, 2021.
  3. 'Not every maze works so use the Space Bar to make ones that do.
  4. 'Press C to copy to clipboard so you can paste it into your favorite graphics program.
  5. 'From there you can save it or print it to your printer.
  6. '-------------------------------------------------------------------------------------
  7. 'This little program doesn't find a path, instead it randomly chooses areas to make walls and exits after making a bunch of boxes.
  8. 'After trial and error I believe this is as good, or almost as good as it gets for this type of maze.
  9.  
  10. _TITLE "Space Bar for new maze. C = Copy to clipboard. Not every maze works. "
  11. DIM maze AS LONG
  12. start:
  13. IF maze& <> 0 THEN SCREEN _NEWIMAGE(600, 600, 32): _FREEIMAGE maze&
  14. maze& = _NEWIMAGE(600, 600, 32)
  15. SCREEN maze&
  16. PAINT (2, 2), _RGB32(255, 255, 255)
  17. LINE (50, 50)-(550, 550), _RGB32(0, 0, 0), B
  18. LINE (275, 550)-(325, 550), _RGB32(255, 255, 255)
  19.  
  20. FOR boxes = 50 TO 225 STEP 25
  21.     LINE (300 - boxes, 300 - boxes)-(300 + boxes, 300 + boxes), _RGB32(0, 0, 0), B
  22. NEXT boxes
  23. FOR lx = 50 TO _WIDTH - 100
  24.     FOR ly = 50 TO _HEIGHT - 100
  25.         IF POINT(lx, ly) = _RGB32(0, 0, 0) AND POINT(lx + 25, ly) = _RGB32(0, 0, 0) THEN
  26.             IF INT(RND * 1000) + 1 > 996 THEN
  27.                 LINE (lx, ly)-(lx + 25, ly), _RGB32(0, 0, 0)
  28.                 LINE (lx + 25, ly)-(lx + 25, ly + 25), _RGB32(255, 255, 255)
  29.             END IF
  30.         END IF
  31.         IF POINT(lx, ly) = _RGB32(0, 0, 0) AND POINT(lx, ly + 25) = _RGB32(0, 0, 0) THEN
  32.             IF INT(RND * 1000) + 1 > 996 THEN
  33.                 LINE (lx, ly)-(lx, ly + 25), _RGB32(0, 0, 0)
  34.                 LINE (lx, ly + 25)-(lx + 25, ly + 25), _RGB32(255, 255, 255)
  35.             END IF
  36.         END IF
  37.         'Make more exits.
  38.         FOR a = 1 TO 2
  39.             IF POINT(lx, ly) = _RGB32(0, 0, 0) AND POINT(lx + 25, ly) = _RGB32(0, 0, 0) AND lx > 190 AND lx < 460 THEN
  40.                 IF INT(RND * 1000) + 1 > 996 THEN
  41.                     LINE (lx + 25, ly)-(lx + 25, ly + 25), _RGB32(255, 255, 255)
  42.                 END IF
  43.             END IF
  44.             IF POINT(lx, ly) = _RGB32(0, 0, 0) AND POINT(lx, ly + 25) = _RGB32(0, 0, 0) AND lx > 190 AND lx < 460 THEN
  45.                 IF INT(RND * 1000) + 1 > 996 THEN
  46.                     LINE (lx, ly + 25)-(lx + 25, ly + 25), _RGB32(255, 255, 255)
  47.                 END IF
  48.             END IF
  49.         NEXT a
  50.     NEXT ly
  51. NEXT lx
  52.     _LIMIT 30
  53.     a$ = INKEY$
  54.     IF a$ = CHR$(27) THEN END
  55.     IF a$ = " " THEN GOTO start:
  56.     IF a$ = "c" OR a$ = "C" THEN _CLIPBOARDIMAGE = maze&
  57. GOTO start:
  58.  
Maze Generator 8.jpg
* Maze Generator 8.jpg (Filesize: 42.75 KB, Dimensions: 600x600, Views: 211)

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Maze Generator 8
« Reply #1 on: January 16, 2021, 07:53:41 pm »
Post deleted.
« Last Edit: January 17, 2021, 11:30:13 am by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Maze Generator 8
« Reply #2 on: January 17, 2021, 02:53:43 pm »
Here is an update. I did it 38 times before I got a maze that didn't have an ending. It makes easier mazes but I like this one better. Here's a picture of this one below. I hope some of you use this.

Code: QB64: [Select]
  1. 'Maze Generator 8 - by SierraKen
  2. 'Made on January 17, 2021.
  3. 'Not every maze works so use the Space Bar to make ones that do.
  4. 'Press C to copy to clipboard so you can paste it into your favorite graphics program.
  5. 'From there you can save it or print it to your printer.
  6. '-------------------------------------------------------------------------------------
  7. 'This little program doesn't find a path, instead it randomly chooses areas to make walls and exits after making a bunch of boxes.
  8. 'After trial and error I believe this is as good, or almost as good as it gets for this type of maze.
  9.  
  10. _TITLE "Space Bar for new maze. C = Copy to clipboard. Not every maze works. "
  11. DIM maze AS LONG
  12. start:
  13. IF maze& <> 0 THEN SCREEN _NEWIMAGE(600, 600, 32): _FREEIMAGE maze&
  14. maze& = _NEWIMAGE(600, 600, 32)
  15. SCREEN maze&
  16. PAINT (2, 2), _RGB32(255, 255, 255)
  17. LINE (50, 50)-(550, 550), _RGB32(0, 0, 0), B
  18. LINE (275, 550)-(325, 550), _RGB32(255, 255, 255)
  19.  
  20. FOR boxes = 50 TO 225 STEP 25
  21.     LINE (300 - boxes, 300 - boxes)-(300 + boxes, 300 + boxes), _RGB32(0, 0, 0), B
  22. NEXT boxes
  23. FOR lx = 50 TO _WIDTH - 100
  24.     FOR ly = 50 TO _HEIGHT - 100
  25.         IF POINT(lx, ly) = _RGB32(0, 0, 0) AND POINT(lx + 25, ly) = _RGB32(0, 0, 0) THEN
  26.             IF INT(RND * 100) + 1 > 99 THEN
  27.                 LINE (lx, ly)-(lx + 25, ly), _RGB32(0, 0, 0)
  28.                 LINE (lx + 25, ly)-(lx + 25, ly + 25), _RGB32(255, 255, 255)
  29.             END IF
  30.         END IF
  31.         IF POINT(lx, ly) = _RGB32(0, 0, 0) AND POINT(lx, ly + 25) = _RGB32(0, 0, 0) THEN
  32.             IF INT(RND * 100) + 1 > 99 THEN
  33.                 LINE (lx, ly)-(lx, ly + 25), _RGB32(0, 0, 0)
  34.                 LINE (lx, ly + 25)-(lx + 25, ly + 25), _RGB32(255, 255, 255)
  35.             END IF
  36.         END IF
  37.         'Make more exits.
  38.         FOR a = 1 TO 2
  39.             IF POINT(lx, ly) = _RGB32(0, 0, 0) AND POINT(lx + 25, ly) = _RGB32(0, 0, 0) AND lx > 190 AND lx < 460 THEN
  40.                 IF INT(RND * 100) + 1 > 99 THEN
  41.                     LINE (lx + 25, ly)-(lx + 25, ly + 25), _RGB32(255, 255, 255)
  42.                 END IF
  43.             END IF
  44.             IF POINT(lx, ly) = _RGB32(0, 0, 0) AND POINT(lx, ly + 25) = _RGB32(0, 0, 0) AND lx > 190 AND lx < 460 THEN
  45.                 IF INT(RND * 100) + 1 > 99 THEN
  46.                     LINE (lx, ly + 25)-(lx + 25, ly + 25), _RGB32(255, 255, 255)
  47.                 END IF
  48.             END IF
  49.         NEXT a
  50.     NEXT ly
  51. NEXT lx
  52.  
  53. 'LINE (250, 250)-(350, 350), _RGB32(255, 0, 0), B
  54. 'LINE (225, 225)-(375, 375), _RGB32(0, 0, 255), B
  55. 'LINE (200, 200)-(400, 400), _RGB32(0, 255, 0), B
  56. 'LINE (175, 175)-(425, 425), _RGB32(0, 255, 255), B
  57.  
  58.  
  59.  
  60.     _LIMIT 30
  61.     a$ = INKEY$
  62.     IF a$ = CHR$(27) THEN END
  63.     IF a$ = " " THEN GOTO start:
  64.     IF a$ = "c" OR a$ = "C" THEN _CLIPBOARDIMAGE = maze&
  65. GOTO start:
  66.  
Maze Generator 8 - 2.jpg
* Maze Generator 8 - 2.jpg (Filesize: 45.85 KB, Dimensions: 600x600, Views: 175)

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Maze Generator 8
« Reply #3 on: January 17, 2021, 03:14:48 pm »
I decided to make it more than double as hard with 10 pixel hallways instead of 25. This one is more fun to use. After 13 mazes it got to one that didn't have an exit.
A picture of this one is also below.

Code: QB64: [Select]
  1. 'Maze Generator 8 - by SierraKen
  2. 'Made on January 17, 2021.
  3. 'Not every maze works so use the Space Bar to make ones that do.
  4. 'Press C to copy to clipboard so you can paste it into your favorite graphics program.
  5. 'From there you can save it or print it to your printer.
  6. '-------------------------------------------------------------------------------------
  7. 'This little program doesn't find a path, instead it randomly chooses areas to make walls and exits after making a bunch of boxes.
  8.  
  9. _TITLE "Space Bar for new maze. C = Copy to clipboard. Not every maze works. "
  10. DIM maze AS LONG
  11. start:
  12. IF maze& <> 0 THEN SCREEN _NEWIMAGE(600, 600, 32): _FREEIMAGE maze&
  13. maze& = _NEWIMAGE(600, 600, 32)
  14. SCREEN maze&
  15. PAINT (2, 2), _RGB32(255, 255, 255)
  16.  
  17. FOR boxes = 50 TO 270 STEP 10
  18.     LINE (300 - boxes, 300 - boxes)-(300 + boxes, 300 + boxes), _RGB32(0, 0, 0), B
  19. NEXT boxes
  20. LINE (275, 570)-(325, 570), _RGB32(255, 255, 255)
  21.  
  22. FOR lx = 50 TO _WIDTH - 50
  23.     FOR ly = 50 TO _HEIGHT - 50
  24.         IF POINT(lx, ly) = _RGB32(0, 0, 0) AND POINT(lx + 10, ly) = _RGB32(0, 0, 0) THEN
  25.             IF INT(RND * 100) + 1 > 99 THEN
  26.                 LINE (lx, ly)-(lx + 10, ly), _RGB32(0, 0, 0)
  27.                 LINE (lx + 10, ly)-(lx + 10, ly + 10), _RGB32(255, 255, 255)
  28.             END IF
  29.         END IF
  30.         IF POINT(lx, ly) = _RGB32(0, 0, 0) AND POINT(lx, ly + 10) = _RGB32(0, 0, 0) THEN
  31.             IF INT(RND * 100) + 1 > 99 THEN
  32.                 LINE (lx, ly)-(lx, ly + 10), _RGB32(0, 0, 0)
  33.                 LINE (lx, ly + 10)-(lx + 10, ly + 10), _RGB32(255, 255, 255)
  34.             END IF
  35.         END IF
  36.         'Make more exits.
  37.         FOR a = 1 TO 2
  38.             IF POINT(lx, ly) = _RGB32(0, 0, 0) AND POINT(lx + 10, ly) = _RGB32(0, 0, 0) AND lx > 190 AND lx < 460 THEN
  39.                 IF INT(RND * 100) + 1 > 99 THEN
  40.                     LINE (lx + 10, ly)-(lx + 10, ly + 10), _RGB32(255, 255, 255)
  41.                 END IF
  42.             END IF
  43.             IF POINT(lx, ly) = _RGB32(0, 0, 0) AND POINT(lx, ly + 10) = _RGB32(0, 0, 0) AND lx > 190 AND lx < 460 THEN
  44.                 IF INT(RND * 100) + 1 > 99 THEN
  45.                     LINE (lx, ly + 10)-(lx + 10, ly + 10), _RGB32(255, 255, 255)
  46.                 END IF
  47.             END IF
  48.         NEXT a
  49.     NEXT ly
  50. NEXT lx
  51.  
  52.     _LIMIT 30
  53.     a$ = INKEY$
  54.     IF a$ = CHR$(27) THEN END
  55.     IF a$ = " " THEN GOTO start:
  56.     IF a$ = "c" OR a$ = "C" THEN _CLIPBOARDIMAGE = maze&
  57. GOTO start:
  58.  

Maze Generator 8 - harder.jpg
* Maze Generator 8 - harder.jpg (Filesize: 124.51 KB, Dimensions: 600x600, Views: 189)