public bool TestIsCellIndexValid(int x, int y)
        {
            CartesianGrid grid = new CartesianGrid(10, 10);

            CartesianGridLogic gridLogic = new CartesianGridLogic(grid);

            return gridLogic.IsCellIndexValid(x, y);
        }
        public bool TestIsNeighborAlive(int x, int y)
        {
            CartesianGridCell gridCell = new CartesianGridCell(1, 1);

            CartesianGrid grid = new CartesianGrid(FourNeighborsGrid);

            CartesianGridLogic gridLogic = new CartesianGridLogic(grid);

            return gridLogic.IsNeighborAlive(gridCell, x, y);
        }
        public int TestNumberOfLiveNeighbors(int x, int y)
        {
            string[] lines = File.ReadAllLines("../../smallexploder.txt");

            CartesianGrid cartesianGrid = new CartesianGrid(lines);

            CartesianGridLogic cartesianGridLogic = new CartesianGridLogic(cartesianGrid);

            return cartesianGridLogic.NumberOfLiveNeighbors(cartesianGrid.Map[x][y]);
        }
        public void NextGeneration()
        {
            CartesianGridCell[][] emptyMap = new CartesianGrid(Width, Height).Map;

            CartesianGridLogic cartesianGridLogic = new CartesianGridLogic(this);

            for (int w = 0; w < Width; w++)
            {
                for (int h = 0; h < Height; h++)
                {
                    emptyMap[w][h].IsAlive = CellLogic.DetermineIfCellLives(Map[w][h], cartesianGridLogic.NumberOfLiveNeighbors(Map[w][h]));
                }
            }

            Map = emptyMap;
        }
Пример #5
0
        public static void Main(string[] args)
        {
            string[] lines = File.ReadAllLines(args[0]);

            CartesianGrid cartesianGrid = new CartesianGrid(lines);

            Console.WriteLine("Starting grid, press \"Y\" to view next generation");
            Console.WriteLine(cartesianGrid.ToString());

            while (Console.ReadLine() == "y")
            {
                cartesianGrid.NextGeneration();

                Console.WriteLine(cartesianGrid.ToString());
                Console.WriteLine("Press \"Y\" to view next generation");
            }
        }
        public void TestNextGeneration(int numberOfGenerations, string startFile, string endFile)
        {
            string[] startLines = File.ReadAllLines(startFile);
            string[] endLines = File.ReadAllLines(endFile);

            CartesianGrid cartesianGrid = new CartesianGrid(startLines);
            CartesianGrid cartesianGridFinal = new CartesianGrid(endLines);

            for (int i = 0; i < numberOfGenerations; i++)
            {
                cartesianGrid.NextGeneration();

                Console.WriteLine(cartesianGrid.ToString());
            }

            Assert.AreEqual(cartesianGridFinal.ToString(), cartesianGrid.ToString());
        }
        public void TestNumberOfLiveNeighbors(string[] testArray, int expectedLiveNeighbors)
        {
            CartesianGrid grid = new CartesianGrid(testArray);

            CartesianGridLogic gridLogic = new CartesianGridLogic(grid);

            int liveNeighbors = gridLogic.NumberOfLiveNeighbors(grid.Map[1][1]);

            Assert.AreEqual(liveNeighbors, expectedLiveNeighbors);
        }
        public int TestGenerateGrid(int width, int height)
        {
            CartesianGrid cartesianGrid = new CartesianGrid(width, height);

            return cartesianGrid.Map.GetLength(0) * cartesianGrid.Map[0].GetLength(0);
        }