Class MimicFill

java.lang.Object
squidpony.squidgrid.MimicFill

public class MimicFill
extends Object
A class that imitates patterns in an existing 2D boolean array and uses it to generate a new boolean array with a similar visual style. Useful for creating procedural filler around a desired path or series of known rooms. Can also convert between 2D boolean arrays (samples) and 2D char arrays (maps). Created by Tommy Ettinger on 5/14/2016, porting from https://github.com/mxgmn/ConvChain (public domain)
  • Field Summary

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

    Modifier and Type Method Description
    static boolean[][] andSamples​(boolean[][] left, boolean[][] right)
    Runs a logical AND on each pair of booleans at the same position in left and right, and returns the result of all the AND operations as a 2D boolean array (using the minimum dimensions shared between left and right).
    static boolean[][] fill​(boolean[][] sample, int size, double temperature, int iterations, IRNG random)
    The main part of MimicFill; generates a 2D boolean array that mimics the patterns present in the 2D boolean array sample, but can produce a larger or smaller output 2D array than the sample.
    static boolean[] fillSolo​(boolean[][] sample, int size, double temperature, int iterations, IRNG random)
    The main part of MimicFill; generates a 1D boolean array that, when used correctly, mimics the patterns present in the 2D boolean array sample, but can produce a larger or smaller output 1D array than the sample.
    static boolean[][] mapToSample​(char[][] map, char... yes)
    Converts a 2D char array map to a 2D boolean array, 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 boolean[][] markSample​(boolean[][] sample, Iterable<Coord> points)
    Given a 2D boolean array 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), copies sample, then marks every Coord in points as true if it is in-bounds, and returns the modified copy of sample.
    static boolean[][] orSamples​(boolean[][] left, boolean[][] right)
    Runs a logical OR on each pair of booleans at the same position in left and right, and returns the result of all the OR operations as a 2D boolean array (using the minimum dimensions shared between left and right).
    static char[][] sampleToMap​(boolean[][] sample, char yes, char no)
    Comverts a 2D boolean array to a 2D char array, where false means the parameter no and true the parameter yes.
    static char[][] sampleToMap​(boolean[] sample, int width, int height, char yes, char no)
    Comverts a 2D boolean array to a 2D char array, where false means the parameter no and true the parameter yes.

    Methods inherited from class java.lang.Object

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

    • boulders

      public static final boolean[][] boulders
      Predefined sample; many small separate squares.
    • cave

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

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

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

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

      public static final boolean[][] 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 boolean[][] quarterBlack
      Predefined sample; produces weird, large areas of "true" and "false" that suddenly change to the other.
    • river

      public static final boolean[][] river
      Predefined sample; produces multiple directions of flowing, river-like shapes made of "false".
    • rooms

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

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

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

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

      public static final boolean[][] ruins
    • openRooms

      public static final boolean[][] openRooms
    • samples

      public static final boolean[][][] samples
  • Method Details

    • mapToSample

      public static boolean[][] mapToSample​(char[][] map, char... yes)
      Converts a 2D char array map to a 2D boolean array, 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:
      map - a 2D char array that you want converted to a 2D boolean array
      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​(boolean[][] sample, char yes, char no)
      Comverts a 2D boolean array to a 2D char array, where false means the parameter no and true the parameter yes.
      Parameters:
      sample - a 2D boolean array that you want converted to a 2D char array
      yes - true in sample will be mapped to this char; usually '.'
      no - false in sample will be mapped to this char; usually '#'
      Returns:
      a 2D char array containing only the chars yes and no
    • sampleToMap

      public static char[][] sampleToMap​(boolean[] sample, int width, int height, char yes, char no)
      Comverts a 2D boolean array to a 2D char array, where false means the parameter no and true the parameter yes.
      Parameters:
      sample - a 1D boolean array that you want converted to a 2D char array
      width - the desired width of the 2D char array
      height - the desired height of the 2D char array
      yes - true in sample will be mapped to this char; usually '.'
      no - false in sample will be mapped to this char; usually '#'
      Returns:
      a 2D char array containing only the chars yes and no
    • orSamples

      public static boolean[][] orSamples​(boolean[][] left, boolean[][] right)
      Runs a logical OR on each pair of booleans at the same position in left and right, and returns the result of all the OR operations as a 2D boolean array (using the minimum dimensions shared between left and right).
      Parameters:
      left - a 2D boolean array
      right - another 2D boolean array
      Returns:
      the 2D array resulting from a logical OR on each pair of booleans at a point shared by left and right
    • andSamples

      public static boolean[][] andSamples​(boolean[][] left, boolean[][] right)
      Runs a logical AND on each pair of booleans at the same position in left and right, and returns the result of all the AND operations as a 2D boolean array (using the minimum dimensions shared between left and right).
      Parameters:
      left - a 2D boolean array
      right - another 2D boolean array
      Returns:
      the 2D array resulting from a logical AND on each pair of booleans at a point shared by left and right
    • markSample

      public static boolean[][] markSample​(boolean[][] sample, Iterable<Coord> points)
      Given a 2D boolean array 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), copies sample, then marks every Coord in points as true if it is in-bounds, and returns the modified copy of sample. 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 2D boolean array; will be copied, not modified directly
      points - an Iterable (such as a List or Set) of Coord that will be marked as true if in-bounds
      Returns:
      a copy of sample with the Coords in points marked as true
    • fill

      public static boolean[][] fill​(boolean[][] sample, int size, double temperature, int iterations, IRNG random)
      The main part of MimicFill; generates a 2D boolean array that mimics the patterns present in the 2D boolean array sample, but can produce a larger or smaller output 2D array than the sample. Takes a 2D boolean array as a "sample" (often one of the constants in this class), a size parameter for the generated square data (same width and height) 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.2 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. This also takes an RNG, and because it queries it very frequently, a fast RNG is ideal; the default RandomnessSource used by RNG (DiverRNG) is fine, and in most cases MiniMover64RNG will be reasonably good for quality while probably being slightly faster. On GWT, GWTRNG is a good choice due to how few operations on long values it needs to do, and GWT has a hard time with longs; the algorithm used by GWTRNG can also produce all but one possible long value.
      Parameters:
      sample - a 2D boolean array to mimic visually; you can use mapToSample() if you have a 2D char array
      size - the side length of the square boolean array to generate
      temperature - typically 0.2 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 RNG to use for the random components of this technique
      Returns:
      a new 2D boolean array, width = size, height = size, mimicking the visual style of sample
    • fillSolo

      public static boolean[] fillSolo​(boolean[][] sample, int size, double temperature, int iterations, IRNG random)
      The main part of MimicFill; generates a 1D boolean array that, when used correctly, mimics the patterns present in the 2D boolean array sample, but can produce a larger or smaller output 1D array than the sample. Using the output correctly mostly involves passing the 1D boolean array with the correct width and height settings to sampleToMap(boolean[], int, int, char, char) to get a 2D char array or producing a GreasedRegion with it using GreasedRegion(boolean[], int, int). Both the width and height used to interpret the 1D array as a 2D array should be equal to the size parameter passed here. The main reason you would prefer this method over fill(boolean[][], int, double, int, IRNG) is that this overload is somewhat faster due to slightly less-frequent RNG calls and a lot less nested array reading and writing.
      Takes a 2D boolean array as a "sample" (often one of the constants in this class), a size parameter for the generated square data (same width and height) 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.2 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. This also takes an RNG, and because it queries it very frequently, a fast RNG is ideal; the default RandomnessSource used by RNG (DiverRNG) is fine, and in most cases MiniMover64RNG will be reasonably good for quality while probably being slightly faster. On GWT, GWTRNG is a good choice due to how few operations on long values it needs to do, and GWT has a hard time with longs; the algorithm used by GWTRNG can also produce all but one possible long value.
      Parameters:
      sample - a 2D boolean array to mimic visually; you can use mapToSample() if you have a 2D char array
      size - the side length of the square boolean array to generate
      temperature - typically 0.2 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 RNG to use for the random components of this technique
      Returns:
      a new 1D boolean array, length = size * size, mimicking the visual style of sample when used as 2D data