public void CountLivingNeighborsWorking()
 {
     GameOfLife test = new GameOfLife(3, 3);
     test.grid[0, 0] = true;
     test.grid[1, 0] = true;
     Assert.AreEqual(2, test.CountLivingNeighbors(1, 1));
 }
 public void Rule1()
 {
     GameOfLife game = new GameOfLife(3, 3);
     game.grid[1, 1] = true;
     game.Tick();
     Assert.IsFalse(game.grid[1, 1]);
 }
 public void TickTestLoafFormation()
 {
     GameOfLife ATestGrid = new GameOfLife(6, 6);
     ATestGrid[1, 2] = true;
     ATestGrid[1, 3] = true;
     ATestGrid[2, 1] = true;
     ATestGrid[2, 4] = true;
     ATestGrid[3, 2] = true;
     ATestGrid[3, 4] = true;
     ATestGrid[4, 3] = true;
     GameOfLife ATestGridToTick = new GameOfLife(6, 6);
     ATestGridToTick[1, 2] = true;
     ATestGridToTick[1, 3] = true;
     ATestGridToTick[2, 1] = true;
     ATestGridToTick[2, 4] = true;
     ATestGridToTick[3, 2] = true;
     ATestGridToTick[3, 4] = true;
     ATestGridToTick[4, 3] = true;
     ATestGridToTick.Tick();
     CollectionAssert.AreEqual(ATestGrid.ToList()[0], ATestGridToTick.ToList()[0]);
     CollectionAssert.AreEqual(ATestGrid.ToList()[1], ATestGridToTick.ToList()[1]);
     CollectionAssert.AreEqual(ATestGrid.ToList()[2], ATestGridToTick.ToList()[2]);
     CollectionAssert.AreEqual(ATestGrid.ToList()[3], ATestGridToTick.ToList()[3]);
     CollectionAssert.AreEqual(ATestGrid.ToList()[4], ATestGridToTick.ToList()[4]);
     CollectionAssert.AreEqual(ATestGrid.ToList()[5], ATestGridToTick.ToList()[5]);
 }
 public void EdgeCase()
 {
     GameOfLife game = new GameOfLife(3, 3);
     Assert.IsTrue(game.IsEdge(0,0));
     Assert.IsTrue(game.IsEdge(2, 2));
     Assert.IsTrue(game.IsEdge(0, 2));
     Assert.IsTrue(game.IsEdge(2, 0));
 }
 //rule 3 - Any live cell with more than three live neighbours
 //dies.
 public void OverPopulationTest()
 {
     GameOfLife test = new GameOfLife(3, 3);
     test.grid[1, 1] = true;
     test.grid[0, 0] = true;
     test.grid[1, 0] = true;
     test.grid[2, 0] = true;
     test.grid[2, 1] = true;
     Assert.IsFalse(test.OverPopulation(1, 1));
 }
 //rule 2 - Any live cell with two or three live neighbours 
 //lives.
 public void RemainAliveTest()
 {
     GameOfLife test = new GameOfLife(3, 3);
     test.grid[1, 1] = true;
     test.grid[1, 0] = true;
     test.grid[2, 0] = true;
     Assert.IsTrue(test.RemainAlive(1, 1));
     //another way of testing the same thing
     Assert.AreEqual(test.grid[1, 1], test.RemainAlive(1, 1));
 }
 public void Blinker()
 {
     GameOfLife game = new GameOfLife(5, 5);
     game.grid[1, 2] = true;
     game.grid[2, 2] = true;
     game.grid[3, 2] = true;
     game.Tick();
     Assert.IsFalse(game.grid[1, 2]);
     Assert.IsFalse(game.grid[3, 2]);
     Assert.IsTrue(game.grid[2, 2]);
 }
 public void TickTestRuleFourDeadCellWithFourLiveNeighbors()
 {
     GameOfLife ATestGridToTick = new GameOfLife(5, 3);
     ATestGridToTick[2, 1] = true;
     ATestGridToTick[2, 2] = true;
     ATestGridToTick[3, 1] = false;
     ATestGridToTick[4, 0] = true;
     ATestGridToTick[4, 1] = true;
     Assert.AreEqual(false, ATestGridToTick[3, 1]);
     ATestGridToTick.Tick();
     Assert.AreEqual(false, ATestGridToTick[3, 1]);
 }
Exemplo n.º 9
0
        public void When_Game_Ticks_State_Changes()
        {
            var initialBoard = new int[10, 10];

            initialBoard[5, 5] = 1;

            var game = new GameOfLife(initialBoard);

            var newBoard = game.Tick();

            Assert.Equal(0, newBoard[5, 5]);
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            var input = "";

            GameOfLife game = new GameOfLife(new TextFileReader(), new OutputWriter());

            while (input != "q")
            {
                input = Console.ReadLine();
                game.Step();
            }
        }
Exemplo n.º 11
0
        public MainWindow()
        {
            GameOfLife arrayBoard = new GameOfLife(25, 25);
            arrayBoard.RandomizeStartPattern();
            currentBoard = arrayBoard;
            dispatcherTimer = new DispatcherTimer();

            InitializeComponent();

            TheListView.ItemsSource = currentBoard.ToList();
            dispatcherTimer.Tick += dispatcherTimerClick;
            dispatcherTimer.Interval = TimeSpan.FromSeconds((double)RunSpeed.Value);
        }
Exemplo n.º 12
0
        public void When_Cell_Has_Two_Living_Neighbour_Cell_Stays_Alive()
        {
            var initialBoard = new int[10, 10];

            initialBoard[5, 5] = 1;
            initialBoard[5, 6] = 1;
            initialBoard[6, 6] = 1;

            var game     = new GameOfLife(initialBoard);
            var newBoard = game.Tick();

            Assert.Equal(1, newBoard[5, 5]);
            Assert.Equal(1, newBoard[5, 6]);
            Assert.Equal(1, newBoard[6, 6]);
            Assert.Equal(3, game.CountAlive());
        }
 public void TickTestBlinkerFormation()
 {
     GameOfLife ATestGrid = new GameOfLife(5, 5);
     ATestGrid[1, 2] = true;
     ATestGrid[2, 2] = true;
     ATestGrid[3, 2] = true;
     GameOfLife ATestGridToTick = new GameOfLife(5, 5);
     ATestGridToTick[2, 1] = true;
     ATestGridToTick[2, 2] = true;
     ATestGridToTick[2, 3] = true;
     ATestGridToTick.Tick();
     CollectionAssert.AreEqual(ATestGrid.ToList()[0], ATestGridToTick.ToList()[0]);
     CollectionAssert.AreEqual(ATestGrid.ToList()[1], ATestGridToTick.ToList()[1]);
     CollectionAssert.AreEqual(ATestGrid.ToList()[2], ATestGridToTick.ToList()[2]);
     CollectionAssert.AreEqual(ATestGrid.ToList()[3], ATestGridToTick.ToList()[3]);
     CollectionAssert.AreEqual(ATestGrid.ToList()[4], ATestGridToTick.ToList()[4]);
 }
Exemplo n.º 14
0
        private static void Main()
        {
            Console.Title           = "Conway's Game of Life";
            Console.OutputEncoding  = Encoding.Unicode;
            Console.CursorVisible   = false;
            Console.WindowWidth     = 90;
            Console.BufferWidth     = 90;
            Console.WindowHeight    = 40;
            Console.BufferHeight    = 40;
            Console.BackgroundColor = ConsoleColor.Gray;
            Console.Clear();
            Console.ForegroundColor = ConsoleColor.Black;

            var userConfig = UserConfig.UserInput();
            var gameOfLife = new GameOfLife(userConfig);

            gameOfLife.Initialise();
            gameOfLife.Run();
        }
Exemplo n.º 15
0
        static void Main(string[] args)
        {
            int runs = 0;
            int height, width, maxRuns;

            // Get the INput Values
            Console.Write("Enter Board Height : ");
            int.TryParse(Console.ReadLine(), out height);

            Console.Write("Enter Board Width : ");
            int.TryParse(Console.ReadLine(), out width);

            Console.Write("Enter Number of Generation : ");
            int.TryParse(Console.ReadLine(), out maxRuns);

            // Validate the values and if values are not int, then exit from program
            if (height == 0 || width == 0 || maxRuns == 0)
            {
                Console.Write("Value for Height, Width and NUmbe of Generation must be greater then 0");
                Console.ReadLine();
                return;
            }
            // Display a message for  Board
            GameOfLife gm = new GameOfLife(height, width);

            Console.WriteLine("\r");
            Console.Write("Generating a Bord of {0} X {1}, will run for {2}", height.ToString(), width.ToString(), maxRuns.ToString());
            Console.WriteLine("\r");
            // Run the Program
            while (runs++ < maxRuns)
            {
                gm.StartGame();
                System.Threading.Thread.Sleep(1000);
            }

            Console.ReadKey();
        }
Exemplo n.º 16
0
        /*
         *  This example will use the concept of Conway's Game of Life to create sound.
         *  The sound will be made using MIDI Gremlin.
         */
        private static void Main(string[] args)
        {
            bool[,] grid = new bool[40, 40];
            // Setup some start values

            // Glider 1 : depicted as followed
            // 0 1 0
            // 0 0 1
            // 1 1 1
            grid[2, 1] = true;
            grid[3, 2] = true;
            grid[3, 3] = true;
            grid[2, 3] = true;
            grid[1, 3] = true;

            // Glider 2
            // 1 1 1
            // 0 0 1
            // 0 1 0
            grid[12, 13] = true;
            grid[11, 11] = true;
            grid[12, 11] = true;
            grid[13, 11] = true;
            grid[13, 12] = true;


            // Start The Game of Life
            GameOfLife gol = new GameOfLife(grid);

            // Start Drawing
            gol.IsDrawing = true;

            // Play sounds using the Game of Life
            gol.MusicSetup();

            Console.ReadKey();
        }
Exemplo n.º 17
0
 public void Toad()
 {
     GameOfLife game = new GameOfLife(6, 6);
     game.grid[2, 2] = true;
     game.grid[2, 3] = true;
     game.grid[2, 4] = true;
     game.grid[3, 1] = true;
     game.grid[3, 2] = true;
     game.grid[3, 3] = true;
     game.Tick();
     Assert.IsFalse(game.grid[2, 2]);
     Assert.IsFalse(game.grid[2, 3]);
     Assert.IsFalse(game.grid[3, 2]);
     Assert.IsFalse(game.grid[3, 3]);
     Assert.IsTrue(game.grid[1, 3]);
     Assert.IsTrue(game.grid[2, 1]);
     Assert.IsTrue(game.grid[2, 4]);
     Assert.IsTrue(game.grid[3, 1]);
     Assert.IsTrue(game.grid[3, 4]);
     Assert.IsTrue(game.grid[4, 2]);
 }
Exemplo n.º 18
0
 static void Main()
 {
     using (var game = new GameOfLife())
         game.Run();
 }
Exemplo n.º 19
0
        public void CreateNewGridGetCellValue()
        {
            GameOfLife ATestGrid = new GameOfLife(5, 5);

            Assert.AreEqual(false, ATestGrid[0, 0]);
        }
Exemplo n.º 20
0
 public void CreateNewGrid()
 {
     GameOfLife ATestGrid = new GameOfLife(5, 5);
     Assert.AreEqual(25, ATestGrid.cells.Length);
 }
Exemplo n.º 21
0
 public void CreateNewGridSetCellValue()
 {
     GameOfLife ATestGrid = new GameOfLife(5, 5);
     ATestGrid[2, 2] = true;
     Assert.AreEqual(true, ATestGrid[2, 2]);
 }
Exemplo n.º 22
0
 public void CountNeighbors()
 {
     GameOfLife game = new GameOfLife(3, 3);
     game.grid[0, 0] = true;
     Assert.AreEqual(1, game.GetAliveNeighbors(1, 1));
 }
Exemplo n.º 23
0
 public void CellsCanChangeState()
 {
     GameOfLife game = new GameOfLife(3, 3);
     game.grid[1, 1] = true;
     Assert.IsTrue(game.grid[1, 1]);
 }
Exemplo n.º 24
0
 public void ToListWith1x1Grid()
 {
     GameOfLife ATestGrid = new GameOfLife(1, 1);
     List<bool> ATestList = new List<bool> { false };
     List<List<bool>> ATestListOfLists = new List<List<bool>>();
     ATestListOfLists.Add(ATestList);
     CollectionAssert.AreEquivalent(ATestListOfLists[0], ATestGrid.ToList()[0]);
 }
Exemplo n.º 25
0
 public void RemoveOffGridNeighborsWithPositiveCoordinatesInRectangularGrid()
 {
     GameOfLife ATestGrid = new GameOfLife(8, 5);
     Cell ACornerCell = ATestGrid.cells[7, 4];
     Assert.AreEqual(3, ACornerCell.Neighbors.Count);
 }
Exemplo n.º 26
0
        public static void Main()
        {
            int boardSize, numberOfGenerations;

            Console.WriteLine("!!! Welcome to Conway's Game of Life !!!\n");

            // Get the board size
            Console.WriteLine("Please enter a number for the boardsize. (It will determine the board size, e.g. 5 generates a 5x5 board):");
            var input = Console.ReadLine();

            while (!int.TryParse(input, out boardSize))
            {
                Console.WriteLine("Invalid input. Please enter a number.");
                input = Console.ReadLine();
            }

            // Get the number of generations
            Console.WriteLine("Please enter the number of generations for the simulation:");
            input = Console.ReadLine();
            while (!int.TryParse(input, out numberOfGenerations))
            {
                Console.WriteLine("Invalid input. Please enter a number.");
                input = Console.ReadLine();
            }

            // Pad the board with dead cells so that we don't try iterate out of bounds
            var paddedBoardSize = boardSize + 2;

            // Initialise the board and set the initial state
            var gameOfLife = new GameOfLife(paddedBoardSize, numberOfGenerations);

            gameOfLife.RandomiseCellsToInitialiseBoard();

            // Display the initial state of the board
            Console.WriteLine("\nInitial State:");
            gameOfLife.PrintBoard();

            // Run and display each tick (generation) of the simulation
            var generation = 0;

            while (generation < gameOfLife.NumberOfGenerations)
            {
                // The simulation will end earlier than the specified number of generations provided if all the cells are dead.
                if (gameOfLife.CountLivingCellsOnBoard() == 0)
                {
                    Console.WriteLine("The simulation has ended because all cells have died.");
                    break;
                }
                else
                {
                    gameOfLife.Tick();
                    Console.WriteLine($"\nGeneration: {generation + 1}");
                    gameOfLife.PrintBoard();
                    generation++;
                    Thread.Sleep(1000);
                }
            }

            Console.WriteLine("\nPress any key to quit.");
            Console.ReadKey();
        }
Exemplo n.º 27
0
 public UnitTest1(ITestOutputHelper log)
 {
     _logger = log;
     _game   = GameOfLife.Create(size: 10);
     _board  = _game.Display();
 }
Exemplo n.º 28
0
 public void GameExists()
 {
     GameOfLife game = new GameOfLife();
     Assert.IsNotNull(game);
 }
Exemplo n.º 29
0
 public void CreateNewGridSetCellValueOtherCellsRetainValue()
 {
     GameOfLife ATestGrid = new GameOfLife(5, 5);
     ATestGrid[2, 2] = true;
     Assert.AreEqual(false, ATestGrid[2, 3]);
 }
Exemplo n.º 30
0
 public void CanCreateGrids()
 {
     GameOfLife game = new GameOfLife(3, 3);
     Assert.AreEqual(9, game.grid.Length);
 }
Exemplo n.º 31
0
 public void ToListWith3x3Grid()
 {
     GameOfLife ATestGrid = new GameOfLife(3, 3);
     List<bool> ATestList = new List<bool>(new bool[] { false, false, false });
     List<List<bool>> ATestListOfLists = new List<List<bool>>();
     ATestListOfLists.Add(ATestList);
     ATestListOfLists.Add(ATestList);
     ATestListOfLists.Add(ATestList);
     CollectionAssert.AreEquivalent(ATestListOfLists[0], ATestGrid.ToList()[0]);
     CollectionAssert.AreEquivalent(ATestListOfLists[1], ATestGrid.ToList()[1]);
     CollectionAssert.AreEquivalent(ATestListOfLists[2], ATestGrid.ToList()[2]);
 }
Exemplo n.º 32
0
 public void CellsStartDead()
 {
     GameOfLife game = new GameOfLife(3, 3);
     Assert.IsFalse(game.grid[1,1]);
 }
Exemplo n.º 33
0
 public void ToListWithEmptyGrid()
 {
     GameOfLife ATestGrid = new GameOfLife(0, 0);
     List<List<bool>> ATestListOfLists = new List<List<bool>>();
     CollectionAssert.AreEqual(ATestListOfLists, ATestGrid.ToList());
 }
Exemplo n.º 34
0
 public void RemoveOffGridNeighborsRectangularGridInnerCell()
 {
     GameOfLife ATestGrid = new GameOfLife(8, 5);
     Cell AnInnerCell = ATestGrid.cells[2, 3];
     Assert.AreEqual(8, AnInnerCell.Neighbors.Count);
 }
Exemplo n.º 35
0
 public void CreateNewEmptyGrid()
 {
     GameOfLife ATestGrid = new GameOfLife(0, 0);
     var ThisWillFail = ATestGrid[0, 0];
 }
Exemplo n.º 36
0
 public void GameWithArgumentsExists()
 {
     GameOfLife game = new GameOfLife(2, 2);
     Assert.IsNotNull(game);
 }
Exemplo n.º 37
0
 public void RemoveOffGridNeighborsWithNegativeCoordinates()
 {
     GameOfLife ATestGrid = new GameOfLife(5, 5);
     Cell ACornerCell = ATestGrid.cells[0, 0];
     Assert.AreEqual(3, ACornerCell.Neighbors.Count);
 }
Exemplo n.º 38
0
 public void Rule1OnLargerBoard()
 {
     GameOfLife game = new GameOfLife(8, 8);
     game.grid[1, 1] = true;
     game.grid[5, 5] = true;
     game.Tick();
     Assert.IsFalse(game.grid[1, 1]);
     Assert.IsFalse(game.grid[5, 5]);
 }
Exemplo n.º 39
0
 public void RemoveOffGridNeighborsWithOneCellGrid()
 {
     GameOfLife ATestGrid = new GameOfLife(1, 1);
     Cell TheOnlyCell = ATestGrid.cells[0, 0];
     Assert.AreEqual(0, TheOnlyCell.Neighbors.Count);
 }