Automatic Randomized Maze Generator
Some background:
- This maze was inspired by this gif: http://kidscancode.org/blog/img/maze_demo1.gif
- Several observations about the gif can be made:
- Decision making: In brand new uncharted territory, the decision about which direction to take (whether up, down, left or right) is essentially random. However, as the map begins to evolve into a mix of both charted and uncharted territory, performing a survey of available directions becomes helpful. A decision is then made from among the available directions.
- Lining the path: After a decision is made, we build walls to outline the path (this is a maze after all). More importantly, we also need to build a pseudo-wall (think of it as a supporting arch) through which we can pass. This supporting arch is important because it forms a marker NOT to build any walls here in the future (we don't want to cut off the path we just set).
- Deadends: When we walk ourselves into a deadend (i.e., we are surrounded by walls and/or all adjacent tiles around us have been explored), there needs to be a way to reach new uncharted territory. We have 2 alternatives:
- Check around you for existing walls and if there is an undiscovered tile behind that wall. If you find one, breakthrough the wall and step onto the new undiscovered tile.
- Most of the time, this won't happen. This is when you'll need to backtrack and follow the path you came from. So, set up a system to record your coordinates too!
Comments
Post a Comment