예제 #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;
 }