Example #1
0
        public bool getTransition(int i, int j, CAState cas)
        {
            int neighbors = (cas.getValue(i - 1, j - 1)? 1: 0) +
                            (cas.getValue(i - 1, j)? 1: 0) +
                            (cas.getValue(i - 1, j + 1)? 1: 0) +
                            (cas.getValue(i, j - 1)? 1: 0) +
                            (cas.getValue(i, j + 1)? 1: 0) +
                            (cas.getValue(i + 1, j - 1)? 1: 0) +
                            (cas.getValue(i + 1, j)? 1: 0) +
                            (cas.getValue(i + 1, j + 1)? 1: 0);

            if (cas.getValue(i, j))
            {
                if (neighbors < 2 || neighbors > 3)
                {
                    return(false);
                }
                return(true);
            }
            else if (neighbors == 3)
            {
                return(true);
            }
            return(false);
        }
Example #2
0
        // simple breeding model - randomly choose each cell from either A or B
        private CAState breed(CAState a, CAState b, Random rng)
        {
            CAState c = new CAState(a);

            for (int i = 0; i < c.Width; ++i)
            {
                for (int j = 0; j < c.Height; ++j)
                {
                    if (rng.Next() % 2 == 0)
                    {
                        c.setValue(i, j, a.getValue(i, j));
                    }
                    else
                    {
                        c.setValue(i, j, b.getValue(i, j));
                    }
                }
            }
            return(c);
        }