-
Notifications
You must be signed in to change notification settings - Fork 70
Make Maze Generation Iterative #944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
1aedb88 to
57763b2
Compare
|
Force-pushed to remove changes introduced by running |
|
Oh wow, this is very cool, thanks! Given that you don't seem to have changed the order of things, this new implementation should give the very same mazes as the old recursive one if started with the same random seed, right? Can you test that? |
I mean, I trust Otherwise I am very very happy to see recursion gone. Now I understand better what happens. And it makes it also clear why you need an infinite loop and why you can not know in advance the number of partitions. The infinite loop is guaranteed to exit? I am not sure I can prove that... |
I tested with # on main
for i in $(seq 100); do pelita --seed $i --store-layout old/$i.layout; done
# on make-maze-generation-iterative
for i in $(seq 100); do pelita --seed $i --store-layout new/$i.layout; doneand which shows nothing (every file's content is the same in both directories) and sha256sum old/* | awk '{print $1 }' | old.txt
sha256sum new/* | awk '{print $1 }' | new.txtwhich yields 1000 mazes would have taken a fair amount of time, but I think 100 mazes is also quite assuring. |
It is always exiting, since the position of the walls So, partitions always shrink, no new partitions are added once they shrank below a threshold, and the loop increases the list index in every case. |
Yes, thanks, perfect! |
Great explanation, could you add this as a comment in the function for future reference? |
otizonaizit
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks , that's very straightforward. If you could add the explanation of the guaranteed loop exit in the function I will merge right away ;)
|
Done |
Make Maze Generation Iterative d2c6f14
|
👍 Not sure if the partition index |
|
Yes, you are right, we could drop that index and realize the routine with partitions.pop(0)
...
partitions.insert(0, new[1])
partitions.insert(0, new[0])The index Also, I am thinking about a This would be a point for the finalization PR for the maze generation, alongside getting all the |
|
But if you |
|
Yes, it should. |
Or we make it a deque ? |
|
We can try all of the suggestions. Not to much work. In the end, well written comments are the most important thing to keep the algorithm understandable. |
|
See #946 for changes. |
Our binary space partitioning routine has been implemented recursively.
Now its iterative.
I ran
pyinstrumenton this benchmark scriptand saw a slight performance improvement from
0.247 sto0.232 sinadd_wall_and_split.I used
pyinstrument --show=generate_half_maze benchmark.pyto filter the output a bit.before
after
The tests, especially the maze stability test, pass.
The logic for creating the walls did not change, but maybe this would be something for another PR anyway?