Package math.wfc

Class Gridstate

java.lang.Object
math.wfc.Gridstate

public class Gridstate extends Object
A class storing the Superpositions in a grid.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Gridstate(int w, int h, Tile[] tileset)
    Constructor for a Gridstate object with just dimensions and tileset given.
    Gridstate(Superposition[][] grid, boolean looping, Superposition borderSP)
    Constructer for a Gridstate object with all possible parameters.
  • Method Summary

    Modifier and Type
    Method
    Description
    Overwrites the clone function from Object.
    boolean
    Collapses the State until a random choice is needed or the grid can't be finished.
    int
    Getter Function for the height of the grid.
    getPosition(int x, int y)
    Gets the Superposition object at a certain coordinate following the rules set by looping.
    int
    Getter Function for the width of the grid.
    boolean
    Tests if the grid is fully collapsed.
    Chooses a random possibility of a random Superposition that hasn't collapsed yet and collapses it down.
    Converts the Grid to its String representation.

    Methods inherited from class java.lang.Object

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

    • Gridstate

      public Gridstate(int w, int h, Tile[] tileset)
      Constructor for a Gridstate object with just dimensions and tileset given.
      Parameters:
      w - width of the grid
      h - height of the grid
      tileset - the tileset to fill the grid with
    • Gridstate

      public Gridstate(Superposition[][] grid, boolean looping, Superposition borderSP)
      Constructer for a Gridstate object with all possible parameters.
      Parameters:
      grid - The grid of Superpositions
      looping - Whether or not positions outside the grid should be looping around
      borderSP - If not the Superposition to return for positions outside the grid
  • Method Details

    • getPosition

      public Superposition getPosition(int x, int y)
      Gets the Superposition object at a certain coordinate following the rules set by looping.
      Parameters:
      x - x-Coordinate of the Position to get
      y - y-Coordinate of the Position to get
      Returns:
      Superposition object at that coordinate
    • getWidth

      public int getWidth()
      Getter Function for the width of the grid.
      Returns:
      Width of the grid
    • getHeight

      public int getHeight()
      Getter Function for the height of the grid.
      Returns:
      Height of the grid
    • collapse

      public boolean collapse()
      Collapses the State until a random choice is needed or the grid can't be finished.
      Returns:
      true if it stopped because the grid can't be finished
    • isFinished

      public boolean isFinished()
      Tests if the grid is fully collapsed.
      Returns:
      true if every Superposition is fully collapsed
    • makeRandomChoice

      public Gridstate makeRandomChoice(Random rand)
      Chooses a random possibility of a random Superposition that hasn't collapsed yet and collapses it down. If the function is executed multiple times it will collapse to a different State every time and return null if there are no States left.
      Parameters:
      rand - A java.util.Random object to use for randomisation
      Returns:
      A new Gridstate that has one random Superposition collapsed
    • clone

      public Object clone()
      Overwrites the clone function from Object.
      Overrides:
      clone in class Object
      Returns:
      Clone of the Gridstate object
    • toString

      public String toString()
      Converts the Grid to its String representation. If a Superposition has collapsed the id of the collapsed tile will be written at that position in the grid, otherwise a "~"-Symbol will be there.
      Overrides:
      toString in class Object
      Returns:
      String representation