john-science / mazelib

A Python library for creating and solving mazes.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why does the maze parameter receive h and w but the resulting maze has different dimensions?

farisfaikar opened this issue · comments

I know this is probably a stupid question and perhaps I should read the documentation again, but why is it that the parameters for the mazes don't correspond to the actual maze dimensions? For example, this code right here:

from mazelib import Maze
from mazelib.generate.Prims import Prims

m = Maze()
m.generator = Prims(3, 3)
m.generate()
print(m)

Prints this:

#######
#     #
### ###
# # # #
# # # #
#     #
#######

Which is a 7x7 grid. Upon reading the MazeGenAlgo.py file, I saw this for the constructor:

...
    def __init__(self, h, w):
        assert w >= 3 and h >= 3, "Mazes cannot be smaller than 3x3."
        self.h = h
        self.w = w
        self.H = (2 * self.h) + 1
        self.W = (2 * self.w) + 1
...

The class deliberately multiplies the height and width by 2 and adds 1. This is quite frustrating because when I input the parameter, for example, 8x8, I want to have an 8x8 maze, but instead, I get a 17x17. That also means I can never get an exact number dimension for my maze.

My question is why do you multiply it by 2 and then add by 1? Also, how do I get my maze to have a 16x16 dimension then?

The difference between the lowercase and uppercase dimensions are:

  • lowercase dimensions - does not include walls
  • uppercase dimensions - includes walls

The reason this distinction exists is because walls can be as thick has hallways, or they can be paper thin. The difference is just one of how we DISPLAY the maze. For examples of how to display mazes with thicker or thinner walls, see the docs.

Okay, to help other people in the future, I have added an explanatory comment for this issue:

"""Maze Generator Algorithm constructor
Attributes:
h (int): height of maze, in number of hallways
w (int): width of maze, in number of hallways
H (int): height of maze, in number of hallways + walls
W (int): width of maze, in number of hallways + walls
"""

Assuming those (admittedly few) words are enough, I'll close this ticket.

Holler if you think it needs more explanation!