Exemplo n.º 1
0
        public void Output(World world)
        {
            var numberOfCells = world.Rows.First().Cells.Count();

            PrintNumbers(numberOfCells);

            var rowCounter = 0;
            foreach (var row in world.Rows)
            {
                PrintBorder(numberOfCells);

                Console.Write("{0}|", rowCounter);
                foreach (var cell in row.Cells)
                {
                    cell.Print(c => Console.Write(string.Format(" {0} |", c)));
                }

                rowCounter++;
                Console.WriteLine();
            }

            PrintBorder(numberOfCells);

            Console.WriteLine();
        }
Exemplo n.º 2
0
 public void Apply(World world)
 {
     foreach (var row in world.Rows)
     {
         ApplyRule(world, row);
     }
 }
Exemplo n.º 3
0
        public World Build()
        {
            var world = new World();
            foreach (var row in loader.Read())
            {
                world.AddRow();

                foreach (var cell in row.GetCells())
                {
                    world.AddCell(cell.Alive);
                }
            }

            return world;
        }
Exemplo n.º 4
0
        private void ApplyRule(World world, WorldRow row)
        {
            var baseType = typeof (AliveState);
            foreach (var cell in row.Cells)
            {
                var neighbours = world.GetNeighbors(row.RowNumber, cell.CellNumber);
                var livingCells = neighbours.Count(n => n.State.GetType() == baseType);

                if (livingCells < 2)
                {
                    log.InfoFormat("Killing {0},{1} because less than 2 neighbours, got {2} neighbours",
                        cell.CellNumber,
                        cell.RowNumber,
                        livingCells);

                    cell.Die();
                }
                else
                {
                    log.DebugFormat("Ignoring {0}, {1} has {2} neighbours", cell.CellNumber, cell.RowNumber, livingCells);
                }
            }
        }