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 <> 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/mazemaster.x         # maze analyzer
    

    Execute ranmaze.x to generate maze files and mazemaster.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 mazemaster.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:

    namespace fsu
    {
      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     PushSingleton ()                   { parent_.PushBack((N)parent_.Size()); rank_.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 rank_.Size(); }
        size_t   Components    () const;
        void     Display       ( std::ostream& os ) const;
        void     Dump          ( std::ostream& os ) 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> rank_;
      };
      ...
    } // fsu
    

    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] == (N)i)
    3. Rank/height info is maintained in the separate vector rank_. Recall this starts out as the height of the tree rooted at i but is not maintained once i ceases to be a root in the forest.

    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 area51/fpartition.x to see what behavior is expected from Display() and Components(). Because Dump() should display the internal data of the structure, which is of course different from that in the distributed example, you should consult the discussion forum to agree with other students on this behavior.

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 - mazemaster.x is helpful in testing your output.

  2. The maze file should have the start as cell at the beginning (left-most cell) of the middle row and the goal at the end (right-most cell) of the same row.

  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 correctly "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