Ejemplo n.º 1
0
        private int CheckNeighbours(int x, int y)
        {
            var neighbours     = GetNeighbours(x, y);
            int neighbourCount = 0;

            foreach (var neighbour in neighbours)
            {
                if (CurrentGenCells.Contains(new Tuple <int, int>(neighbour.Item1, neighbour.Item2)))
                {
                    neighbourCount++;
                }
                else
                {
                    var currentNeighbour = new Tuple <int, int>(neighbour.Item1, neighbour.Item2);
                    int currentNeighbourCount;
                    if (PotentialCells.TryGetValue(currentNeighbour,
                                                   out currentNeighbourCount))
                    {
                        PotentialCells[currentNeighbour] += 1;
                    }
                    else
                    {
                        PotentialCells.Add(currentNeighbour, 1);
                    }
                }
            }
            return(neighbourCount);
        }
        public async Task Start(List <Cell> seed = null, int generation = 0)
        {
            CurrentGenCells.Clear();

            if (seed != null)
            {
                StartSeed = seed;
            }
            else
            {
                StartSeed = Seeds.RPentomino;
                //StartSeed.AddRange(Seeds.Stairs);
                //StartSeed.AddRange(Seeds.Toad);
                //StartSeed.AddRange(Seeds.RPentomino2);
                //StartSeed.AddRange(Seeds.Stairs2);
            }

            Generation = generation;

            foreach (var cell in StartSeed)
            {
                CurrentGenCells.Add(new Tuple <int, int>(cell.X, cell.Y));
            }

            Running = true;

            await Run();
        }