예제 #1
0
 private static IAmACell[] randomGridCells()
 {
     var rand = new Random();
     var seedCells = new IAmACell[GridWidth*GridHeight];
     for (var x = 0; x < GridWidth; x++)
         for (var y = 0; y < GridHeight; y++)
         {
             if (rand.NextDouble() > 0.5)
                 seedCells[x + GridWidth*y] = new LiveCell(x, y);
             else
                 seedCells[x + GridWidth*y] = new DeadCell(x, y);
         }
     return seedCells;
 }
예제 #2
0
 private static IAmACell[] randomGridCells()
 {
     var rand = new Random();
     var seedCells = new IAmACell[GridWidth*GridHeight];
     for (var x = 0; x < GridWidth; x++)
         for (var y = 0; y < GridHeight; y++)
         {
             if (rand.NextDouble() > 0.5)
                 seedCells[x + GridWidth*y] = new LiveCell(x, y);
             else
                 seedCells[x + GridWidth*y] = new DeadCell(x, y);
         }
     return seedCells;
 }
예제 #3
0
        public Grid NextEvolution(Grid grid)
        {
            var array = new IAmACell[_width * _height];

            for (var y = 0; y < _height; y++)
            {
                for (var x = 0; x < _width; x++)
                {
                    var coordinate = new Coordinate(x, y);
                    grid.GetCellState(coordinate,
                                      () => array[coordinate.X + _width * coordinate.Y] = whenCurrentCellisAlive(coordinate, grid),
                                      () => array[coordinate.X + _width * coordinate.Y] = whenCurrentCellIsDead(coordinate, grid));
                }
            }
            return(new Grid(array));
        }