Ejemplo n.º 1
0
        private static Generation GetGenerationZero(GridSize gridSize)
        {
            Console.WriteLine("Enter Generation Zero");

            Generation generationZero = new Generation();

            for (int x = 0; x < gridSize.Rows; x++)
            {
                string userInput = Console.ReadLine();

                if (userInput.Length != gridSize.Columns)
                {
                    Console.WriteLine("Incorrect columns parts");
                    return(null);
                }

                for (int y = 0; y < userInput.Length; y++)
                {
                    int intValue;

                    if (!int.TryParse(userInput[y].ToString(), out intValue))
                    {
                        Console.WriteLine("Incorrect column value " + userInput[y]);
                        return(null);
                    }

                    if (intValue < 0 && intValue > 1)
                    {
                        Console.WriteLine("Incorrect column value " + userInput[y]);
                        return(null);
                    }

                    GridPoint point = new GridPoint();
                    point.X     = x;
                    point.Y     = y;
                    point.Value = intValue;


                    generationZero.Points.Add(point);
                }
            }
            return(generationZero);
        }
Ejemplo n.º 2
0
        private static Generation GetNextGeneration(Generation generation)
        {
            Generation nextGeneration = new Generation();

            for (int i = 0; i < generation.Points.Count; i++)
            {
                GridPoint point = generation.Points[i];

                GridPoint newPoint = new GridPoint();

                newPoint.X = point.X;

                newPoint.Y = point.Y;

                newPoint.Value = GetNewPointValue(generation, point);

                nextGeneration.Points.Add(newPoint);
            }
            return(nextGeneration);
        }