CodingTrain / CodingTrain/Suggestion-Box
topic: random maze genorator
- Dominant language
- No language data
- Stars
- 570
- Forks
- 85
- PR merge metrics
- No merged PRs in 30d
Description
I found a way to generate a random maze from a point. I have not found any article about it but i tried programing it and can write some pseudocode.
The main idea:
Draw a point.
Draw another point X far from the first one and draw a line to it.
Pick one of the points and draw another point X far from it and draw a line to that point.
and so on but you only have to follow one rule:
**never let two points go closer than X far from each other**
it is not as easy as it sounds because of lag but i think a quadtree would work.
[https://codepen.io/ProGramer31415/pen/BxPWXx](url)
Here is some pseudocode, I am not good at writing pseudocode:
```
class node {
main(x, y) {
keep position of node
create an array of nodes created from this node, starts empty
}
addChild(x, y) {
create new child at x, y
add child to array of children
}
draw() {
draw line from node to all children
}
}
class maze {
main(segment-length) {
create array / quadtree of nodes and add one node to it
create variable with length of each segment
}
update() {
pick a random node
pick a random position segment-length far from the node
check if the random position is legal with moveLegal
if its legal {
add a new kid to the random node with the random position
add the kid to the array of nodes
}
}
moveLegal(x, y) {
check if the length to the closest node in the mazes array of nodes is more than segment-length.
if so return true
else return false
}
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.