Esempio n. 1
0
        public void Step()
        {
            var result   = new List <bool>();
            var maxIndex = Plants.Count;

            for (int i = -2; i < Plants.Count + 2; i++)
            {
                var change = false;
                foreach (var rule in Rules)
                {
                    if (rule.Match(Plants, i))
                    {
                        change = rule.Pattern[5] ^ Plants.ElementAtOrDefault(i);
                    }
                }

                if (change && i < 0)
                {
                    FirstIndex += i;
                    result.Add(Plants.ElementAtOrDefault(i) ^ change);
                }
                else if (i >= 0)
                {
                    result.Add(Plants.ElementAtOrDefault(i) ^ change);
                }
            }

            // Trim the end
            while (true)
            {
                if (!result.Last())
                {
                    result.RemoveAt(result.Count - 1);
                }
                else
                {
                    break;
                }
            }
            Plants = result;
        }