Class SerpentMapGenerator

java.lang.Object
squidpony.squidgrid.mapping.SerpentMapGenerator
All Implemented Interfaces:
IDungeonGenerator

public class SerpentMapGenerator
extends Object
implements IDungeonGenerator
Generate dungeons based on a random, winding, looping path through 2D space. Uses techniques from MixedGenerator. Uses a Moore Curve, which is related to Hilbert Curves but loops back to its starting point, and stretches and distorts the grid to make sure a visual correlation isn't obvious. This supports the getEnvironment() method, which can be used in conjunction with RoomFinder to find where separate room, corridor, and cave areas have been placed.
To get a sense of what kinds of map this generates, you can look at a sample map on https://gist.github.com/tommyettinger/93b47048fc8a209a9712 , which also includes a snippet of Java code that can generate that map.
The name comes from a vivid dream I had about gigantic, multi-colored snakes that completely occupied a roguelike dungeon. Shortly after, I made the connection to the Australian mythology I'd heard about the Rainbow Serpent, which in some stories dug water-holes and was similarly gigantic. Created by Tommy Ettinger on 10/24/2015.
  • Constructor Summary

    Constructors 
    Constructor Description
    SerpentMapGenerator​(int width, int height, IRNG rng)
    This prepares a map generator that will generate a map with the given width and height, using the given IRNG.
    SerpentMapGenerator​(int width, int height, IRNG random, boolean symmetrical)
    This prepares a map generator that will generate a map with the given width and height, using the given IRNG.
    SerpentMapGenerator​(int width, int height, IRNG rng, double branchingChance)
    This prepares a map generator that will generate a map with the given width and height, using the given IRNG.
    SerpentMapGenerator​(int width, int height, IRNG random, double branchingChance, boolean symmetrical)
    This prepares a map generator that will generate a map with the given width and height, using the given IRNG.
  • Method Summary

    Modifier and Type Method Description
    char[][] generate()
    This generates a new map by stretching a 16x16 grid of potential rooms to fit the width and height passed to the constructor, randomly expanding columns and rows before contracting the whole to fit perfectly.
    char[][] getDungeon()
    Gets the most recently-produced dungeon as a 2D char array, usually produced by calling IDungeonGenerator.generate() or some similar method present in a specific implementation.
    int[][] getEnvironment()
    Gets a 2D array of int constants, each representing a type of environment corresponding to a static field of MixedGenerator.
    void putBoxRoomCarvers​(int count)
    Changes the number of "carvers" that will create right-angle corridors from one room to the next, create rooms with a random size in a box shape at the start and end, and a small room at the corner if there is one.
    void putCaveCarvers​(int count)
    Changes the number of "carvers" that will create caves from one room to the next.
    void putRoundRoomCarvers​(int count)
    Changes the number of "carvers" that will create right-angle corridors from one room to the next, create rooms with a random size in a circle shape at the start and end, and a small circular room at the corner if there is one.
    void putWalledBoxRoomCarvers​(int count)
    Changes the number of "carvers" that will create right-angle corridors from one room to the next, create rooms with a random size in a box shape at the start and end, and a small room at the corner if there is one.
    void putWalledRoundRoomCarvers​(int count)
    Changes the number of "carvers" that will create right-angle corridors from one room to the next, create rooms with a random size in a circle shape at the start and end, and a small circular room at the corner if there is one.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SerpentMapGenerator

      public SerpentMapGenerator​(int width, int height, IRNG rng)
      This prepares a map generator that will generate a map with the given width and height, using the given IRNG. The intended purpose is to carve a long path that loops through the whole dungeon, while hopefully maximizing the amount of rooms the player encounters. You call the different carver-adding methods to affect what the dungeon will look like, putCaveCarvers(), putBoxRoomCarvers(), and putRoundRoomCarvers(), defaulting to only caves if none are called. You call generate() after adding carvers, which returns a char[][] for a map.
      Parameters:
      width - the width of the final map in cells
      height - the height of the final map in cells
      rng - an IRNG object to use for random choices; this make a lot of random choices.
      See Also:
      MixedGenerator
    • SerpentMapGenerator

      public SerpentMapGenerator​(int width, int height, IRNG random, boolean symmetrical)
      This prepares a map generator that will generate a map with the given width and height, using the given IRNG. The intended purpose is to carve a long path that loops through the whole dungeon, while hopefully maximizing the amount of rooms the player encounters. You call the different carver-adding methods to affect what the dungeon will look like, putCaveCarvers(), putBoxRoomCarvers(), and putRoundRoomCarvers(), defaulting to only caves if none are called. You call generate() after adding carvers, which returns a char[][] for a map.
      Parameters:
      width - the width of the final map in cells
      height - the height of the final map in cells
      random - an IRNG object to use for random choices; this make a lot of random choices.
      symmetrical - true if this should generate a bi-radially symmetric map, false for a typical map
      See Also:
      MixedGenerator
    • SerpentMapGenerator

      public SerpentMapGenerator​(int width, int height, IRNG rng, double branchingChance)
      This prepares a map generator that will generate a map with the given width and height, using the given IRNG. The intended purpose is to carve a long path that loops through the whole dungeon, while hopefully maximizing the amount of rooms the player encounters. You call the different carver-adding methods to affect what the dungeon will look like, putCaveCarvers(), putBoxRoomCarvers(), and putRoundRoomCarvers(), defaulting to only caves if none are called. You call generate() after adding carvers, which returns a char[][] for a map.
      Parameters:
      width - the width of the final map in cells
      height - the height of the final map in cells
      rng - an IRNG object to use for random choices; this make a lot of random choices.
      branchingChance - the chance from 0.0 to 1.0 that each room will branch at least once
      See Also:
      MixedGenerator
    • SerpentMapGenerator

      public SerpentMapGenerator​(int width, int height, IRNG random, double branchingChance, boolean symmetrical)
      This prepares a map generator that will generate a map with the given width and height, using the given IRNG. The intended purpose is to carve a long path that loops through the whole dungeon, while hopefully maximizing the amount of rooms the player encounters. You call the different carver-adding methods to affect what the dungeon will look like, putCaveCarvers(), putBoxRoomCarvers(), and putRoundRoomCarvers(), defaulting to only caves if none are called. You call generate() after adding carvers, which returns a char[][] for a map.
      Parameters:
      width - the width of the final map in cells
      height - the height of the final map in cells
      random - an IRNG object to use for random choices; this make a lot of random choices.
      branchingChance - the chance from 0.0 to 1.0 that each room will branch at least once
      symmetrical - true if this should generate a bi-radially symmetric map, false for a typical map
      See Also:
      MixedGenerator
  • Method Details

    • putCaveCarvers

      public void putCaveCarvers​(int count)
      Changes the number of "carvers" that will create caves from one room to the next. If count is 0 or less, no caves will be made. If count is at least 1, caves are possible, and higher numbers relative to the other carvers make caves more likely. Carvers are shuffled when used, then repeat if exhausted during generation. Since typically about 30-40 rooms are carved, large totals for carver count aren't really needed; aiming for a total of 10 between the count of putCaveCarvers(), putBoxRoomCarvers(), and putRoundRoomCarvers() is reasonable.
      Parameters:
      count - the number of carvers making caves between rooms; only matters in relation to other carvers
      See Also:
      MixedGenerator
    • putBoxRoomCarvers

      public void putBoxRoomCarvers​(int count)
      Changes the number of "carvers" that will create right-angle corridors from one room to the next, create rooms with a random size in a box shape at the start and end, and a small room at the corner if there is one. If count is 0 or less, no box-shaped rooms will be made. If count is at least 1, box-shaped rooms are possible, and higher numbers relative to the other carvers make box-shaped rooms more likely. Carvers are shuffled when used, then repeat if exhausted during generation. Since typically about 30-40 rooms are carved, large totals for carver count aren't really needed; aiming for a total of 10 between the count of putCaveCarvers(), putBoxRoomCarvers(), and putRoundRoomCarvers() is reasonable.
      Parameters:
      count - the number of carvers making box-shaped rooms and corridors between them; only matters in relation to other carvers
      See Also:
      MixedGenerator
    • putWalledBoxRoomCarvers

      public void putWalledBoxRoomCarvers​(int count)
      Changes the number of "carvers" that will create right-angle corridors from one room to the next, create rooms with a random size in a box shape at the start and end, and a small room at the corner if there is one. This also ensures walls will be placed around the room, only allowing corridors and small cave openings to pass. If count is 0 or less, no box-shaped rooms will be made. If count is at least 1, box-shaped rooms are possible, and higher numbers relative to the other carvers make box-shaped rooms more likely. Carvers are shuffled when used, then repeat if exhausted during generation. Since typically about 30-40 rooms are carved, large totals for carver count aren't really needed; aiming for a total of 10 between the count of putCaveCarvers(), putBoxRoomCarvers(), and putRoundRoomCarvers() is reasonable.
      Parameters:
      count - the number of carvers making box-shaped rooms and corridors between them; only matters in relation to other carvers
      See Also:
      MixedGenerator
    • putRoundRoomCarvers

      public void putRoundRoomCarvers​(int count)
      Changes the number of "carvers" that will create right-angle corridors from one room to the next, create rooms with a random size in a circle shape at the start and end, and a small circular room at the corner if there is one. If count is 0 or less, no circular rooms will be made. If count is at least 1, circular rooms are possible, and higher numbers relative to the other carvers make circular rooms more likely. Carvers are shuffled when used, then repeat if exhausted during generation. Since typically about 30-40 rooms are carved, large totals for carver count aren't really needed; aiming for a total of 10 between the count of putCaveCarvers(), putBoxRoomCarvers(), and putRoundRoomCarvers() is reasonable.
      Parameters:
      count - the number of carvers making circular rooms and corridors between them; only matters in relation to other carvers
      See Also:
      MixedGenerator
    • putWalledRoundRoomCarvers

      public void putWalledRoundRoomCarvers​(int count)
      Changes the number of "carvers" that will create right-angle corridors from one room to the next, create rooms with a random size in a circle shape at the start and end, and a small circular room at the corner if there is one. This also ensures walls will be placed around the room, only allowing corridors and small cave openings to pass. If count is 0 or less, no circular rooms will be made. If count is at least 1, circular rooms are possible, and higher numbers relative to the other carvers make circular rooms more likely. Carvers are shuffled when used, then repeat if exhausted during generation. Since typically about 30-40 rooms are carved, large totals for carver count aren't really needed; aiming for a total of 10 between the count of putCaveCarvers(), putBoxRoomCarvers(), and putRoundRoomCarvers() is reasonable.
      Parameters:
      count - the number of carvers making circular rooms and corridors between them; only matters in relation to other carvers
      See Also:
      MixedGenerator
    • generate

      public char[][] generate()
      This generates a new map by stretching a 16x16 grid of potential rooms to fit the width and height passed to the constructor, randomly expanding columns and rows before contracting the whole to fit perfectly. This uses the Moore Curve, a space-filling curve that loops around on itself, to guarantee that the rooms will always have a long path through the dungeon that, if followed completely, will take you back to your starting room. Some small branches are possible, and large rooms may merge with other rooms nearby. This uses MixedGenerator.
      Specified by:
      generate in interface IDungeonGenerator
      Returns:
      a char[][] where '#' is a wall and '.' is a floor or corridor; x first y second
      See Also:
      MixedGenerator
    • getEnvironment

      public int[][] getEnvironment()
      Gets a 2D array of int constants, each representing a type of environment corresponding to a static field of MixedGenerator. This array will have the same size as the last char 2D array produced by generate(); the value of this method if called before generate() is undefined, but probably will be a 2D array of all 0 (UNTOUCHED).
      • MixedGenerator.UNTOUCHED, equal to 0, is used for any cells that aren't near a floor.
      • MixedGenerator.ROOM_FLOOR, equal to 1, is used for floor cells inside wide room areas.
      • MixedGenerator.ROOM_WALL, equal to 2, is used for wall cells around wide room areas.
      • MixedGenerator.CAVE_FLOOR, equal to 3, is used for floor cells inside rough cave areas.
      • MixedGenerator.CAVE_WALL, equal to 4, is used for wall cells around rough cave areas.
      • MixedGenerator.CORRIDOR_FLOOR, equal to 5, is used for floor cells inside narrow corridor areas.
      • MixedGenerator.CORRIDOR_WALL, equal to 6, is used for wall cells around narrow corridor areas.
      Returns:
      a 2D int array where each element is an environment type constant in MixedGenerator
    • getDungeon

      public char[][] getDungeon()
      Description copied from interface: IDungeonGenerator
      Gets the most recently-produced dungeon as a 2D char array, usually produced by calling IDungeonGenerator.generate() 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 interface IDungeonGenerator
      Returns:
      the most recently-produced dungeon/map as a 2D char array