Package application.model.rules.hrot
Class HROTRegeneratingGenerations
java.lang.Object
application.model.rules.Rule
application.model.rules.RuleFamily
application.model.rules.hrot.BaseHROT
application.model.rules.hrot.HROTRegeneratingGenerations
- All Implemented Interfaces:
ApgtableGeneratable,MinMaxRuleable,java.lang.Cloneable
public class HROTRegeneratingGenerations extends BaseHROT implements MinMaxRuleable, ApgtableGeneratable
Implements the HROT Regenerating Generations rule family
-
Field Summary
Fields inherited from class application.model.rules.hrot.BaseHROT
hrotTransitions, neighbourhood, neighbourhoodRegex, weightsFields inherited from class application.model.rules.Rule
alternatingPeriod, background, boundedGrid, numStates, readingOrder, tiling -
Constructor Summary
Constructors Constructor Description HROTRegeneratingGenerations()Creates a HROT Regenerating Generations rule with the rule RegenLifeHROTRegeneratingGenerations(java.lang.String rulestring)Creates a HROT Regenerating Generations rule with the given rulestring -
Method Summary
Modifier and Type Method Description booleanbetweenMinMax(RuleFamily minRule, RuleFamily maxRule)Checks if the current rule is between the given minimum and maximum rulesjava.lang.Stringcanonise(java.lang.String rulestring)Canonises the inputted rulestring with the currently loaded parameters.java.lang.Objectclone()Clones the ruleprotected voidfromRulestring(java.lang.String rulestring)Loads the rule's parameters from a rulestringRuleDirective[]generateApgtable()Generates an apgtable for apgsearch to usejava.lang.String[]generateComments()Generates comments that will be placed in the RLE.java.util.HashSet<java.lang.Integer>getBirth()The birth conditions of the rule (e.g.java.lang.StringgetDescription()Returns a plain text description of the HROT Regenerating Generations rule family to be displayed in the Rule Dialogorg.javatuples.Pair<RuleFamily,RuleFamily>getMinMaxRule(Grid[] grids)Returns the minimum and maximum rule of the provided evolutionary sequencejava.util.HashSet<java.lang.Integer>getRegenBirth()The regenerating birth conditions of the rule (e.g.java.util.HashSet<java.lang.Integer>getRegenSurvival()The survival conditions of the rule (e.g.java.lang.String[]getRegex()The regexes that will match a valid rulestringint[]getStateWeights()Gets the state weights of the HROT Regenerating Generations rulejava.util.HashSet<java.lang.Integer>getSurvival()The survival conditions of the rule (e.g.voidloadComments(java.lang.String[] comments)Loads the weights stored in the comments generated by generateCommentsvoidrandomise(RuleFamily minRule, RuleFamily maxRule)Randomise the parameters of the current rule to be between minimum and maximum rules Used in CAViewer's rule search programvoidsetBirth(java.util.HashSet<java.lang.Integer> birth)Sets the birth conditions of the rulevoidsetRegenBirth(java.util.HashSet<java.lang.Integer> birth)Sets the regenerating birth conditions of the rulevoidsetRegenSurvival(java.util.HashSet<java.lang.Integer> survival)Sets the survival conditions of the rulevoidsetStateWeights(int[] stateWeights)Sets the states weights of the rulevoidsetSurvival(java.util.HashSet<java.lang.Integer> survival)Sets the survival conditions of the ruleinttransitionFunc(int[] neighbours, int cellState, int generations, Coordinate coordinate)This method represents the transition function of the rulevoidupdateBackground()Updates the background based on the currently loaded parametersbooleanvalidMinMax(RuleFamily minRule, RuleFamily maxRule)Checks if the minimum rule and maximum rules provided are validMethods inherited from class application.model.rules.hrot.BaseHROT
getNeighbourhood, getNeighbourhoodSpecifier, getRuleInfo, getWeights, loadNeighbourhood, setNeighbourhood, setWeightsMethods inherited from class application.model.rules.RuleFamily
equals, getName, getNeighbourList, getRulestring, hashCode, setRulestring, toStringMethods inherited from class application.model.rules.Rule
convertState, dependsOnNeighbours, getAlternatingPeriod, getBoundedGrid, getColour, getName, getNeighbourhood, getNumStates, getTiling, setBackground, setBoundedGrid, setReadingOrder, step
-
Constructor Details
-
HROTRegeneratingGenerations
public HROTRegeneratingGenerations()Creates a HROT Regenerating Generations rule with the rule RegenLife -
HROTRegeneratingGenerations
public HROTRegeneratingGenerations(java.lang.String rulestring)Creates a HROT Regenerating Generations rule with the given rulestring- Parameters:
rulestring- The rulestring of the HROT Regenerating Generations rule to be created- Throws:
java.lang.IllegalArgumentException- Thrown if the rulestring is invalid
-
-
Method Details
-
fromRulestring
protected void fromRulestring(java.lang.String rulestring) throws java.lang.IllegalArgumentExceptionLoads the rule's parameters from a rulestring- Specified by:
fromRulestringin classRuleFamily- Parameters:
rulestring- The rulestring of the HROT Regenerating Generations rule (eg. R1,C3,S1-2,B3-4,NM)- Throws:
java.lang.IllegalArgumentException- Thrown if an invalid rulestring is passed in
-
canonise
public java.lang.String canonise(java.lang.String rulestring)Canonises the inputted rulestring with the currently loaded parameters.- Specified by:
canonisein classRuleFamily- Parameters:
rulestring- The rulestring to canonised- Returns:
- Canonised rulestring
-
getRegex
public java.lang.String[] getRegex()The 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()Returns a plain text description of the HROT Regenerating Generations rule family to be displayed in the Rule Dialog- Specified by:
getDescriptionin classRuleFamily- Returns:
- Description of the HROT Regenerating Generations rule family
-
updateBackground
public void updateBackground()Updates the background based on the currently loaded parameters- Overrides:
updateBackgroundin classRuleFamily
-
randomise
public void randomise(RuleFamily minRule, RuleFamily maxRule) throws java.lang.IllegalArgumentExceptionRandomise the parameters of the current rule to be between minimum and maximum rules Used in CAViewer's rule search program- Specified by:
randomisein interfaceMinMaxRuleable- Parameters:
minRule- The minimum rule for randomisationmaxRule- The maximum rule for randomisation- Throws:
java.lang.IllegalArgumentException- Thrown if the minimum and maximum rules are invalid
-
getMinMaxRule
Returns the minimum and maximum rule of the provided evolutionary sequence- Specified by:
getMinMaxRulein interfaceMinMaxRuleable- Parameters:
grids- An array of grids representing the evolutionary sequence- Returns:
- A pair containing the min rule as the first value and the max rule as the second value
-
betweenMinMax
public boolean betweenMinMax(RuleFamily minRule, RuleFamily maxRule) throws java.lang.IllegalArgumentExceptionChecks if the current rule is between the given minimum and maximum rules- Specified by:
betweenMinMaxin interfaceMinMaxRuleable- Parameters:
minRule- The minimum rulemaxRule- The maximum rule- Returns:
- True if the current rule is between minimum and maximum rules and false if the current rule is not between the minimum and maximum rules
- Throws:
java.lang.IllegalArgumentException- Thrown if the minimum rule and maximum rule are invalid
-
validMinMax
Checks if the minimum rule and maximum rules provided are valid- Specified by:
validMinMaxin interfaceMinMaxRuleable- Parameters:
minRule- The minimum rule to checkmaxRule- The maximum rule to check- Returns:
- True if the minimum and maximum rules are valid and false if the minimum and maximum rules are not valid
-
generateApgtable
Generates an apgtable for apgsearch to use- Specified by:
generateApgtablein interfaceApgtableGeneratable- Returns:
- True if the operation was successful, false otherwise
- Throws:
java.lang.UnsupportedOperationException
-
generateComments
public java.lang.String[] generateComments()Generates comments that will be placed in the RLE. These comments represent weights. They are only generated if the neighbourhood specifier is N@ with no additional hex digits- Overrides:
generateCommentsin classBaseHROT- Returns:
- An array of comments each starting with "#R" (eg. {"#R 1 2 3 2 1", "#R 2 4 6 4 2"}). If no additional information needs to be added return null or an empty string array.
-
loadComments
public void loadComments(java.lang.String[] comments)Loads the weights stored in the comments generated by generateComments- Overrides:
loadCommentsin classBaseHROT- Parameters:
comments- The comments from the RLE (all starting with #R)
-
getBirth
public java.util.HashSet<java.lang.Integer> getBirth()The birth conditions of the rule (e.g. {2, 3})- Returns:
- Birth conditions of the rule
-
getSurvival
public java.util.HashSet<java.lang.Integer> getSurvival()The survival conditions of the rule (e.g. {2, 3})- Returns:
- Survival conditions of the rule
-
getRegenBirth
public java.util.HashSet<java.lang.Integer> getRegenBirth()The regenerating birth conditions of the rule (e.g. {2, 3})- Returns:
- Regenerating birth conditions of the rule
-
getRegenSurvival
public java.util.HashSet<java.lang.Integer> getRegenSurvival()The survival conditions of the rule (e.g. {2, 3})- Returns:
- Regenerating survival conditions of the rule
-
getStateWeights
public int[] getStateWeights()Gets the state weights of the HROT Regenerating Generations rule- Returns:
- State weights of the HROT Regenerating Generations rule
-
setBirth
public void setBirth(java.util.HashSet<java.lang.Integer> birth)Sets the birth conditions of the rule- Parameters:
birth- Birth conditions of the rule
-
setSurvival
public void setSurvival(java.util.HashSet<java.lang.Integer> survival)Sets the survival conditions of the rule- Parameters:
survival- Survival conditions of the rule
-
setRegenBirth
public void setRegenBirth(java.util.HashSet<java.lang.Integer> birth)Sets the regenerating birth conditions of the rule- Parameters:
birth- Regenerating birth conditions of the rule
-
setRegenSurvival
public void setRegenSurvival(java.util.HashSet<java.lang.Integer> survival)Sets the survival conditions of the rule- Parameters:
survival- Regenerating survival conditions of the rule
-
setStateWeights
public void setStateWeights(int[] stateWeights)Sets the states weights of the rule- Parameters:
stateWeights- State weights of the rule
-
clone
public java.lang.Object clone()Clones the rule- Specified by:
clonein classRuleFamily- Returns:
- Returns a deep copy of the HROT Regenerating Generations 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
-