示例#1
0
 /// <summary>
 /// Setup the grid
 /// </summary>
 /// <param name="rows"></param>
 /// <param name="columns"></param>
 public Game(int rows, int columns)
 {
     if (rows <= 0 || columns <= 0)
     {
         throw new ArgumentOutOfRangeException("Row and Column size must be greater than zero");
     }
     this.InputGrid  = new Grid(rows, columns);
     this.OutputGrid = new Grid(rows, columns);
     ReachableCell.InitializeReachableCells();
 }
示例#2
0
        /// <summary>
        /// Count live adjacent cells for specified cell co-ordinates
        /// </summary>
        /// <param name="grid"></param>
        /// <param name="coOrdinates"></param>
        /// <returns>returns number of live neighbours</returns>
        private static int CountAliveNeighbours(Grid grid, CoOrdinates coOrdinates)
        {
            int liveNeighbours = 0;
            // Get the Cell type of current cell
            CellTypeEnum       enumInnerCell  = ReachableCell.GetCellType(grid, coOrdinates);
            List <CoOrdinates> reachableCells = new List <CoOrdinates>();

            // populate reachable cells from current cell for easier traversing
            ReachableCell.ReachableCells.TryGetValue(enumInnerCell, out reachableCells);
            if (reachableCells.Count == 0)
            {
                throw new ArgumentNullException("Cannot find reachable co-ordinates");
            }
            foreach (CoOrdinates coOrds in reachableCells)
            {
                liveNeighbours += IsAliveNeighbour(grid, coOrdinates, coOrds);
            }
            return(liveNeighbours);
        }