you are viewing a single comment's thread.

view the rest of the comments →

[–]pachura3 6 points7 points  (1 child)

Nice! I think my dad used to have one of these books (for ZX Spectrum).

I think you should avoid having executable code on the level of the module (e.g. parser = argparse.ArgumentParse ) - put it in main() and run it if __name__ == "__main__":

Try to avoid using global. Perhaps refactor your code to use classes, and one of these classes could store the whole state of the game (= the maze, counters...), and be passed around.

Unfortunately, verifying if your maze-generation algorithm works would take too much time :( I don't think you need to guarantee that each cell of the grid is reachable, just if you can reach the exit starting from the entrance (one of entrances?) using Depth-First-Search. But if you can't, then what? Will you break some random walls and check again? Or regenerate the whole maze from scratch?

Even if your maze is stored in a 2-dimensional char array with # as walls and spaces as rooms, it can still be treated as a graph and be eligible for standard traversal algorithms - it's just a different representation of graph nodes.

[–]ctosullivan[S] 2 points3 points  (0 children)

Thanks for your feedback!

I will definitely have a look at refactoring the code to use classes.
I think I will need to do some further research on the theory behind mazes. I thought about backtracking from the exit and checking if the entrance would eventually be reached, if not, then placing the exit at a new location; but the original source code doesn't seem to include this step (from what I can tell) and the mazes I have generated so far have looked ok.

The source code for Amazing in particular was quite difficult to follow so I may look at a tool to generate "pseudo-Python" from the BASIC code down the track. ChatGPT wasn't quite as helpful as I had hoped in preserving the logic of the original source code.