Difference between revisions of "Python - Maze Generation Assignment"

From WLCS
Line 1: Line 1:
= Objective =
+
= Objectives =
 
* You will create a maze generation program
 
* You will create a maze generation program
 
* You will create Python classes that represent a MazeRoom and a Maze
 
* You will create Python classes that represent a MazeRoom and a Maze
 
* You will implement a depth-first search maze algorithm using a stack as a backtracker
 
* You will implement a depth-first search maze algorithm using a stack as a backtracker
  
== Resources ==
+
= Resources =
 
* [[Media:Stacks.ppt]]
 
* [[Media:Stacks.ppt]]
 
* [http://www.csanimated.com/animation.php?t=Stack Stack - CS Animated]
 
* [http://www.csanimated.com/animation.php?t=Stack Stack - CS Animated]
Line 11: Line 11:
 
* [http://gwydir.demon.co.uk/jo/maze/makemaze/index.htm Maze Designer]
 
* [http://gwydir.demon.co.uk/jo/maze/makemaze/index.htm Maze Designer]
  
== MazeRoom class  ==
+
= MazeRoom class  =
 
* Create a file named '''MazeRoom.py''' for the MazeRoom class
 
* Create a file named '''MazeRoom.py''' for the MazeRoom class
=== Attributes ===
+
== Attributes ==
 
* MazeRoom should have the following attributes with default values:
 
* MazeRoom should have the following attributes with default values:
 
** roomToNorth - references the a doorway to the north.  A None value means that there is wall
 
** roomToNorth - references the a doorway to the north.  A None value means that there is wall
Line 29: Line 29:
 
** visited - a Boolean that keeps track of whether or not the room has been visited in the maze algorithm
 
** visited - a Boolean that keeps track of whether or not the room has been visited in the maze algorithm
 
*** Default: False
 
*** Default: False
=== Methods ===
+
== Methods ==
 
* MazeRoom should have the following method:
 
* MazeRoom should have the following method:
 
** '''def __init__(self, row = -1, col = -1)''' - set the internal row and col attributes to be the same as the input parameters
 
** '''def __init__(self, row = -1, col = -1)''' - set the internal row and col attributes to be the same as the input parameters
  
== Maze class ==
+
= Maze class =
 
* Create a file named '''Maze.py''' for the Maze class
 
* Create a file named '''Maze.py''' for the Maze class
=== Attributes ===
+
== Attributes ==
 
* numRows - an int that stores the total number of rows in your maze
 
* numRows - an int that stores the total number of rows in your maze
 
* numCols - an int that stores the total number of cols in your maze
 
* numCols - an int that stores the total number of cols in your maze
Line 41: Line 41:
 
* stack - a list of Rooms that will be used to backtrack
 
* stack - a list of Rooms that will be used to backtrack
  
=== Methods ===
+
== Methods ==
  
== Testing ==
+
= Testing =
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
 
from Maze import *
 
from Maze import *

Revision as of 12:53, 16 May 2013

Objectives

  • You will create a maze generation program
  • You will create Python classes that represent a MazeRoom and a Maze
  • You will implement a depth-first search maze algorithm using a stack as a backtracker

Resources

MazeRoom class

  • Create a file named MazeRoom.py for the MazeRoom class

Attributes

  • MazeRoom should have the following attributes with default values:
    • roomToNorth - references the a doorway to the north. A None value means that there is wall
      • Default: None
    • roomToSouth - references the a doorway to the south. A None value means that there is wall
      • Default: None
    • roomToEast - references the a doorway to the east. A None value means that there is wall
      • Default: None
    • roomToWest - references the a doorway to the west. A None value means that there is wall
      • Default: None
    • row - the row number for the Room
      • Default: -1
    • col - the column number for the Room
      • Default: -1
    • visited - a Boolean that keeps track of whether or not the room has been visited in the maze algorithm
      • Default: False

Methods

  • MazeRoom should have the following method:
    • def __init__(self, row = -1, col = -1) - set the internal row and col attributes to be the same as the input parameters

Maze class

  • Create a file named Maze.py for the Maze class

Attributes

  • numRows - an int that stores the total number of rows in your maze
  • numCols - an int that stores the total number of cols in your maze
  • rooms - a 2-dimensional list of Rooms
  • stack - a list of Rooms that will be used to backtrack

Methods

Testing

from Maze import *

maze = Maze()
maze.generate()
maze.print()