# Constructing and printing a maze

I have implemented a maze with

• a function addCoordinate where x and y denote the x and y coord of grid and block type: zero means open and 1 means wall.
• a printMaze function which prints the maze with * for wall and empty space for open spaces.

My implementation seems to be working fine but could there be a better way of doing this:

class Maze:
board, max_x, max_y, list = [],2,2,[]

def __init__(self):
"""
Constructor - You may modify this, but please do not add any extra parameters
"""

def addCoordinate(self, x, y, blockType):
"""
Add information about a coordinate on the maze grid
x is the x coordinate
y is the y coordinate
blockType should be 0 (for an open space) of 1 (for a wall)
"""
if x > self.max_x:
self.max_x = x
if y > self.max_y:
self.max_y = y
if self.max_y >= len(self.board) or self.max_x >= len(self.board[0]):
newboard = [[1 for a in range(self.max_x + 1)] for b in range(self.max_y + 1)]
for i in range(len(self.board)):
for j in range(len(self.board[i])):
newboard[i][j] = self.board[i][j]
self.board = newboard
self.board[y][x] = blockType
def printMaze(self):
"""
Print out an ascii representation of the maze.
A * indicates a wall and a empty space indicates an open space in the maze
"""

for i in range(self.max_x + 1):
for j in range(self.max_y + 1):
if self.board[i][j] == 0:
print " ",
else:
print "*",
print ""

def mazeTest():
"""
This sets the open space coordinates for the example
maze in the assignment.
The remainder of coordinates within the max bounds of these specified coordinates
are assumed to be walls
"""
myMaze = Maze()

myMaze.printMaze()

mazeTest()


Output:

*   * * * * * *
*   * * * * *
*         *
* * * *   * *
* * * *   * *
* * *     * *
*         *
* * * * *   * *

• Is this really how you want each maze to be specified — one element at a time? – 200_success Nov 23 '17 at 18:25
• yes,that's what i could think of – Dkk Nov 23 '17 at 18:28
• Is there any other way in which we could specify the maze – Dkk Nov 23 '17 at 19:25
• You could generate the maze more procedural, see Wikipedia – Ludisposed Nov 24 '17 at 12:21