Example #1
0
        static void Main(string[] args)
        {
            Cell[] cells = null;
            PrintInstructions();
            if (!string.IsNullOrWhiteSpace(GetUserInput(ref cells)))
            {

                Game grid = new Game(4, 4);
                SetAliveValue(cells,grid);

                IGameOfLife gameOfLife = GetGameOfLifeController(grid);

                PrintCellCurrentState(grid);

                for (int hitCount = 0; hitCount < 10; hitCount++)
                {
                    Console.WriteLine("Press to enter to next generation");
                    Console.ReadLine();
                    gameOfLife.Evolve();
                    PrintCellCurrentState(grid);
                }

                Console.WriteLine("Press enter to exit");
                Console.ReadLine();
            }
        }
Example #2
0
        private static IGameOfLife GetGameOfLifeController(Game grid)
        {
            // Create the neighbourhood rule
            INeighbourRuleFactory neighbourRuleFactory = new NeighbourRuleFactory();

            // Create the rule
            IRuleFactory ruleFactory = new RuleFactory();

            IGameOfLife gameofLifeobject = new GameOfLife(grid, ruleFactory, neighbourRuleFactory);
            return gameofLifeobject;
        }
Example #3
0
        private static void PrintCellCurrentState(Game grid)
        {
            int rownumber = 0;
            for (int count = 0; count < grid.RowCount; count++ )
            {
                for(int colCount = 0; colCount < grid.ColumnCount ; colCount++)
                {
                    if (rownumber != grid[count,colCount].RowNumber)
                    {
                        rownumber++;
                        Console.WriteLine();
                    }

                    Console.Write("{0}\t", grid[count, colCount].IsAlive ? "Live" : "Dead");
                }
            }
            Console.WriteLine();
        }
Example #4
0
 private static void SetAliveValue(Cell[] cells, Game grid)
 {
     // Initialize with values got as user input.
     foreach (Cell cell in cells)
     {
         grid[cell.RowNumber, cell.ColNumber].IsAlive = true;
     }
 }
 /// <summary>
 /// To find neighbours of pass cell in optimized way, the rule must be self aware of strucutre in which it's contained.
 /// </summary>
 /// <param name="grid"></param>
 public MatrixNeighbourCellRule(Game grid)
 {
     this.grid = grid;
 }