Class RuleLoader

java.lang.Object
application.model.rules.Rule
application.model.rules.RuleFamily
application.model.rules.ruleloader.RuleLoader
All Implemented Interfaces:
java.lang.Cloneable

public class RuleLoader
extends RuleFamily
Implements the RuleLoader algorithm which CAViewer uses to load *.rule files.
  • Field Details

  • Constructor Details

    • RuleLoader

      public RuleLoader()
      Constructs a new RuleLoader rule.
    • RuleLoader

      public RuleLoader​(java.lang.String rulestring)
      Constructs a new RuleLoader rule with the provided name.
      Parameters:
      rulestring - The name of the RuleLoader rule (from rules directory or LifeWiki:Rule namespace)
  • Method Details

    • fromRulestring

      protected void fromRulestring​(java.lang.String rulestring)
      Loads the *.rule file from the LifeWiki:Rule namespace or from the rules directory
      Specified by:
      fromRulestring in class RuleFamily
      Parameters:
      rulestring - The name of the *.rule file
    • 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 class RuleFamily
      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 class RuleFamily
      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 class RuleFamily
      Returns:
      Description of the rule family
    • clone

      public java.lang.Object clone()
      Description copied from class: RuleFamily
      Clones the object
      Specified by:
      clone in class RuleFamily
      Returns:
      A deepcopy of the object
    • getNeighbourhood

      public Coordinate[] getNeighbourhood​(int generation)
      Description copied from class: Rule
      This method returns the neighbourhood of a given cell at a certain generation
      Specified by:
      getNeighbourhood in class Rule
      Parameters:
      generation - The generation of the simulation
      Returns:
      A list of Coordinates that represent the neighbourhood
    • 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
    • getColour

      public javafx.scene.paint.Color getColour​(int state)
      Description copied from class: Rule
      Returns the colour of a cell of the provided state
      Overrides:
      getColour in class Rule
      Parameters:
      state - The state of the cell
      Returns:
      The colour of the cell
    • addDirective

      public void addDirective​(Directive directive)
    • addRuleDirective

      public void addRuleDirective​(RuleDirective directive)
    • export

      public java.lang.String export()