(42) Maze generator algorithm
|
06-29-2021, 12:18 AM
(This post was last modified: 06-29-2021 12:24 AM by arhtur.)
Post: #1
|
|||
|
|||
(42) Maze generator algorithm
I'm not sure if this is a previously implemented algorithm. I have found that a maze can be generated if an array of pillars are drawn, and a wall is drawn as follows:
From top border: draw a wall from a pillar either above or to the right. From right border: draw a wall from a pillar either to the right or below. From the bottom border: draw a wall from a pillar either below or to the left. From the left border: draw a wall from a pillar either to the left or above. A pattern has to be followed, where these walls are drawn first from the outer part of the maze to the inner. A random number Z is either 0 or 1. Then, from the top border, the X and Y coordinate of the wall to draw are determined from the following 2 equations, where px and py are the coordinates of the pillar. X=Z+px Y=Z-1+py If Z is 0, then X=px and Y=py-1 (draw a wall above the pillar) If Z is 1, then X=px+1 and Y=py (draw a wall to the right of the pillar) This same approach is used to draw walls from pillars from the other 3 borders. When the algorithm reaches the middle of the screen, there is a small row remaining, so one of 3 directions to draw a wall is picked (4 directions cannot be used, because overlap of walls is possible). When run on a 42s, it is easier to see the algorithm work to generate the maze. On Free42 and the DM42 it runs much faster and almost instantly, you see the maze. This can run on the HP 42s, Free42 and the DM42. Code:
|
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)