Class Margolus

java.lang.Object
All Implemented Interfaces:
java.lang.Cloneable

public class Margolus
extends RuleFamily
Represents a 2-state Margolus rule
  • Constructor Details

    • Margolus

      public Margolus()
      Creates a margolus rule
    • Margolus

      public Margolus​(java.lang.String rulestring)
      Creates a Margolus rule based on the provided rulestring
      Parameters:
      rulestring - The rulestring of the Margolus rule
  • Method Details

    • fromRulestring

      protected void fromRulestring​(java.lang.String rulestring)
      Loads the Margolus rule's parameters from a rulestring
      Specified by:
      fromRulestring in class RuleFamily
      Parameters:
      rulestring - The rulestring of the Margolus rule
      Throws:
      java.lang.IllegalArgumentException - Thrown if the rulestring is invalid
    • 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
    • updateBackground

      public void updateBackground()
      Description copied from class: RuleFamily
      Updates 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:
      updateBackground in class RuleFamily
    • 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()
      Gets the deep copy of the Margolus rule
      Specified by:
      clone in class RuleFamily
      Returns:
      Returns a deep copy of the Margolus rule
    • getNeighbourhood

      public Coordinate[] getNeighbourhood​(int generation)
      Gets the neighbourhood of the 1D rule
      Specified by:
      getNeighbourhood in class Rule
      Parameters:
      generation - The generation of the simulation
      Returns:
      Returns the neighbourhood of the 1D rule
    • 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
    • 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.IllegalArgumentException
      Description copied from class: Rule
      Steps the grid provided forward one generation
      Overrides:
      step in class Rule
      Parameters:
      grid - The grid that will be stepped forward one generation
      cellsChanged - 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 rule
      generation - The current generation of the simulation
      step - 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