Package math.wfc
Class Gridstate
java.lang.Object
math.wfc.Gridstate
A class storing the Superpositions in a grid.
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor 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 TypeMethodDescriptionclone()
Overwrites the clone function from Object.boolean
collapse()
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
getWidth()
Getter Function for the width of the grid.boolean
Tests if the grid is fully collapsed.makeRandomChoice
(Random rand) Chooses a random possibility of a random Superposition that hasn't collapsed yet and collapses it down.toString()
Converts the Grid to its String representation.
-
Constructor Details
-
Gridstate
Constructor for a Gridstate object with just dimensions and tileset given.- Parameters:
w
- width of the gridh
- height of the gridtileset
- the tileset to fill the grid with
-
Gridstate
Constructer for a Gridstate object with all possible parameters.- Parameters:
grid
- The grid of Superpositionslooping
- Whether or not positions outside the grid should be looping aroundborderSP
- If not the Superposition to return for positions outside the grid
-
-
Method Details
-
getPosition
Gets the Superposition object at a certain coordinate following the rules set by looping.- Parameters:
x
- x-Coordinate of the Position to gety
- 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
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
Overwrites the clone function from Object. -
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.
-