Beispiel #1
0
 public GameOfLife(String gameInput, GameCriteria criteria, 
                   ITranslator<GameData> translator, BoardFactory boardFactory)
 {
     this.criteria = criteria;
     var gameData = translator.Translate(gameInput);
     board = boardFactory.GetBoard(gameData);
 }
Beispiel #2
0
        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;
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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 };
        }