Package org.apache.calcite.example.maze
Class Maze
- java.lang.Object
-
- org.apache.calcite.example.maze.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.
-
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)
-
-
-
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
-
DEBUG
static final boolean DEBUG
- See Also:
- Constant Field Values
-
horizontal
private final boolean horizontal
- See Also:
- Constant Field Values
-
spiral
private final boolean spiral
- See Also:
- Constant Field Values
-
-
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 writerspace
- 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 generatorints
- Array of integers to shuffle
-
-