示例#1
0
        public static SimulationRule FromString(string str)
        {
            var regex = new Regex(@"^B(?<birth>[0-9]{0,9})/S(?<stay>[0-9]{0,9})$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
            var match = regex.Match(str);

            if (!match.Success) {
                throw new ArgumentException("Rule string is invalid.");
            }

            var rule = new SimulationRule();

            var birthChars = match.Groups["birth"].Value.ToCharArray();
            var stayAliveChars = match.Groups["stay"].Value.ToCharArray();

            foreach (var ch in birthChars) {
                rule.Birth[ch - '0'] = true;
            }

            foreach (var ch in stayAliveChars) {
                rule.StayAlive[ch - '0'] = true;
            }

            return rule;
        }
示例#2
0
 public static bool Simulate(World world, SimulationRule simulationRule)
 {
     return Simulate(world, simulationRule.RuleFunction);
 }