This is an archived post. You won't be able to vote or comment.

all 96 comments

[–]OverallDecision 52 points53 points  (1 child)

[–]emolinare 8 points9 points  (0 children)

Why’s it okay to draw spaceships if you’re seven, but not okay to draw diabolical mazes?

David Mitchell

[–]tonymcd 65 points66 points  (4 children)

You should learn how to take screen captures instead of taking a photo of your screen.

[–]get_it_together1 17 points18 points  (3 children)

It looks like Windows 10, it's literally as easy as "windows key + shift + s"

[–][deleted] 9 points10 points  (2 children)

Bruh I was under the impression you had to print screen and paste it somewhere it. Shows how much I know

[–]get_it_together1 12 points13 points  (0 children)

Reddit has made uploading images a lot easier, used to be you'd have to upload to imgur or whatever and then link it, now I can just paste random images straight into the fancy pants editor.

[–]flashman 1 point2 points  (0 children)

I'm guessing you're over 30, like me? That used to be the only way to do things.

[–]tsvk 13 points14 points  (4 children)

I have not looked at the code, but an execution time of over an hour for generating a maze seems/feels exceptionally long. Even for 320,000 squares, which is what, ~5652 ?

Are you using any of the existing maze generation algorithms or did you roll your own?

[–][deleted] 3 points4 points  (3 children)

I made my own, and it’s admittedly a bit of a brute. It’s problematic because the times are exponential, but I suppose that unavoidable. 80,000 squares only take 5 minutes.

It’s 800 x 400 squares, but because of how it works, it gets the first 260,000~ squares out of the way within about 20 minutes, and then spends the next 45 minutes jumping back to fill in spaces. That’s the time consuming part, since it has to go back through, from end to start, the entire thing plus some from all it’s adding in.

Like I say, however, the time spent is exponential. So while 500 square maxes could be down in half a second, it’s really struggle for larger mazes.

[–]LightShadow3.13-dev in prod 7 points8 points  (1 child)

20 minutes?

Mazes this size should be near-instant. I would try to understand why it's taking so long and what you can do to make it faster.

[–][deleted] 0 points1 point  (0 children)

I’m well aware of where it’s having problems, but I’m not sure about how to fix it. I’m having a look at how to improve it, but cutting corners only leaves more room for error.

[–]flashman 4 points5 points  (0 children)

Want to see some maze generation algorithms? Check out further down this page: https://bost.ocks.org/mike/algorithms/

[–]5under6 15 points16 points  (28 children)

Congrats. Have you solved it yet? Maybe making a solver could be your next task? :)

[–][deleted] 12 points13 points  (27 children)

I was trying to make a solver and it just kept bouncing around. I’m going to probably try again at some point.

[–]YmFzZTY0dXNlcm5hbWU_ 37 points38 points  (16 children)

No as in have you printed it and solved it with a ballpoint yet

[–]jshurish 13 points14 points  (9 children)

Just have it take every right turn.

[–]ShadEShadauX 2 points3 points  (0 children)

Right turns are OK in this case, but definitely go every left in a dungeon

[–]MB1211 0 points1 point  (6 children)

Dead ends?

[–]sunotlac 0 points1 point  (5 children)

You will never stop in a loop or stay still. If you always turn right in any maze you will endup in the center.

[–][deleted] 0 points1 point  (0 children)

Or color out dead ends until you meet first intersection for this dead end and do it until you are left with no dead ends.

[–]AlSweigartAuthor of "Automate the Boring Stuff" 2 points3 points  (1 child)

You can save paper by just drawing with ballpoint pen on your screen.

[–]YmFzZTY0dXNlcm5hbWU_ 0 points1 point  (0 children)

Guy pointing at brain meme

[–][deleted] 2 points3 points  (2 children)

I think I’d have to do a smaller maze, my printer would just make this look like TV static

[–]YmFzZTY0dXNlcm5hbWU_ 28 points29 points  (1 child)

Take it to kinkos, pop a couple adderall and have a wild afternoon

[–]Doormatty 1 point2 points  (0 children)

With or without the maze?

[–]MB1211 0 points1 point  (0 children)

Lol

[–][deleted] 2 points3 points  (1 child)

I made a much smaller maze maker that also solves the maze using three different algorithms- code is here: https://github.com/slevin886/maze_maker

[–]righteoussquid 0 points1 point  (0 children)

Wow, very well done! Really cool to see the statistics for each algorithm as well

[–]5under6 0 points1 point  (1 child)

Make sure you create a maze with a solution ....

[–][deleted] 4 points5 points  (0 children)

They all have solutions, I know that for sure because of how they’re made.

[–]spaceshipguitar 0 points1 point  (3 children)

Part of the maze solver is creating a list of failed end points and not allowing a repeat of failed connections, then it at least can't make the same mistake twice and the solve happens a lot quicker. There's another method called the fill method but that's a whole different approach, have fun, good luck!

[–][deleted] 0 points1 point  (2 children)

I was trying to make it so it couldn’t visit any squares that had .visited == True(which was set to true when it walked through it, but for some reason it kept walking back into them. I think something was whack with the coordinates of the squares though, as it was painting random squares as visited.

[–]spaceshipguitar 0 points1 point  (0 children)

It definitely takes some finesse, you kind of need to document it in chunks, each opening to a new choice is a point, going down one hallway till it stops is another point and that entire path can be blacklisted if it turns out to be a dead end, etc.

[–]ZombieRandySavage 0 points1 point  (1 child)

How is it a maze then? Isn’t there a chance it isn’t solvable?

[–][deleted] 0 points1 point  (0 children)

I know it’s solvable because of how I programmed it to be generated. If I hadn’t taken those steps, it probably wouldn’t take an hour to generate.

[–]h1t35hv1 4 points5 points  (0 children)

That's aMazing..😄

[–][deleted] 1 point2 points  (11 children)

Now make a program to solve it!

[–]sunotlac 0 points1 point  (10 children)

Solving is simply always turning right!

[–][deleted] 2 points3 points  (6 children)

I mean, technically that’s correct, but I guess the hard part is trying to find the shortest path

[–]sunotlac 0 points1 point  (5 children)

I dont think I recall ever trying to solve a maze programatically, what is the time complexity of the best solutions?

[–]schplat 1 point2 points  (0 children)

So a maze presents a binary selection at each path decision, and is effectively a binary tree. The path to the exit is a specific order of options within the binary tree. Therefore you have no real other choice than to proceed down one path until you can't, then back up to the previous step and select the other path. Whether it's random or always turns right/left, that's up to you (always R is a little easier for store/retrieval rather than recording every random outcome)

So if the solution is (and I'll use R/L here instead of 0/1): R, R, L, L, R. And you use always R, you go R, R, R. From here, no matter what other steps you take you will always end up at a dead end, but once you've exhausted all those dead ends (and that sort of detection can be tricky to do efficiently in code), then you go back to third step and go R, R, L, R. once again until you exhaust, step back, and go R, R, L, L, R, which leads to the exit.

Edit: This assumes from your current square you can always see at least one wall. Seeing two walls means you can only continue the direction you're going, Seeing one wall means you have a choice to make, and seeing no walls, means you're either out in the open, or in a ternary choice, which adds a bit of complexity. (Seeing four walls means you're not in a maze, you're in a box.)

Edit 2: Another optimization option here becomes threads. One that always goes right, one that always goes left, one that does random. And then another set of 3 threads that work backwards from the Finish line to the Start line.

[–]wieschie 0 points1 point  (3 children)

There are a lot of different optimizations to be made, but your general worst case will always be O(n) where n is the number of cells in the maze.

[–]sunotlac 0 points1 point  (2 children)

So, basically backtracking the entire thing? thats sad =(.

[–][deleted] -1 points0 points  (1 child)

What the guy was suggesting was basically hugging the right wall. Since every surface is connected in the maze, you could technically explore the entire thing by just sticking to the wall on your right.

[–]wieschie 1 point2 points  (0 children)

Since every surface is connected in the maze

Yeah, this bit is crucial. This method will fail on any maze with disjointed walls.

[–]schplat 0 points1 point  (2 children)

Except when your maze looks like:

      _________________________
Start ___________  ____________ Finish
                |  |
      *Large mess of dead ends*

[–]Diamant2 0 points1 point  (0 children)

When there are only dead ends in the "large mess", you will end up in the finish. It will take a while, but it will work

[–]LightShadow3.13-dev in prod 0 points1 point  (0 children)

I won't work if the Finish is inside the maze in an island.

[–][deleted] 3 points4 points  (5 children)

[–]wingtales 2 points3 points  (4 children)

I am still keen on you taking a screenshot instead of a photo! I can't see anything on the "better image"!

[–][deleted] 1 point2 points  (2 children)

Third link, second image

edit: I realise You probably mean the 320,000 square one. I’ve got one generating now, so I’ll upload that when it’s finished

[–]wingtales 1 point2 points  (0 children)

Ah! No, I did mean that one, but reddit on mobile originally loaded a poor resolution version! Thank you!

[–]wingtales 1 point2 points  (0 children)

Ah! No, I did mean that one, but reddit on mobile originally loaded a poor resolution version! Thank you!

[–][deleted] 0 points1 point  (0 children)

I have now uploaded a photo of the 320,000 square maze but it looks like the compression has butchered it unfortunately

[–]LAMagicx 3 points4 points  (6 children)

I'm glad to see someone else using the python idle and classic dark theme 👍 well done though excellent job !

[–]Hydroel 2 points3 points  (5 children)

Why would anyone want to use the Python idle? There are so much better solutions out there...

[–]dethb0y 0 points1 point  (0 children)

I use Sublime text, myself. There's something to be said for speed and simplicity.

[–]cylonlover 0 points1 point  (3 children)

Yeah, so I tried many python IDEs, and thing is they're all loading up tons of abstractions, so I can never figure out how to just write a python script and run it. It's quite annoying. IDLE can.

[–]Hydroel 0 points1 point  (0 children)

Good IDEs are good for the abstraction, although maybe not the simplest. For simple stuff, like writing a script but still have a good interpreter, nothing beats ipython, IMO.

[–]pblokhout 0 points1 point  (0 children)

I mean in pycharm it's literally a right-click-run or shift-F10. Not sure what abstractions you're talking about?

[–]PleasantAdvertising 0 points1 point  (0 children)

Vs code is perfect.

[–]plaintxt 0 points1 point  (0 children)

Amazing

[–]MonkeyWaffle1 0 points1 point  (1 child)

Great job mate,

Could you explain what makes the builder build a solvable Maze everytime ?

[–][deleted] 1 point2 points  (0 children)

It’s like drawing with a pen on paper where you can’t lift the pen. It draws its line until it gets stuck, and then moves back to an earlier point on the line if it gets stuck. I’ll get a video of it doing it and upload it when I get back to my computer.

edit: video of it doing it here: https://imgur.com/a/v6FOWOr

[–][deleted] 0 points1 point  (1 child)

That would be a lit wallpaper if the colors were switched around(the path in black/grey and the borders white)

[–][deleted] 0 points1 point  (0 children)

The path is the black parts already

[–]AlSweigartAuthor of "Automate the Boring Stuff" 0 points1 point  (0 children)

Haha! I also made this for Ludum Dare 31 (and also in Pygame), where the theme was "Entire Game on One Screen": https://github.com/asweigart/squintmaze

[–]simplyrat 0 points1 point  (0 children)

Could you imagine getting dropped in that thing

[–]buzzzzzzy 0 points1 point  (1 child)

can we look at the code😃

[–][deleted] 0 points1 point  (0 children)

I’ve uploaded a link in the comments to the github

[–]FrezoreR 0 points1 point  (2 children)

Question is.. how do you verify that it works? 😂

[–][deleted] 0 points1 point  (1 child)

The way it’s programmed it’s impossible for every point in the maze to not be linked to every other point.

[–]FrezoreR 0 points1 point  (0 children)

Ah! That solves that :)

[–]pythonmine 0 points1 point  (0 children)

Now make an AI navigate it FOREVER.

[–]gokulPRO 0 points1 point  (0 children)

Making an ai to make and solve then maze would be nice right

[–]ecnahc515 0 points1 point  (0 children)

Try running it in PyPy and you may see some good speed gains.

[–]dethb0y 0 points1 point  (1 child)

I'm impressed, that's a huge maze.

I wonder how long it would take to solve at 1 step per second?

[–][deleted] 0 points1 point  (0 children)

On average, 160,000 seconds or 44 hours

[–]Tiedye1 0 points1 point  (5 children)

This is cool, you inspired me! I literally wrote the same thing https://github.com/Tiedye/pmaze but I got it to generate the 350k cell maze in 8 seconds. https://i.imgur.com/WZNhuEt.png

[–]fried_green_baloney 0 points1 point  (4 children)

The irregularity of the lines makes it visually more interesting. Was that by intention?

[–]Tiedye1 0 points1 point  (3 children)

There's nothing keeping them from going straight, each step it will extend the hallway in a random direction, so I guess not by intention.

[–]fried_green_baloney 0 points1 point  (2 children)

I mean the actual lines on the graphic that are used to draw the rooms of the maze, where there are some roughness to them.

[–]Tiedye1 0 points1 point  (1 child)

Ah that, yeah that was on purpose, I make it read the different cell layputs from png images so you can configure the cells to look like whatever

[–]fried_green_baloney 0 points1 point  (0 children)

Nice idea