예제 #1
0
        public CellState? Get(NeighborhoodState pattern)
        {
            CellState result;

            if (Rules.TryGetValue(pattern, out result))
                return result;

            return null;
        }
예제 #2
0
        public static NeighborhoodState GetRandom()
        {
            byte[] bytes = Random.NextBytes(9);

            NeighborhoodState next = new NeighborhoodState(
                (byte)(bytes[0] % CellState.StateCount), (byte)(bytes[1] % CellState.StateCount), (byte)(bytes[2] % CellState.StateCount),
                (byte)(bytes[3] % CellState.StateCount), (byte)(bytes[4] % CellState.StateCount), (byte)(bytes[5] % CellState.StateCount),
                (byte)(bytes[6] % CellState.StateCount), (byte)(bytes[7] % CellState.StateCount), (byte)(bytes[8] % CellState.StateCount));

            if (2573485501887179 == next.Value)
                Console.WriteLine("HERE IS ONE");

            return next;
        }
예제 #3
0
        static void TestNumberOfStates()
        {
            Func<int, Tuple<int, int>> test = new Func<int, Tuple<int, int>>(m =>
            {
                int[] powers = Enumerable.Range(0, 10).Select(p => (int)Math.Pow(m, p)).ToArray();
                int states = powers[9];
                ISet<ulong> distinct = new HashSet<ulong>();
                for (int i = 0; i < states; i++)
                {
                    int state = i;

                    var ns = new NeighborhoodState(
                            (byte)((state % powers[0 + 1]) / powers[0]),
                            (byte)((state % powers[1 + 1]) / powers[1]),
                            (byte)((state % powers[2 + 1]) / powers[2]),
                            (byte)((state % powers[3 + 1]) / powers[3]),
                            (byte)((state % powers[4 + 1]) / powers[4]),
                            (byte)((state % powers[5 + 1]) / powers[5]),
                            (byte)((state % powers[6 + 1]) / powers[6]),
                            (byte)((state % powers[7 + 1]) / powers[7]),
                            (byte)((state % powers[8 + 1]) / powers[8])
                        );

                    distinct.Add(ns.Value);
                }
                return new Tuple<int, int>(states, distinct.Count);
            });

            Enumerable.Range(1, 7)
                .Select(test)
                .ToList()
                .ForEach(t => Console.Out.WriteLine("Expected: " + t.Item1 + "\tActual: " + t.Item2));
        }
예제 #4
0
 public void Remove(NeighborhoodState pattern)
 {
     if (Rules.ContainsKey(pattern))
         Rules.Remove(pattern);
 }