Class GrowingTreeMazeGenerator
java.lang.Object
com.github.yellowstonegames.place.GrowingTreeMazeGenerator
- All Implemented Interfaces:
PlaceGenerator
A maze generator that can be configured using an
Here, an IntToIntFunction used to choose cells takes a size (exclusive upper bound) and returns some int between 0 (inclusive) and that size (exclusive). These are typically lambdas.
IntToIntFunction, which can be customized for the app.
Based in part on code from
Jamis Buck's blog.
This defaults to newest for its IntToIntFunction, but random is also good to try; you can specify a
IntToIntFunction with generate(IntToIntFunction).
Here, an IntToIntFunction used to choose cells takes a size (exclusive upper bound) and returns some int between 0 (inclusive) and that size (exclusive). These are typically lambdas.
-
Field Summary
FieldsModifier and TypeFieldDescriptionchar[][]int[][]final com.github.tommyettinger.function.IntToIntFunctionProduces high-quality mazes that are very similar to those produced by a recursive back-tracking algorithm.final com.github.tommyettinger.function.IntToIntFunctionProduces mostly straight corridors that dead-end at the map's edge; probably only useful withmix(IntToIntFunction, double, IntToIntFunction, double).final com.github.tommyettinger.function.IntToIntFunctionProduces chaotic, jumbled spans of corridors, often with dead-ends, that are similar to those produced by Prim's algorithm. -
Constructor Summary
ConstructorsConstructorDescriptionGrowingTreeMazeGenerator(int width, int height) GrowingTreeMazeGenerator(int width, int height, com.github.tommyettinger.random.EnhancedRandom rng) -
Method Summary
Modifier and TypeMethodDescriptionchar[][]generate()Builds and returns a 2D char array maze by usingnewestwithgenerate(IntToIntFunction).char[][]generate(com.github.tommyettinger.function.IntToIntFunction choosing) Builds and returns a 2D char array maze using the provided chooser method object.int[][]Gets the most recently-produced place's environment as a 2D int array, where each int is typically a constant inDungeonToolslikeDungeonTools.NATURAL_WALLorDungeonTools.ROOM_FLOOR.char[][]Gets the most recently-produced maze as a 2D char array, usually produced by callinggenerate()orgenerate(IntToIntFunction).com.github.tommyettinger.function.IntToIntFunctionmix(com.github.tommyettinger.function.IntToIntFunction methodA, double chanceA, com.github.tommyettinger.function.IntToIntFunction methodB, double chanceB) toString()
-
Field Details
-
dungeon
public char[][] dungeon -
environment
public int[][] environment -
newest
public final com.github.tommyettinger.function.IntToIntFunction newestProduces high-quality mazes that are very similar to those produced by a recursive back-tracking algorithm.
Example:┌─────┬───────┬───┬─────────┬─────┬───┐ │.....│.......│...│.........│.....│...│ │.────┘.┌──.│.│.│.└───┐.┌──.│.──┐.│.│.│ │.......│...│.│.│.....│.│...│...│.│.│.│ │.──────┤.──┤.│.└─┬──.│.└─┐.└─┐.│.│.│.│ │.......│...│.│...│...│...│...│.│.│.│.│ ├─────┐.├──.│.└─┐.└─┐.├──.├─┐.│.│.│.│.│ │.....│.│...│...│...│.│...│.│...│...│.│ │.│.──┘.│.──┼───┼──.│.│.──┤.└───┼───┘.│ │.│.....│...│...│...│.│...│.....│.....│ │.└─┬───┴─┐.└─┐.│.┌─┘.│.│.└───┐.│.──┬─┤ │...│.....│...│...│...│.│.....│.│...│.│ ├──.│.┌──.│.──┴───┤.──┴─┤.──┐.│.└─┐.│.│ │...│.│...│.......│.....│...│.│...│.│.│ │.┌─┴─┘.│.├─┐.│.┌─┴───┐.├───┘.│.│.│.│.│ │.│.....│.│.│.│.│.....│.│.....│.│.│.│.│ │.│.┌───┘.│.│.└─┘.──┐.│.│.┌───┘.│.│.│.│ │...│.......│.......│.....│.....│.....│ └───┴───────┴───────┴─────┴─────┴─────┘
-
oldest
public final com.github.tommyettinger.function.IntToIntFunction oldestProduces mostly straight corridors that dead-end at the map's edge; probably only useful withmix(IntToIntFunction, double, IntToIntFunction, double).
Example:┌─┬─┬─┬─┬─┬─┬─┬───────────────────────┐ │.│.│.│.│.│.│.│.......................│ │.│.│.│.│.│.│.│.──────────────────────┤ │.│.│.│.│.│.│.│.......................│ │.│.│.│.│.│.│.│.──────────────────────┤ │.│.│.│.│.│.│.│.......................│ │.│.│.│.│.│.│.│.──────────────────────┤ │.........│.│.│.......................│ ├────────.│.│.│.──────────────────────┤ │.....................................│ ├────────────.│.──────────────────────┤ │.............│.......................│ ├────────────.│.──────────────────────┤ │.............│.......................│ ├────────────.│.│.────────────────────┤ │.............│.│.....................│ ├────────.│.│.│.│.────────────────────┤ │.........│.│.│.│.....................│ └─────────┴─┴─┴─┴─────────────────────┘
-
random
public final com.github.tommyettinger.function.IntToIntFunction randomProduces chaotic, jumbled spans of corridors, often with dead-ends, that are similar to those produced by Prim's algorithm. This works well when mixed withnewestusingmix(IntToIntFunction, double, IntToIntFunction, double), and not as well when mixed witholdest.
Example:┌─────────────┬───────────┬───────────┐ │.............│...........│...........│ ├─┬─┬─┬────.┌─┘.┌─┐.──┐.──┤.──┐.──┐.│.│ │.│.│.│.....│...│.│...│...│...│...│.│.│ │.│.│.└─┬──.│.┌─┘.└─┐.└─┬─┘.──┴───┤.│.│ │.│.│...│...│.│.....│...│.........│.│.│ │.│.└─┐.└─┐.│.│.┌─┬─┤.┌─┤.──┐.────┴─┼─┤ │.....│...│.....│.│.│.│.│...│.......│.│ ├────.├──.└──.──┘.│.└─┘.│.──┴─┐.│.──┘.│ │.....│...........│...........│.│.....│ ├────.└──.│.│.│.──┘.──────────┴─┴─┐.──┤ │.........│.│.│...................│...│ ├──────.│.│.│.│.────────────────┐.└─┬─┤ │.......│.│.│.│.................│...│.│ ├────.│.│.│.│.├─┬─┐.│.│.│.──┐.──┴───┘.│ │.....│.│.│.│.│.│.│.│.│.│...│.........│ │.┌──.├─┴─┴─┘.│.│.└─┴─┴─┴─┐.└─┐.│.│.│.│ │.│...│...................│...│.│.│.│.│ └─┴───┴───────────────────┴───┴─┴─┴─┴─┘
-
-
Constructor Details
-
GrowingTreeMazeGenerator
public GrowingTreeMazeGenerator() -
GrowingTreeMazeGenerator
public GrowingTreeMazeGenerator(int width, int height) -
GrowingTreeMazeGenerator
public GrowingTreeMazeGenerator(int width, int height, com.github.tommyettinger.random.EnhancedRandom rng)
-
-
Method Details
-
getPlaceGrid
public char[][] getPlaceGrid()Gets the most recently-produced maze as a 2D char array, usually produced by callinggenerate()orgenerate(IntToIntFunction). This passes a direct reference and not a copy, so you can normally modify the returned array to propagate changes back into this PlaceGenerator.- Specified by:
getPlaceGridin interfacePlaceGenerator- Returns:
- the most recently-produced dungeon/map as a 2D char array
-
getEnvironment
public int[][] getEnvironment()Description copied from interface:PlaceGeneratorGets the most recently-produced place's environment as a 2D int array, where each int is typically a constant inDungeonToolslikeDungeonTools.NATURAL_WALLorDungeonTools.ROOM_FLOOR.- Specified by:
getEnvironmentin interfacePlaceGenerator- Returns:
- the environment of the most recently-produced place, as a 2D int array
-
generate
public char[][] generate()Builds and returns a 2D char array maze by usingnewestwithgenerate(IntToIntFunction).- Specified by:
generatein interfacePlaceGenerator- Returns:
dungeon, after filling it with a maze
-
generate
public char[][] generate(com.github.tommyettinger.function.IntToIntFunction choosing) Builds and returns a 2D char array maze using the provided chooser method object. The most maze-like dungeons usenewest, the least maze-like useoldest, and the most jumbled userandomor a mix of others usingmix(IntToIntFunction, double, IntToIntFunction, double).- Parameters:
choosing- the callback object for making the split decision- Returns:
dungeon, after filling it with a maze
-
toString
-
mix
public com.github.tommyettinger.function.IntToIntFunction mix(com.github.tommyettinger.function.IntToIntFunction methodA, double chanceA, com.github.tommyettinger.function.IntToIntFunction methodB, double chanceB) Mixes two IntToIntFunction values, likenewestandrandom, given a weight for each, and produces a new IntToIntFunction that randomly (respecting weight) picks one of those IntToIntFunctions each time it is used.- Parameters:
methodA- the first IntToIntFunction to mix; must not be nullchanceA- the weight to favor choosing methodAmethodB- the second IntToIntFunction to mix; must not be nullchanceB- the weight to favor choosing methodB- Returns:
- a IntToIntFunction that randomly picks between
methodAandmethodBeach time it is used
-