Exemplo n.º 1
0
        //function that is not working yet for filling the grid according to the user input
        public static BuildGrid GridValues(int[] dimensions)
        {
            BuildGrid grid = new BuildGrid(dimensions[0], dimensions[1]);

            for (int i = 0; i < grid.HeightY; i++)
            {
                string line = Console.ReadLine().Trim();
                var    row  = Array.ConvertAll(line.Split(' '), int.Parse);
                for (int j = 0; j < grid.WidthX; j++)
                {
                    grid.Cells[i, j] = new Cell(row[j]);
                }
            }
            return(grid);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            int width, height, targetX, targetY;
            int counter      = 0;
            int counterGreen = 0;

            try
            {
                int[] size = Input.GridDimensions();
                // BuildGrid initialGrid = Input.GridValues(size);
                height             = size[0];
                width              = size[1];
                int[,] initialGrid = new int[height, width];
                //filling the initial grid with user input
                for (int i = 0; i < height; i++)
                {
                    string line = Console.ReadLine().Trim();
                    var    row  = Array.ConvertAll(line.Split(' '), int.Parse);

                    for (int j = 0; j < width; j++)
                    {
                        initialGrid[i, j] = row[j];
                    }
                }

                Cell targetCell = Input.TargetCoordinates(out int generetionN);
                targetX = targetCell.X;
                targetY = targetCell.Y;
                ValidateGridCoordinates(initialGrid, targetX, targetY);
                //creating a new grid with the same values
                var nextGen = new int[height, width];
                nextGen = initialGrid;
                //rebuilding the grid N times
                do
                {
                    //checks if the current cell is "green"
                    if (nextGen[targetX, targetY] == 1)
                    {
                        ++counterGreen;
                    }
                    nextGen = BuildGrid.Rebuild(nextGen, height, width);
                    //prints the grid to the console
                    for (int i = 0; i < nextGen.GetLength(0); i++)
                    {
                        for (int j = 0; j < nextGen.GetLength(1); j++)
                        {
                            Console.Write(nextGen[i, j] + " ");
                        }
                        Console.WriteLine();
                    }
                    Console.WriteLine();
                    counter++;
                } while (counter <= generetionN);
                Console.WriteLine("The result is: " + counterGreen);
            }
            catch (Exception)
            {
                Console.WriteLine("Some error occured.");
            }
            Console.Read();
        }
Exemplo n.º 3
0
 public BuildGrid(BuildGrid grid)
 {
     this.Cells   = grid.Cells.Clone() as Cell[, ];
     this.HeightY = grid.HeightY;
     this.WidthX  = grid.WidthX;
 }