Class HROT

All Implemented Interfaces:
ApgtableGeneratable, MinMaxRuleable, java.lang.Cloneable
Direct Known Subclasses:
HROTDeadlyEnemies, HROTHistory, HROTSymbiosis

public class HROT
extends BaseHROT
implements MinMaxRuleable, ApgtableGeneratable
Implements the 2-state HROT rule family
  • Field Details

    • birth

      protected final java.util.HashSet<java.lang.Integer> birth
      The birth conditions of the HROT rule
    • survival

      protected final java.util.HashSet<java.lang.Integer> survival
      The survival conditions of the HROT rule
    • maxNeighbourhoodCount

      protected int maxNeighbourhoodCount
      The maximum possible neighbourhood count. Used for B0 and min, max rule generation.
  • Constructor Details

    • HROT

      public HROT()
      Creates a 2-state HROT rule with the Minibugs rule
    • HROT

      public HROT​(java.lang.String rulestring)
      Creates a 2-state HROT rule with the given rulestring
      Parameters:
      rulestring - The rulestring of the 2-state HROT 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.IllegalArgumentException
      Loads the rule's parameters from a rulestring
      Specified by:
      fromRulestring in class RuleFamily
      Parameters:
      rulestring - The rulestring of the HROT rule (eg. B3/S23, R2,C2,S6-9,B7-8,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:
      canonise in class RuleFamily
      Parameters:
      rulestring - The rulestring to canonised
      Returns:
      Canonised rulestring
    • updateBackground

      public void updateBackground()
      Updates the background based on the currently loaded parameters
      Overrides:
      updateBackground in class RuleFamily
    • getRegex

      public java.lang.String[] getRegex()
      The regexes that will match a valid rulestring
      Specified by:
      getRegex in class RuleFamily
      Returns:
      An array of regexes that will match a valid rulestring
    • getDescription

      public java.lang.String getDescription()
      Returns a plain text description of the 2-state HROT rule family to be displayed in the Rule Dialog
      Specified by:
      getDescription in class RuleFamily
      Returns:
      Description of the 2-state HROT rule family
    • randomise

      public void randomise​(RuleFamily minRule, RuleFamily maxRule) throws java.lang.IllegalArgumentException
      Randomise the parameters of the current rule to be between minimum and maximum rules Used in CAViewer's rule search program
      Specified by:
      randomise in interface MinMaxRuleable
      Parameters:
      minRule - The minimum rule for randomisation
      maxRule - The maximum rule for randomisation
      Throws:
      java.lang.IllegalArgumentException - Thrown if the minimum and maximum rules are invalid
    • getMinMaxRule

      public org.javatuples.Pair<RuleFamily,​RuleFamily> getMinMaxRule​(Grid[] grids)
      Returns the minimum and maximum rule of the provided evolutionary sequence
      Specified by:
      getMinMaxRule in interface MinMaxRuleable
      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.IllegalArgumentException
      Checks if the current rule is between the given minimum and maximum rules
      Specified by:
      betweenMinMax in interface MinMaxRuleable
      Parameters:
      minRule - The minimum rule
      maxRule - 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

      public boolean validMinMax​(RuleFamily minRule, RuleFamily maxRule)
      Checks if the minimum rule and maximum rules provided are valid
      Specified by:
      validMinMax in interface MinMaxRuleable
      Parameters:
      minRule - The minimum rule to check
      maxRule - 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

      public RuleDirective[] generateApgtable()
      Generates an apgtable for apgsearch to use
      Specified by:
      generateApgtable in interface ApgtableGeneratable
      Returns:
      True if the operation was successful, false otherwise
    • 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
    • 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 - Birth conditions of the rule
    • clone

      public java.lang.Object clone()
      Clones the rule
      Specified by:
      clone in class RuleFamily
      Returns:
      Returns a deep copy of the HROT rule
    • getName

      public java.lang.String getName​(int state)
      Returns the name of the provided state
      Overrides:
      getName in class Rule
      Parameters:
      state - The state of the cell
      Returns:
      The name of the state
    • transitionFunc

      public int transitionFunc​(int[] neighbours, int cellState, int generations, Coordinate coordinate)
      Description copied from class: Rule
      This method represents the transition function of the rule
      Specified by:
      transitionFunc in class Rule
      Parameters:
      neighbours - The cell's neighbours in the order of the neighbourhood provided
      cellState - The current state of the cell
      generations - The current generation of the simulation
      coordinate - The coordinate of the cell
      Returns:
      The state of the cell in the next generation