Package application.model.rules.misc
Class OneDimensional
java.lang.Object
application.model.rules.Rule
application.model.rules.RuleFamily
application.model.rules.misc.OneDimensional
- All Implemented Interfaces:
java.lang.Cloneable
public class OneDimensional extends RuleFamily
Represents a 1D cellular automaton rule
-
Field Summary
Fields inherited from class application.model.rules.Rule
alternatingPeriod, background, boundedGrid, numStates, readingOrder, tiling -
Constructor Summary
Constructors Constructor Description OneDimensional()Creates the rule W110OneDimensional(java.lang.String rulestring)Creates a 1D rule based on the provided rulestring -
Method Summary
Modifier and Type Method Description java.lang.Stringcanonise(java.lang.String rulestring)Canonises the inputted rulestring with the currently loaded parameters.java.lang.Objectclone()Gets the deep copy of the 1D ruleprotected voidfromRulestring(java.lang.String rulestring)Loads the 1D rule's parameters from a rulestringjava.lang.StringgetDescription()Returns a plain text description of the rule family to be displayed in the Rule DialogCoordinate[]getNeighbourhood(int generation)Gets the neighbourhood of the 1D rulejava.lang.String[]getRegex()The regexes that will match a valid rulestringinttransitionFunc(int[] neighbours, int cellState, int generations, Coordinate coordinate)This method represents the transition function of the rulevoidupdateBackground()Updates the background of the rule based on the loaded parameters.Methods inherited from class application.model.rules.RuleFamily
equals, generateComments, getName, getNeighbourList, getRuleInfo, getRulestring, hashCode, loadComments, setRulestring, toStringMethods inherited from class application.model.rules.Rule
convertState, dependsOnNeighbours, getAlternatingPeriod, getBoundedGrid, getColour, getName, getNeighbourhood, getNumStates, getTiling, setBackground, setBoundedGrid, setReadingOrder, step
-
Constructor Details
-
OneDimensional
public OneDimensional()Creates the rule W110 -
OneDimensional
public OneDimensional(java.lang.String rulestring)Creates a 1D rule based on the provided rulestring- Parameters:
rulestring- The rulestring of the 1D rule
-
-
Method Details
-
fromRulestring
protected void fromRulestring(java.lang.String rulestring)Loads the 1D rule's parameters from a rulestring- Specified by:
fromRulestringin classRuleFamily- Parameters:
rulestring- The rulestring of the 1D rule (e.g. W110, R1,C3,W1902)- Throws:
java.lang.IllegalArgumentException- Thrown if the rulestring is invalid
-
canonise
public java.lang.String canonise(java.lang.String rulestring)Description copied from class:RuleFamilyCanonises the inputted rulestring with the currently loaded parameters. This method should be called whenever the parameters of a rule are updated.- Specified by:
canonisein classRuleFamily- Parameters:
rulestring- The rulestring to canonised- Returns:
- Canonised rulestring
-
updateBackground
public void updateBackground()Description copied from class:RuleFamilyUpdates the background of the rule based on the loaded parameters. This method should be called whenever the parameters of a rule are updated. For non-strobing rules, the background is {0}.- Overrides:
updateBackgroundin classRuleFamily
-
getRegex
public java.lang.String[] getRegex()Description copied from class:RuleFamilyThe regexes that will match a valid rulestring- Specified by:
getRegexin classRuleFamily- Returns:
- An array of regexes that will match a valid rulestring
-
getDescription
public java.lang.String getDescription()Description copied from class:RuleFamilyReturns a plain text description of the rule family to be displayed in the Rule Dialog- Specified by:
getDescriptionin classRuleFamily- Returns:
- Description of the rule family
-
clone
public java.lang.Object clone()Gets the deep copy of the 1D rule- Specified by:
clonein classRuleFamily- Returns:
- Returns a deep copy of the 1D rule
-
getNeighbourhood
Gets the neighbourhood of the 1D rule- Specified by:
getNeighbourhoodin classRule- Parameters:
generation- The generation of the simulation- Returns:
- Returns the neighbourhood of the 1D rule
-
transitionFunc
Description copied from class:RuleThis method represents the transition function of the rule- Specified by:
transitionFuncin 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
-