public void AddCell(CellLocation cellLocation) { if (WorldDoesNotHaveCellAt(cellLocation)) { CellLocationsOfLivingCells.Add(_surroundingCellLocations.CreateKeyFrom(cellLocation), cellLocation); } }
private void CheckLivingCellAgainstLiveEvolutionRules(GameWorld newWorld, CellLocation cellLocation) { var neighours = CurrentWorld.CountNeighboursOf( cellLocation); if (_liveEvolutionRules.CellStateBasedOnNumberOfNeighbours(neighours)) { newWorld.AddCell(cellLocation); } }
private void CheckAgainstDeadEvolutionRules(GameWorld newWorld, CellLocation cellLocation) { var noCellsInLocation = _neighbourGenerator.GenerateSurroundingCellLocations(cellLocation); foreach (var cells in noCellsInLocation.Values) { var deadNeighours = CurrentWorld.CountNeighboursOf( cells); if (_deadEvolutionRules.CellStateBasedOnNumberOfNeighbours(deadNeighours)) { newWorld.AddCell(cells); } } }
public CellLocation(CellLocation updateCellLocation, int x, int y) : this(updateCellLocation.X + x, updateCellLocation.Y + y) { }
private bool WorldDoesNotHaveCellAt(CellLocation cellLocation) { return(!CellLocationsOfLivingCells.ContainsKey(_surroundingCellLocations.CreateKeyFrom(cellLocation))); }
public int CountNeighboursOf(CellLocation cellLocation) { var numberOfNeighbouringCells = _surroundingCellLocations.GenerateSurroundingCellLocations(cellLocation); return(numberOfNeighbouringCells.Keys.Intersect(CellLocationsOfLivingCells.Keys).Count()); }