Package application.model.rules
Class Rule
java.lang.Object
application.model.rules.Rule
- Direct Known Subclasses:
RuleFamily
public abstract class Rule
extends java.lang.Object
Represents a single rule
-
Field Summary
Fields Modifier and Type Field Description protected int
alternatingPeriod
Alternating period of the ruleprotected int[]
background
A list of backgrounds to be used for B0 rules.protected BoundedGrid
boundedGrid
Bounded grid used by the ruleprotected int
numStates
Number of states in the ruleprotected ReadingOrder
readingOrder
Naive reading order used by the ruleprotected Tiling
tiling
The tiling of the rule -
Constructor Summary
Constructors Constructor Description Rule()
-
Method Summary
Modifier and Type Method Description int
convertState(int state, int generation)
Convert the cell state based on the background Used to simulate B0 rulesint
dependsOnNeighbours(int state, int generation, Coordinate coordinate)
If the next state of the cell depends on its neighbours, return -1.int
getAlternatingPeriod()
Gets the alternating period of the ruleBoundedGrid
getBoundedGrid()
Gets the bounded grid of the rulejavafx.scene.paint.Color
getColour(int state)
Returns the colour of a cell of the provided statejava.lang.String
getName(int state)
Returns the name of the provided stateCoordinate[]
getNeighbourhood()
This method returns the neighbourhood of a given cell at a generation 0abstract Coordinate[]
getNeighbourhood(int generation)
This method returns the neighbourhood of a given cell at a certain generationint
getNumStates()
Gets the number of states in the ruleTiling
getTiling()
Returns the tiling of the rule (Square, Hexagonal or Triangular)void
setBackground(int[] background)
Sets the background of the rulevoid
setBoundedGrid(BoundedGrid boundedGrid)
Sets the bounded grid of the rulevoid
setReadingOrder(ReadingOrder order)
Sets the naive reading order of the rulevoid
step(Grid grid, java.util.ArrayList<java.util.Set<Coordinate>> cellsChanged, int generation, java.util.function.Function<Coordinate,java.lang.Boolean> step)
Steps the grid provided forward one generationabstract int
transitionFunc(int[] neighbours, int cellState, int generations, Coordinate coordinate)
This method represents the transition function of the rule
-
Field Details
-
background
protected int[] backgroundA list of backgrounds to be used for B0 rules. Example: A 3-state generations B0 rule without Smax would have a background of {0, 1, 2}. A non-B0 rule would have a background of {0}. -
numStates
protected int numStatesNumber of states in the rule -
alternatingPeriod
protected int alternatingPeriodAlternating period of the rule -
tiling
The tiling of the rule -
boundedGrid
Bounded grid used by the rule -
readingOrder
Naive reading order used by the rule
-
-
Constructor Details
-
Rule
public Rule()
-
-
Method Details
-
getNeighbourhood
This method returns the neighbourhood of a given cell at a generation 0- Returns:
- A list of Coordinates that represent the neighbourhood
-
getNeighbourhood
This method returns the neighbourhood of a given cell at a certain generation- Parameters:
generation
- The generation of the simulation- Returns:
- A list of Coordinates that represent the neighbourhood
-
transitionFunc
public abstract int transitionFunc(int[] neighbours, int cellState, int generations, Coordinate coordinate)This method represents the transition function of the rule- Parameters:
neighbours
- The cell's neighbours in the order of the neighbourhood providedcellState
- The current state of the cellgenerations
- The current generation of the simulationcoordinate
- The coordinate of the cell- Returns:
- The state of the cell in the next generation
-
dependsOnNeighbours
If the next state of the cell depends on its neighbours, return -1. If not return the next state of the cell.- Parameters:
state
- The current state of the cellgeneration
- The generation of the simulationcoordinate
- The coordinate of the cell- Returns:
- Returns -1 or the next state of the cell
-
getAlternatingPeriod
public int getAlternatingPeriod()Gets the alternating period of the rule- Returns:
- Returns the rule's alternating period
-
getNumStates
public int getNumStates()Gets the number of states in the rule- Returns:
- Returns the number of states in the rule
-
getColour
public javafx.scene.paint.Color getColour(int state)Returns the colour of a cell of the provided state- Parameters:
state
- The state of the cell- Returns:
- The colour of the cell
-
getName
public java.lang.String getName(int state)Returns the name of the provided state- Parameters:
state
- The state of the cell- Returns:
- The name of the state
-
getTiling
Returns the tiling of the rule (Square, Hexagonal or Triangular)- Returns:
- Returns the rule's tiling
-
getBoundedGrid
Gets the bounded grid of the rule- Returns:
- Returns the bounded grid of the rule
-
step
public void step(Grid grid, java.util.ArrayList<java.util.Set<Coordinate>> cellsChanged, int generation, java.util.function.Function<Coordinate,java.lang.Boolean> step) throws java.lang.IllegalArgumentExceptionSteps the grid provided forward one generation- Parameters:
grid
- The grid that will be stepped forward one generationcellsChanged
- An array of sets that contains the cells the changed in the previous generations. The first entry will contains the cells that changed in the previous generation and the next entry will contain the cells that changed the previous previous generation and so on. It should be the same length as the alternating period of the rulegeneration
- The current generation of the simulationstep
- A function that returns whether the cell at that coordinate should be stepped forward.- Throws:
java.lang.IllegalArgumentException
- Thrown if the length of cellsChanged is not the same as the alternating period
-
convertState
public int convertState(int state, int generation)Convert the cell state based on the background Used to simulate B0 rules- Parameters:
state
- The current state of the cellgeneration
- The generation of the simulation- Returns:
- Returns the new cell state
-
setBackground
public void setBackground(int[] background)Sets the background of the rule- Parameters:
background
- The background of the rule
-
setBoundedGrid
Sets the bounded grid of the rule- Parameters:
boundedGrid
- The bounded grid of the rule
-
setReadingOrder
Sets the naive reading order of the rule- Parameters:
order
- The naive reading order the rule should use
-