示例#1
0
        public CellState GetNextCellState(ReadOnlyGrid neighbours)
        {
            var prioritisedRuleKeys = GetRuleKeysOrderedInReversePriority();

            var currentState = neighbours.GetCellState(new CellPosition(1, 1));

            foreach (var ruleKey in prioritisedRuleKeys)
            {
                currentState = _rules[ruleKey].GetNextCellState(neighbours, currentState);
            }

            return(currentState);
        }
示例#2
0
        private static List <CellState> GetNeighbouringCellStates(ReadOnlyGrid concernedCells)
        {
            var neighbouringCells = new List <CellState>();

            for (var rowIndex = 0; rowIndex < 3; rowIndex++)
            {
                for (var columnIndex = 0; columnIndex < 3; columnIndex++)
                {
                    if (!IsCenterCell(rowIndex, columnIndex))
                    {
                        var cellPosition = new CellPosition(rowIndex, columnIndex);
                        neighbouringCells.Add(concernedCells.GetCellState(cellPosition));
                    }
                }
            }

            return(neighbouringCells);
        }
        public bool HasMet(ReadOnlyGrid concernedCells)
        {
            var centerCellPosition = new CellPosition(1, 1);

            return(_initialStates.Contains(concernedCells.GetCellState(centerCellPosition)));
        }
        public void GetNextCellState_Should_Get_Next_State_For_Given_Grid(ReadOnlyGrid grid, CellState expectedState)
        {
            var initialState = grid.GetCellState(new CellPosition(1, 1));

            Assert.AreEqual(expectedState, _overcrowdingRule.GetNextCellState(grid, initialState));
        }