What is the algorithm for generating the maze in the game Netwalk?
Asked Answered
E

1

6

What is the algorithm for generating the maze in the game Netwalk?

Netwalk game screenshot

Eyewash answered 7/7, 2011 at 8:56 Comment(1)
I've re-opened this in light of the quality of the answer that has been posted. The community is, however, free to disagree with my decision. My reasoning is, the answer proves this question is indeed answerable objectively, in a constructive way - though I agree the wording is quite broad.Bedraggle
S
18

The source code is available at Google Code, so you can read it for yourself and find out! The maze is generated by the function generate_maze in game.c, lines 78ff.


Update: try the demo!

Netwalk generates a maze by running a randomized version of Prim's algorithm to find a minimum spanning tree. Prim's algorithm iteratively grows a tree once branch at a time, starting from a source node (or nodes: in this case, the "server", the dark blue double-height box). At any given point in the running of the algorithm, the data structure looks something like this:

enter image description here

The cells coloured in green are cells at the tips of the growing branches: they still have at least one empty neighbour into which they might grow. At each step, the algorithm picks one of these green cells, and then picks one of its empty neighbours(1), and adds a branch into that neighbour. This new branch block neighbouring branches from growing in its direction. When a branch has no more empty neighbours(2), then it is removed from the list of green cells.

Eventually the green list is empty: none of the branches of the network have any empty neighbours. This means that the board is full, and every cell is connected to the server by a single path.

enter image description here

[I've idealised the details in a couple of places: (1) in fact the Netwalk algorithm is a bit naïve, and just picks a random direction, and if the neighbour in that direction is non-empty, it does nothing and continues to the next iteration. (2) Branches with no empty neighbours are not detected in a timely manner: they are only removed from the green list if they happen to be selected. The demo fixes these minor infelicities.]

Sanitation answered 7/7, 2011 at 9:45 Comment(2)
Thank You very much for pointing out the idea behind the game and the demo. That's cool.Eyewash
This is a great, objective answer to a question that was really broad. Thank you for contributing.Bedraggle

© 2022 - 2024 — McMap. All rights reserved.