Class CA2DBinaryRule
A transition rule for discrete binary deterministic 2D cellular automata.
public class CA2DBinaryRule : ICA2DRule
- Inheritance
-
CA2DBinaryRule
- Implements
- Inherited Members
Remarks
A rule is defined as a string as follows:
<N,R/{values-for-survival}/{values-for-birth}>
Where:
N
represents the neighborhood type (M
for Moore,V
for Von Neumann,H
for Hexagonal).R
indicates the radius of the neighborhood.{values-for-survival}
and{values-for-birth}
are comma-separated lists where values can be individual numbers or ranges denoted by a start and end number separated by a hyphen (-
). A hyphen at the start or end indicates a range extending from zero or up to the maximum possible number of neighbors, respectively.
Examples:
M,1/2-5/3,6-8
- Neighborhood: Moore
- Radius: 1
- Survival: A cell survives if it has between 2 and 5 live neighbors.
- Birth: A cell is born if it has exactly 3 live neighbors or between 6 and 8 live neighbors.
V,2/-/1-4
- Neighborhood: Von Neumann
- Radius: 2
- Survival: No specific survival rules; the hyphen implies all possibilities are valid, so live cells will always survive.
- Birth: A cell is born if it has between 1 and 4 live neighbors.
H,3/0,2,4-6/10-
- Neighborhood: Hexagonal
- Radius: 3
- Survival: A cell survives if it has 0, 2, or between 4 and 6 live neighbors.
- Birth: Cells are born if they have 10 or more live neighbors.
M,2/1,10-/-3,7-9
- Neighborhood: Moore
- Radius: 2
- Survival: A cell survives if it has exactly 1 live neighbor or more than 10 live neighbors.
- Birth: A cell is born if it has between 0 and 3 live neighbors or between live 7 and 9 neighbors.
Constructors
CA2DBinaryRule(string)
Create a new transition rule defined in the given string.
public CA2DBinaryRule(string ruleString)
Parameters
ruleString
stringA string defining the rule.
Properties
BirthRules
Birth rules.
public ISet<int> BirthRules { get; }
Property Value
NeighborhoodType
Neighborhood type.
public Neighborhood NeighborhoodType { get; }
Property Value
Radius
Neighborhood radius.
public int Radius { get; }
Property Value
SurvivalRules
Survival rules.
public ISet<int> SurvivalRules { get; }
Property Value
Methods
ProcessRule(CA2D, int, int)
Process the specified CA cell with this rule.
public int ProcessRule(CA2D ca, int x, int y)
Parameters
Returns
- int
New value for the specified CA cell after applying this rule.