示例#1
0
文件: Grid.cs 项目: agamya/GameOfLife
        /// <summary>
        ///     Create new instance of current grid
        /// </summary>
        /// <param name="currentGrid"> Current grid </param>
        /// <returns> Retunr new grid instance </returns>
        public IGrid Copy(IGrid currentGrid)
        {
            var gridCopy = new Grid(currentGrid.GridSize);
            foreach (
                var newCell in currentGrid.GetAllCurrentCellInfo().Select(cell => new Cell(cell.Position, cell.Alive)))
            {
                gridCopy.MakeCell(newCell);
            }

            return gridCopy;
        }
示例#2
0
 /// <summary>
 ///     By applying game rules get the next genertion grid instance
 /// </summary>
 /// <param name="currentGrid"> Grid on which games rules </param>
 /// <param name="gameRules"> </param>
 /// <returns> Evolved grid instance </returns>
 public IGrid GetNextGeneration(IGrid currentGrid, IGameRules gameRules)
 {
     if (currentGrid != null && gameRules != null)
     {
         var gridCopy = currentGrid.Copy(currentGrid);
         foreach (var cell in currentGrid.GetAllCurrentCellInfo())
         {
             cell.Alive = gameRules.WillBeAliveInNextGeneration(gridCopy, cell);
             gridCopy.MakeCell(cell);
         }
         return gridCopy;
     }
     return null;
 }