Exemplo n.º 1
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);
        }