public static void writeMaze(PrintStream mazeStream, Set<Integer> knockdowns, 
   int height, int width) {
		// draw maze except lower border
      for (int i = 0; i < height; i++)	{
         for (int j = 0; j < width; j++) { 
            mazeStream.print("+");
				// negative elements in knockdowns denote walls above or below a cell
            if (!knockdowns.contains(-(j + i * width)))
               mazeStream.print("-");
            else
               mazeStream.print(" ");
         }
         mazeStream.println("+");
         for (int j = 0; j < width; j++)
				// Positive elements in knockdowns denote walls to the left or right of a 
				// cell. i + j test in if is to make the entrance to the maze be the 
				// upper left corner.
            if (!knockdowns.contains(j + i * width) && i + j != 0)
               mazeStream.print("| ");
            else 
               mazeStream.print("  ");
			if (i < height - 1) // in every case except last row
         	mazeStream.println("|");
			else 
				mazeStream.println(); // make maze exit in lower right corner
      }
		// draw bottom border
      for (int i = 0; i < width; i++)
			mazeStream.print("+-");
      mazeStream.println("+");
   }