Class Rule

java.lang.Object
application.model.rules.Rule
Direct Known Subclasses:
RuleFamily

public abstract class Rule
extends java.lang.Object
Represents a single rule
  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected int alternatingPeriod
    Alternating period of the rule
    protected int[] background
    A list of backgrounds to be used for B0 rules.
    protected BoundedGrid boundedGrid
    Bounded grid used by the rule
    protected int numStates
    Number of states in the rule
    protected ReadingOrder readingOrder
    Naive reading order used by the rule
    protected Tiling tiling
    The tiling of the rule
  • Constructor Summary

    Constructors 
    Constructor Description
    Rule()  
  • Method Summary

    Modifier and Type Method Description
    int convertState​(int state, int generation)
    Convert the cell state based on the background Used to simulate B0 rules
    int dependsOnNeighbours​(int state, int generation, Coordinate coordinate)
    If the next state of the cell depends on its neighbours, return -1.
    int getAlternatingPeriod()
    Gets the alternating period of the rule
    BoundedGrid getBoundedGrid()
    Gets the bounded grid of the rule
    javafx.scene.paint.Color getColour​(int state)
    Returns the colour of a cell of the provided state
    java.lang.String getName​(int state)
    Returns the name of the provided state
    Coordinate[] getNeighbourhood()
    This method returns the neighbourhood of a given cell at a generation 0
    abstract Coordinate[] getNeighbourhood​(int generation)
    This method returns the neighbourhood of a given cell at a certain generation
    int getNumStates()
    Gets the number of states in the rule
    Tiling getTiling()
    Returns the tiling of the rule (Square, Hexagonal or Triangular)
    void setBackground​(int[] background)
    Sets the background of the rule
    void setBoundedGrid​(BoundedGrid boundedGrid)
    Sets the bounded grid of the rule
    void setReadingOrder​(ReadingOrder order)
    Sets the naive reading order of the rule
    void step​(Grid grid, java.util.ArrayList<java.util.Set<Coordinate>> cellsChanged, int generation, java.util.function.Function<Coordinate,​java.lang.Boolean> step)
    Steps the grid provided forward one generation
    abstract int transitionFunc​(int[] neighbours, int cellState, int generations, Coordinate coordinate)
    This method represents the transition function of the rule

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • background

      protected int[] background
      A list of backgrounds to be used for B0 rules. Example: A 3-state generations B0 rule without Smax would have a background of {0, 1, 2}. A non-B0 rule would have a background of {0}.
    • numStates

      protected int numStates
      Number of states in the rule
    • alternatingPeriod

      protected int alternatingPeriod
      Alternating period of the rule
    • tiling

      protected Tiling tiling
      The tiling of the rule
    • boundedGrid

      protected BoundedGrid boundedGrid
      Bounded grid used by the rule
    • readingOrder

      protected ReadingOrder readingOrder
      Naive reading order used by the rule
  • Constructor Details

    • Rule

      public Rule()
  • Method Details

    • getNeighbourhood

      public Coordinate[] getNeighbourhood()
      This method returns the neighbourhood of a given cell at a generation 0
      Returns:
      A list of Coordinates that represent the neighbourhood
    • getNeighbourhood

      public abstract Coordinate[] getNeighbourhood​(int generation)
      This method returns the neighbourhood of a given cell at a certain generation
      Parameters:
      generation - The generation of the simulation
      Returns:
      A list of Coordinates that represent the neighbourhood
    • transitionFunc

      public abstract int transitionFunc​(int[] neighbours, int cellState, int generations, Coordinate coordinate)
      This method represents the transition function of the 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
    • dependsOnNeighbours

      public int dependsOnNeighbours​(int state, int generation, Coordinate coordinate)
      If the next state of the cell depends on its neighbours, return -1. If not return the next state of the cell.
      Parameters:
      state - The current state of the cell
      generation - The generation of the simulation
      coordinate - The coordinate of the cell
      Returns:
      Returns -1 or the next state of the cell
    • getAlternatingPeriod

      public int getAlternatingPeriod()
      Gets the alternating period of the rule
      Returns:
      Returns the rule's alternating period
    • getNumStates

      public int getNumStates()
      Gets the number of states in the rule
      Returns:
      Returns the number of states in the rule
    • getColour

      public javafx.scene.paint.Color getColour​(int state)
      Returns the colour of a cell of the provided state
      Parameters:
      state - The state of the cell
      Returns:
      The colour of the cell
    • getName

      public java.lang.String getName​(int state)
      Returns the name of the provided state
      Parameters:
      state - The state of the cell
      Returns:
      The name of the state
    • getTiling

      public Tiling getTiling()
      Returns the tiling of the rule (Square, Hexagonal or Triangular)
      Returns:
      Returns the rule's tiling
    • getBoundedGrid

      public BoundedGrid getBoundedGrid()
      Gets the bounded grid of the rule
      Returns:
      Returns the bounded grid of the rule
    • 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
      Steps the grid provided forward one generation
      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
    • convertState

      public int convertState​(int state, int generation)
      Convert the cell state based on the background Used to simulate B0 rules
      Parameters:
      state - The current state of the cell
      generation - The generation of the simulation
      Returns:
      Returns the new cell state
    • setBackground

      public void setBackground​(int[] background)
      Sets the background of the rule
      Parameters:
      background - The background of the rule
    • setBoundedGrid

      public void setBoundedGrid​(BoundedGrid boundedGrid)
      Sets the bounded grid of the rule
      Parameters:
      boundedGrid - The bounded grid of the rule
    • setReadingOrder

      public void setReadingOrder​(ReadingOrder order)
      Sets the naive reading order of the rule
      Parameters:
      order - The naive reading order the rule should use