Package application.model.rules.misc
Class AlternatingRule
java.lang.Object
application.model.rules.Rule
application.model.rules.RuleFamily
application.model.rules.misc.AlternatingRule
- All Implemented Interfaces:
ApgtableGeneratable
,java.lang.Cloneable
public class AlternatingRule extends RuleFamily implements ApgtableGeneratable
Implements the alternating rules rulespace
-
Field Summary
Fields inherited from class application.model.rules.Rule
alternatingPeriod, background, boundedGrid, numStates, readingOrder, tiling
-
Constructor Summary
Constructors Constructor Description AlternatingRule()
Constructs an alternating ruleAlternatingRule(java.lang.String rulestring)
Constructs an alternating rule based on the provided rulestring -
Method Summary
Modifier and Type Method Description java.lang.String
canonise(java.lang.String rulestring)
Canonises the inputted rulestring with the currently loaded parameters.java.lang.Object
clone()
Clones the objectprotected void
fromRulestring(java.lang.String rulestring)
Loads the rule's parameters from a rulestringRuleDirective[]
generateApgtable()
Generates an apgtable for apgsearch to usejava.lang.String
getDescription()
Returns a plain text description of the rule family to be displayed in the Rule DialogCoordinate[]
getNeighbourhood(int generation)
This method returns the neighbourhood of a given cell at a certain generationjava.lang.String[]
getRegex()
The regexes that will match a valid rulestringvoid
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 generationint
transitionFunc(int[] neighbours, int cellState, int generations, Coordinate coordinate)
This method represents the transition function of the ruleMethods inherited from class application.model.rules.RuleFamily
equals, generateComments, getName, getNeighbourList, getRuleInfo, getRulestring, hashCode, loadComments, setRulestring, toString, updateBackground
Methods inherited from class application.model.rules.Rule
convertState, dependsOnNeighbours, getAlternatingPeriod, getBoundedGrid, getColour, getName, getNeighbourhood, getNumStates, getTiling, setBackground, setBoundedGrid, setReadingOrder
-
Constructor Details
-
AlternatingRule
public AlternatingRule()Constructs an alternating rule -
AlternatingRule
public AlternatingRule(java.lang.String rulestring)Constructs an alternating rule based on the provided rulestring- Parameters:
rulestring
- The rulestring of the alternating rule
-
-
Method Details
-
fromRulestring
protected void fromRulestring(java.lang.String rulestring)Description copied from class:RuleFamily
Loads the rule's parameters from a rulestring- Specified by:
fromRulestring
in classRuleFamily
- Parameters:
rulestring
- The rulestring of the rule (eg. B3/S23, R2,C2,S5-9,B7-8,NM)
-
canonise
public java.lang.String canonise(java.lang.String rulestring)Description copied from class:RuleFamily
Canonises the inputted rulestring with the currently loaded parameters. This method should be called whenever the parameters of a rule are updated.- Specified by:
canonise
in classRuleFamily
- Parameters:
rulestring
- The rulestring to canonised- Returns:
- Canonised rulestring
-
getRegex
public java.lang.String[] getRegex()Description copied from class:RuleFamily
The regexes that will match a valid rulestring- Specified by:
getRegex
in classRuleFamily
- Returns:
- An array of regexes that will match a valid rulestring
-
getDescription
public java.lang.String getDescription()Description copied from class:RuleFamily
Returns a plain text description of the rule family to be displayed in the Rule Dialog- Specified by:
getDescription
in classRuleFamily
- Returns:
- Description of the rule family
-
clone
public java.lang.Object clone()Description copied from class:RuleFamily
Clones the object- Specified by:
clone
in classRuleFamily
- Returns:
- A deepcopy of the object
-
getNeighbourhood
Description copied from class:Rule
This method returns the neighbourhood of a given cell at a certain generation- Specified by:
getNeighbourhood
in classRule
- Parameters:
generation
- The generation of the simulation- Returns:
- A list of Coordinates that represent the neighbourhood
-
transitionFunc
Description copied from class:Rule
This method represents the transition function of the rule- Specified by:
transitionFunc
in classRule
- 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
-
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.IllegalArgumentExceptionDescription copied from class:Rule
Steps the grid provided forward one generation- Overrides:
step
in classRule
- 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
-
generateApgtable
Description copied from interface:ApgtableGeneratable
Generates an apgtable for apgsearch to use- Specified by:
generateApgtable
in interfaceApgtableGeneratable
- Returns:
- Returns an array of rule directives to be placed in the ruletable
-