Package squidpony.squidgrid.mapping
Class GrowingTreeMazeGenerator
java.lang.Object
squidpony.squidgrid.mapping.GrowingTreeMazeGenerator
- All Implemented Interfaces:
IDungeonGenerator
public class GrowingTreeMazeGenerator extends Object implements IDungeonGenerator
A maze generator that can be configured using a
GrowingTreeMazeGenerator.ChoosingMethod
, which can be customized for the app.
Based in part on code from Jamis Buck's blog.- Author:
- Eben Howard - http://squidpony.com - howard@squidpony.com
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
GrowingTreeMazeGenerator.ChoosingMethod
A way to configure howgenerate(ChoosingMethod)
places paths through the maze. -
Field Summary
Fields Modifier and Type Field Description char[][]
dungeon
GrowingTreeMazeGenerator.ChoosingMethod
newest
Produces high-quality mazes that are very similar to those produced by a recursive back-tracking algorithm.GrowingTreeMazeGenerator.ChoosingMethod
oldest
Produces mostly straight corridors that dead-end at the map's edge; probably only useful withmix(ChoosingMethod, double, ChoosingMethod, double)
.GrowingTreeMazeGenerator.ChoosingMethod
random
Produces chaotic, jumbled spans of corridors that are similar to those produced by Prim's algorithm. -
Constructor Summary
Constructors Constructor Description GrowingTreeMazeGenerator(int width, int height)
GrowingTreeMazeGenerator(int width, int height, IRNG rng)
-
Method Summary
Modifier and Type Method Description char[][]
generate()
Builds and returns a 2D char array maze by usingnewest
withgenerate(ChoosingMethod)
.char[][]
generate(GrowingTreeMazeGenerator.ChoosingMethod choosing)
Builds and returns a 2D char array maze using the provided chooser method object.char[][]
getDungeon()
Gets the most recently-produced dungeon as a 2D char array, usually produced by callinggenerate()
or some similar method present in a specific implementation.GrowingTreeMazeGenerator.ChoosingMethod
mix(GrowingTreeMazeGenerator.ChoosingMethod methodA, double chanceA, GrowingTreeMazeGenerator.ChoosingMethod methodB, double chanceB)
-
Field Details
-
dungeon
-
newest
Produces high-quality mazes that are very similar to those produced by a recursive back-tracking algorithm. -
oldest
Produces mostly straight corridors that dead-end at the map's edge; probably only useful withmix(ChoosingMethod, double, ChoosingMethod, double)
. -
random
Produces chaotic, jumbled spans of corridors that are similar to those produced by Prim's algorithm.
-
-
Constructor Details
-
Method Details
-
getDungeon
Gets the most recently-produced dungeon as a 2D char array, usually produced by callinggenerate()
or some similar method present in a specific implementation. This normally passes a direct reference and not a copy, so you can normally modify the returned array to propagate changes back into this IDungeonGenerator.- Specified by:
getDungeon
in interfaceIDungeonGenerator
- Returns:
- the most recently-produced dungeon/map as a 2D char array
-
generate
Builds and returns a 2D char array maze by usingnewest
withgenerate(ChoosingMethod)
.- Specified by:
generate
in interfaceIDungeonGenerator
- Returns:
dungeon
, after filling it with a maze
-
generate
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 userandom
or a mix of others usingmix(ChoosingMethod, double, ChoosingMethod, double)
.- Parameters:
choosing
- the callback object for making the split decision- Returns:
dungeon
, after filling it with a maze
-
mix
public GrowingTreeMazeGenerator.ChoosingMethod mix(GrowingTreeMazeGenerator.ChoosingMethod methodA, double chanceA, GrowingTreeMazeGenerator.ChoosingMethod methodB, double chanceB)Mixes two ChoosingMethod values, likenewest
andrandom
, given a weight for each, and produces a new ChoosingMethod that randomly (respecting weight) picks one of those ChoosingMethods each time it is used.- Parameters:
methodA
- the first ChoosingMethod to mix; must not be nullchanceA
- the weight to favor choosing methodAmethodB
- the second ChoosingMethod to mix; must not be nullchanceB
- the weight to favor choosing methodB- Returns:
- a ChoosingMethod that randomly picks between
methodA
andmethodB
each time it is used
-