public GameOfLife(String gameInput, GameCriteria criteria, ITranslator<GameData> translator, BoardFactory boardFactory) { this.criteria = criteria; var gameData = translator.Translate(gameInput); board = boardFactory.GetBoard(gameData); }
public void Generate(GameCriteria criteria) { var nextGeneration = new List<Cell>(); foreach (var cell in Cells) { var nextGenerationCell = GetNextGenerationFor(cell, criteria); nextGeneration.Add(nextGenerationCell); } Cells = nextGeneration; }
private Boolean DetermineNextGenerationLifeStatusFor(Cell cell, GameCriteria criteria) { var iterator = criteria.CellIterator; var aliveNeighbors = 0; iterator.Initialize(Cells); iterator.SetHomeCell(cell); for (iterator.First(); !iterator.IsDone(); iterator.Next()) { if (iterator.CurrentItem() != null && iterator.CurrentItem().IsAlive) aliveNeighbors++; } return criteria.GameRules.IsLifeGrantedFor(cell.IsAlive, aliveNeighbors); }
private Cell GetNextGenerationFor(Cell cell, GameCriteria criteria) { var nextGenerationIsAlive = DetermineNextGenerationLifeStatusFor(cell, criteria); var nextGenerationValue = nextGenerationIsAlive ? criteria.AliveValue : criteria.DeadValue; return new Cell { X = cell.X, Y = cell.Y, IsAlive = nextGenerationIsAlive, Value = nextGenerationValue }; }