Class GrowingTreeMazeGenerator

java.lang.Object
com.github.yellowstonegames.place.GrowingTreeMazeGenerator
All Implemented Interfaces:
PlaceGenerator

public class GrowingTreeMazeGenerator extends Object implements PlaceGenerator
A maze generator that can be configured using an 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

    Fields
    Modifier and Type
    Field
    Description
    char[][]
     
    int[][]
     
    final com.github.tommyettinger.function.IntToIntFunction
    Produces high-quality mazes that are very similar to those produced by a recursive back-tracking algorithm.
    final com.github.tommyettinger.function.IntToIntFunction
    Produces mostly straight corridors that dead-end at the map's edge; probably only useful with mix(IntToIntFunction, double, IntToIntFunction, double).
    final com.github.tommyettinger.function.IntToIntFunction
    Produces chaotic, jumbled spans of corridors, often with dead-ends, 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, com.github.tommyettinger.random.EnhancedRandom rng)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    char[][]
    Builds and returns a 2D char array maze by using newest with generate(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 in DungeonTools like DungeonTools.NATURAL_WALL or DungeonTools.ROOM_FLOOR.
    char[][]
    Gets the most recently-produced maze as a 2D char array, usually produced by calling generate() or generate(IntToIntFunction).
    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, like newest and random, given a weight for each, and produces a new IntToIntFunction that randomly (respecting weight) picks one of those IntToIntFunctions each time it is used.
     

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • dungeon

      public char[][] dungeon
    • environment

      public int[][] environment
    • newest

      public final com.github.tommyettinger.function.IntToIntFunction newest
      Produces 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 oldest
      Produces mostly straight corridors that dead-end at the map's edge; probably only useful with mix(IntToIntFunction, double, IntToIntFunction, double).
      Example:
      ┌─┬─┬─┬─┬─┬─┬─┬───────────────────────┐
      │.│.│.│.│.│.│.│.......................│
      │.│.│.│.│.│.│.│.──────────────────────┤
      │.│.│.│.│.│.│.│.......................│
      │.│.│.│.│.│.│.│.──────────────────────┤
      │.│.│.│.│.│.│.│.......................│
      │.│.│.│.│.│.│.│.──────────────────────┤
      │.........│.│.│.......................│
      ├────────.│.│.│.──────────────────────┤
      │.....................................│
      ├────────────.│.──────────────────────┤
      │.............│.......................│
      ├────────────.│.──────────────────────┤
      │.............│.......................│
      ├────────────.│.│.────────────────────┤
      │.............│.│.....................│
      ├────────.│.│.│.│.────────────────────┤
      │.........│.│.│.│.....................│
      └─────────┴─┴─┴─┴─────────────────────┘
      
    • random

      public final com.github.tommyettinger.function.IntToIntFunction random
      Produces chaotic, jumbled spans of corridors, often with dead-ends, that are similar to those produced by Prim's algorithm. This works well when mixed with newest using mix(IntToIntFunction, double, IntToIntFunction, double), and not as well when mixed with oldest.
      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 calling generate() or generate(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:
      getPlaceGrid in interface PlaceGenerator
      Returns:
      the most recently-produced dungeon/map as a 2D char array
    • getEnvironment

      public int[][] getEnvironment()
      Description copied from interface: PlaceGenerator
      Gets the most recently-produced place's environment as a 2D int array, where each int is typically a constant in DungeonTools like DungeonTools.NATURAL_WALL or DungeonTools.ROOM_FLOOR.
      Specified by:
      getEnvironment in interface PlaceGenerator
      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 using newest with generate(IntToIntFunction).
      Specified by:
      generate in interface PlaceGenerator
      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 use newest, the least maze-like use oldest, and the most jumbled use random or a mix of others using mix(IntToIntFunction, double, IntToIntFunction, double).
      Parameters:
      choosing - the callback object for making the split decision
      Returns:
      dungeon, after filling it with a maze
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • 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, like newest and random, 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 null
      chanceA - the weight to favor choosing methodA
      methodB - the second IntToIntFunction to mix; must not be null
      chanceB - the weight to favor choosing methodB
      Returns:
      a IntToIntFunction that randomly picks between methodA and methodB each time it is used