Project 3: RanMaze

Random Maze Generation using Partition

Educational Objectives: After completing this assignment, the student should be able to accomplish the following:

Operational Objectives: Implement the Partition class and a client program that generates random mazes.

Deliverables: Two files:

partition.h  # contains template < typename N > class Partition
ranmaze.cpp  # client program of Partition < long > generating random mazes

Procedural Requirements

  1. The official development, testing, and assessment environment is g++47 -std=c++11 -Wall -Wextra on the linprog machines. Code should compile without error or warning.

  2. Begin by copying the following files from the course directory into your proj3 directory:

    LIB/proj3/fpartition.cpp        # test harness for Partition
    LIB/proj3/makefile              # builds most executables
    LIB/area51/fpartition.x         # sample executable
    LIB/area51/ranmaze.x            # sample executable
    LIB/area51/mazetest.x           # maze analyzer
    

    Execute ranmaze.x to generate maze files and mazetest.x to analyze the resulting maze files. You will follow the same process in testing your own ranmaze and its resulting maze files. Also pay careful attention to the detailed I/O behavior of ranmaze, this is how your program should behave.

  3. Create the file partition.h containing the definition and implementation of template<typename N> Partition. Test your class thoroughly using the supplied fpartition.cpp.
  4. Create the file ranmaze.cpp, a client of Partition<>. Using mazetest.x, test thoroughly to be sure the mazes it generates are self-consistent and that the behavior mimics that of LIB/area51/ranmaze.x, including the file name extensions for output files.
  5. Check that ranmaze.cpp and Partition<> meet the specifications given below.
  6. Copy the file LIB/proj3/proj3submit.sh into your project directory, change its permissions to executable, and submit the project by executing the script.

    Warning: Submit scripts do not work on the program and linprog servers. Use shell.cs.fsu.edu to submit projects. If you do not receive the second confirmation with the contents of your project, there has been a malfunction.

Code Requirements and Specifications - Partition

  1. Use the API defined by the following:

    template < typename N = size_t >
    class Partition
    {
    public:
      explicit Partition  ( N size );       // create singletons {0} .. {size-1}
      void     Reset      ();               // reverts to singletons
      void     Reset      ( N newsize ); 
      void     Push       ()                     { parent_.PushBack(parent_.Size()); height_.PushBack(0); }
      void     Union      ( N x , N y )          { Link(Root(x),Root(y)); }
      bool     Find       ( N x , N y )          { return Root(x) == Root(y); }
      bool     Find       ( N x , N y ) const    { return Root(x) == Root(y); }
    
      size_t   Size       () const               { return height_.Size(); }
      void     Dump       ( std::ostream& os ) const;
      size_t   Components () const;
    private: // methods
      N Root     ( N x );                // path compression changes state
      N Root     ( N x ) const;          // no path compression
      void Link  ( N root1 , N root2 );  // union assuming arguments are roots
    private: // objects
      fsu::Vector <N> parent_;
      fsu::Vector <N> height_;
    };
    

    Follow the implementation started here. This is distinct from that of the lecture notes in that

    1. N is assumed to be an unsigned type
    2. Root nodes are recognized by (parent_[i] == (size_t)i)
    3. Rank/height info is maintained in the separate vector height_

    Only a few key implementations are lacking.

  2. Be sure that you implement path compression in the non-const version of Root. Of course, you will be forced to use the non-compression version for the const version of Root.

  3. Use the distributed example executable fpartition.x to see what behavior is expected from Dump, Size, and Components.

Code Requirements and Specifications - ranmaze

  1. Output maze files according to the spec in the Union-Find notes Appendix: Maze Technology. Take care that all maze files are syntactically and semantically correct - mazetest.x is helpful in testing your output.

  2. The maze file should have the start as cell 0 (the upper left corner of the maze) and the goal as cell numrows x numcols - 1 (the lower right corner of the maze).

  3. ranmaze should expect three command line arguments: number of rows, number of columns, and filename.

  4. ranmaze should output two versions of the random maze: (1) the first time goal is reachable from start, output the maze to the file "filename.[components]" where [components] is the actual number of components in the maze; and (2) after all cells are reachable from start, output the maze to the file "filename.1".

  5. Take care that your mazes are corerctly "random" in the sense that all walls have the same probability of being selected for inspection at each step. This is mostly a matter of judicious design, especially at boundary cases. For example: be sure that a cell face on an interior cell has the same chance of selection as a cell face of a boundary cell, where fewer faces are eligible.

Hints - Partition

Hints - ranmaze