Class Maze


  • class Maze
    extends java.lang.Object
    Maze generator.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) static interface  Maze.CellContent
      Callback to get what to print in a particular cell.
      private static class  Maze.Direction
      Direction.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) static boolean DEBUG  
      (package private) int height  
      private boolean horizontal  
      private boolean[] lefts  
      private int[] regions  
      private boolean spiral  
      private boolean[] ups  
      private int width  
    • Constructor Summary

      Constructors 
      Constructor Description
      Maze​(int width, int height)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Enumerator<java.lang.String> enumerator​(java.util.Set<java.lang.Integer> solutionSet)
      Generates a list of lines representing the maze in text form.
      Maze layout​(java.util.Random random, java.io.PrintWriter pw)  
      void print​(java.io.PrintWriter pw, boolean space)
      Prints the maze.
      private int region​(int cell)  
      private void row​(Maze.CellContent cellContent, java.lang.StringBuilder b, java.lang.StringBuilder b2, int y)
      Returns a pair of strings representing a row of the maze.
      private void shuffle​(java.util.Random random, int[] ints)
      Randomly permutes the members of an array.
      (package private) java.util.Set<java.lang.Integer> solve​(int x, int y)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • width

        private final int width
      • height

        final int height
      • regions

        private final int[] regions
      • ups

        private final boolean[] ups
      • lefts

        private final boolean[] lefts
    • Constructor Detail

      • Maze

        Maze​(int width,
             int height)
    • Method Detail

      • region

        private int region​(int cell)
      • print

        public void print​(java.io.PrintWriter pw,
                          boolean space)
        Prints the maze. Results are like this:
        +--+--+--+--+--+ | | | +--+ +--+--+ + | | | | + +--+ +--+ + | | +--+--+--+--+--+
        Parameters:
        pw - Print writer
        space - Whether to put a space in each cell; if false, prints the region number of the cell
      • enumerator

        public Enumerator<java.lang.String> enumerator​(java.util.Set<java.lang.Integer> solutionSet)
        Generates a list of lines representing the maze in text form.
      • row

        private void row​(Maze.CellContent cellContent,
                         java.lang.StringBuilder b,
                         java.lang.StringBuilder b2,
                         int y)
        Returns a pair of strings representing a row of the maze.
      • layout

        public Maze layout​(java.util.Random random,
                           java.io.PrintWriter pw)
      • solve

        java.util.Set<java.lang.Integer> solve​(int x,
                                               int y)
      • shuffle

        private void shuffle​(java.util.Random random,
                             int[] ints)
        Randomly permutes the members of an array. Based on the Fisher-Yates algorithm.
        Parameters:
        random - Random number generator
        ints - Array of integers to shuffle