Class ConvChain

java.lang.Object
com.github.yellowstonegames.grid.ConvChain

public final class ConvChain extends Object
A class that imitates patterns in an existing Region and uses it to fill another Region so it has a similar visual style. Useful for creating procedural filler around a desired path or series of known rooms. Can also convert between Regions (samples) and 2D char arrays (maps).
Ported from ConvChain (which is in the public domain).
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Region
    Predefined sample; many small separate squares.
    static final Region
    Predefined sample; a large, enclosed, organic space that usually makes large cave-like rooms.
    static final Region
    Predefined sample; several medium-sized organic spaces that usually make tight, chaotic tunnels.
    static final Region
    Predefined sample; a checkerboard pattern that typically loses recognition as such after generation.
    static final Region
    Predefined sample; produces rectangular rooms with small corridors between them.
    static final Region
    Predefined sample; produces a suitable filler for a maze (but it is unlikely to connect both ends like a maze).
    static final Region
     
    static final Region
    Predefined sample; produces weird, large areas of "on" and "off" that suddenly change to the other.
    static final Region
    Predefined sample; produces multiple directions of flowing, river-like shapes made of "off".
    static final Region
    Predefined sample; produces rectangular rooms with a dense packing.
    static final Region
     
    static final Region[]
     
    static final Region
    Predefined sample; produces an uncanny imitation of a maze with a tiny sample size.
    static final Region
    Predefined sample; produces mostly rectangular rooms with very few corridor-like areas.
    static final Region
    Predefined sample; produces largely rectangular rooms with a good amount of thin corridors.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Region
    fill(Region field, Region sample, double temperature, int iterations, com.github.tommyettinger.random.EnhancedRandom random)
    The main part of MimicFill; generates a Region that mimics the patterns present in the Region sample, but can produce a larger or smaller output Region than the sample.
    static Region
    fill(Region field, Region sample, double temperature, int iterations, com.github.tommyettinger.random.EnhancedRandom random, int order)
    The main part of MimicFill; generates a Region that mimics the patterns present in the Region sample, but can produce a larger or smaller output Region than the sample.
    static Region
    mapToSample(Region toFill, char[][] map, char... yes)
    Converts a 2D char array map to a Region, where any chars in the array or vararg yes will result in true in the returned array at that position and any other chars will result in false.
    static Region
    markSample(Region sample, Collection<Coord> points)
    Given a Region sample (usually a final product of this class' fill() method) and an Iterable of Coord (such as a List or Set of Coord, but a Region can also work), marks every Coord in points as true if it is in-bounds, and returns sample after modifications.
    static char[][]
    sampleToMap(Region sample, char on, char off)
    Converts a Region to a 2D char array, where "on" will be written as the char on, and "off" in the Region will be written as the char off

    Methods inherited from class Object

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

    • boulders

      public static final Region boulders
      Predefined sample; many small separate squares.
    • cave

      public static final Region cave
      Predefined sample; a large, enclosed, organic space that usually makes large cave-like rooms.
    • caves

      public static final Region caves
      Predefined sample; several medium-sized organic spaces that usually make tight, chaotic tunnels.
    • chess

      public static final Region chess
      Predefined sample; a checkerboard pattern that typically loses recognition as such after generation.
    • lessRooms

      public static final Region lessRooms
      Predefined sample; produces rectangular rooms with small corridors between them.
    • maze

      public static final Region maze
      Predefined sample; produces a suitable filler for a maze (but it is unlikely to connect both ends like a maze).
    • quarterBlack

      public static final Region quarterBlack
      Predefined sample; produces weird, large areas of "on" and "off" that suddenly change to the other.
    • river

      public static final Region river
      Predefined sample; produces multiple directions of flowing, river-like shapes made of "off".
    • rooms

      public static final Region rooms
      Predefined sample; produces rectangular rooms with a dense packing.
    • simpleMaze

      public static final Region simpleMaze
      Predefined sample; produces an uncanny imitation of a maze with a tiny sample size.
    • simpleRooms

      public static final Region simpleRooms
      Predefined sample; produces mostly rectangular rooms with very few corridor-like areas.
    • thickWalls

      public static final Region thickWalls
      Predefined sample; produces largely rectangular rooms with a good amount of thin corridors.
    • ruins

      public static final Region ruins
    • openRooms

      public static final Region openRooms
    • samples

      public static final Region[] samples
  • Method Details

    • mapToSample

      public static Region mapToSample(Region toFill, char[][] map, char... yes)
      Converts a 2D char array map to a Region, where any chars in the array or vararg yes will result in true in the returned array at that position and any other chars will result in false. The result can be given to fill() as its sample parameter.
      Parameters:
      toFill -
      map - a 2D char array that you want converted to a Region
      yes - an array or vararg of the chars to consider true in map
      Returns:
      a 2D boolean array that can be given to fill()
    • sampleToMap

      public static char[][] sampleToMap(Region sample, char on, char off)
      Converts a Region to a 2D char array, where "on" will be written as the char on, and "off" in the Region will be written as the char off
      Parameters:
      sample - a 2D boolean array that you want converted to a 2D char array
      on - true in sample will be mapped to this char; usually '.'
      off - false in sample will be mapped to this char; usually '#'
      Returns:
      a 2D char array containing only the chars yes and no
    • markSample

      public static Region markSample(Region sample, Collection<Coord> points)
      Given a Region sample (usually a final product of this class' fill() method) and an Iterable of Coord (such as a List or Set of Coord, but a Region can also work), marks every Coord in points as true if it is in-bounds, and returns sample after modifications. Does not alter the original sample. You may want to use this with techniques like drawing a long line with Bresenham, OrthoLine, or WobblyLine, potentially widening the line with Radius.expand(), and then passing the result as the Iterable of Coord. You could then make the start and end of the line into an entrance and exit and be sure the player can get from one to the other (except for Bresenham and other lines that may make diagonal movements, if the player cannot move diagonally).
      Parameters:
      sample - a Region; will be modified directly
      points - an Iterable (such as a List or Set) of Coord that will be marked as true if in-bounds
      Returns:
      sample, after modifications
    • fill

      public static Region fill(Region field, Region sample, double temperature, int iterations, com.github.tommyettinger.random.EnhancedRandom random)
      The main part of MimicFill; generates a Region that mimics the patterns present in the Region sample, but can produce a larger or smaller output Region than the sample. Takes a Region to fill with the output, a Region as a "sample" (often one of the constants in this class) and several other parameters that affect how closely the output will match the input. The temperature is how "agitated" or "chaotic" the changes to the map can be; 0.2f is definitely recommended for map-like data but other values (between 0 and 1, both exclusive) may be better fits for certain kinds of output. The iterations parameter should usually be between 3 and 5, with higher values taking longer but fitting more closely; values over 5 are barely different from 5 here.
      Parameters:
      field - a Region that will be modified; should be square, otherwise it will have its size increased
      sample - a Region to mimic visually; you can use mapToSample() if you have a 2D char array
      temperature - typically 0.2f works well for this, but other numbers between 0 and 1 may work
      iterations - typically 3-5 works well for this; lower numbers may have slight problems with quality, and higher numbers make this slightly slower
      random - an EnhancedRandom to use for the random components of this technique
      Returns:
      a new Region, width = size, height = size, mimicking the visual style of sample
    • fill

      public static Region fill(Region field, Region sample, double temperature, int iterations, com.github.tommyettinger.random.EnhancedRandom random, int order)
      The main part of MimicFill; generates a Region that mimics the patterns present in the Region sample, but can produce a larger or smaller output Region than the sample. Takes a Region to fill with the output, a Region as a "sample" (often one of the constants in this class) and several other parameters that affect how closely the output will match the input. The temperature is how "agitated" or "chaotic" the changes to the map can be; 0.2f is definitely recommended for map-like data but other values (between 0 and 1, both exclusive) may be better fits for certain kinds of output. The iterations parameter should usually be between 3 and 5, with higher values taking longer but fitting more closely; values over 5 are barely different from 5 here.
      Parameters:
      field - a Region that will be modified; should be square, otherwise it will have its size increased
      sample - a Region to mimic visually; you can use mapToSample() if you have a 2D char array
      temperature - typically 0.2f works well for this, but other numbers between 0 and 1 may work
      iterations - typically 3-5 works well for this; lower numbers may have slight problems with quality, and higher numbers make this slightly slower
      random - an EnhancedRandom to use for the random components of this technique
      order - the order of the algorithm from 2 to 5 inclusive; this determines how big each sample is (the edge length of a square sample).
      Returns:
      a new Region, width = size, height = size, mimicking the visual style of sample