Пример #1
0
 public void AddCell(CellLocation cellLocation)
 {
     if (WorldDoesNotHaveCellAt(cellLocation))
     {
         CellLocationsOfLivingCells.Add(_surroundingCellLocations.CreateKeyFrom(cellLocation), cellLocation);
     }
 }
Пример #2
0
        private void CheckLivingCellAgainstLiveEvolutionRules(GameWorld newWorld, CellLocation cellLocation)
        {
            var neighours =
                CurrentWorld.CountNeighboursOf(
                    cellLocation);

            if (_liveEvolutionRules.CellStateBasedOnNumberOfNeighbours(neighours))
            {
                newWorld.AddCell(cellLocation);
            }
        }
Пример #3
0
        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);
                }
            }
        }
Пример #4
0
 public CellLocation(CellLocation updateCellLocation, int x, int y) : this(updateCellLocation.X + x,
                                                                           updateCellLocation.Y + y)
 {
 }
Пример #5
0
 private bool WorldDoesNotHaveCellAt(CellLocation cellLocation)
 {
     return(!CellLocationsOfLivingCells.ContainsKey(_surroundingCellLocations.CreateKeyFrom(cellLocation)));
 }
Пример #6
0
        public int CountNeighboursOf(CellLocation cellLocation)
        {
            var numberOfNeighbouringCells = _surroundingCellLocations.GenerateSurroundingCellLocations(cellLocation);

            return(numberOfNeighbouringCells.Keys.Intersect(CellLocationsOfLivingCells.Keys).Count());
        }