public IEnumerable<Cell> Enumerate(CellList list)
        {
            List<Cell> unEvaluatedCells = list.Cells.ToList();

            foreach (Cell cell in unEvaluatedCells)
            {
                if (!NotYetEvaluated(cell)) continue;

                yield return cell;

                WasEvaluated(cell);
            }

            foreach (Cell cell in unEvaluatedCells)
            {
                List<Cell> unEvaluatedNeighbourCells = FindOrGenerateNeighbourCells(list, cell).ToList();

                foreach (Cell neighbourCell in unEvaluatedNeighbourCells)
                {
                    if (!NotYetEvaluated(neighbourCell)) continue;

                    yield return neighbourCell;

                    WasEvaluated(neighbourCell);
                }
            }

            Debug.Assert(_evaluatedPoints.Count == list.Cells.Count);
        }
 public bool Tick()
 {
     var executor = new ExecuteConwayRules();
     list = executor.GetNextGeneration(list);
     ticks++;
     return true;
 }
        static CellList ApplyNextGenerationResultsToNewList(IEnumerable<AddNewCellToList> results)
        {
            var nextGeneration = new CellList();

            foreach (AddNewCellToList result in results) result.ToList(nextGeneration);

            return nextGeneration;
        }
        public CellList GetNextGeneration(CellList list)
        {
            List<Cell> cellsToEvaluate = new EnumerateCellsAndAddMissingDeadNeighbours().Enumerate(list).ToList();

            IEnumerable<AddNewCellToList> results = cellsToEvaluate.Select(EvaluateNextGenerationOfCell);

            return ApplyNextGenerationResultsToNewList(results);
        }
        public IEnumerable<Cell> Find(CellList list, Point position)
        {
            var generator = new GeneratePointsAroundPoint();

            IEnumerable<Point> points = generator.Generate(position);

            var cellFinder = new FindCellAtPosition();

            return points.Select(p => cellFinder.Find(list, p)).Where(c => c != null);
        }
        public Cell ToList(CellList list)
        {
            if (list.Cells.Any(c => c.Point == _position))
            {
                throw new Exception("A cell already exists in that position");
            }

            var cell = new Cell(list, _position, _state);

            list.Cells.Add(cell);

            return cell;
        }
Exemple #7
0
        static void Main(string[] args)
        {
            var list = new CellList();

            string[] setup = ConwayBoards.Acorn();

            list.SetupCells(setup);

            var model = new CellListToConwayModelWrapper(list);

            var display = new ConwayTerminalDisplay(79, 35, model);

            display.Start();
        }
        IEnumerable<Cell> FindOrGenerateNeighbourCells(CellList list, Cell cell)
        {
            IEnumerable<Point> points = new GeneratePointsAroundPoint().Generate(cell.Point);

            foreach (Point point in points)
            {
                Cell match = new FindCellAtPosition().Find(list, point);
                if (match != null)
                {
                    yield return match;
                }
                else
                {
                    yield return new AddNewCellToList(point, CellState.Dead).ToList(list);
                }
            }
        }
Exemple #9
0
 void ExecuteGameRules()
 {
     var executor = new ExecuteConwayRules();
     resultList = executor.GetNextGeneration(list);
 }
 public Cell Find(CellList list, Point position)
 {
     return list.Cells.FirstOrDefault(c => c.Point == position);
 }
Exemple #11
0
 public Cell(CellList list, Point point, CellState state)
 {
     Point = point;
     State = state;
     List = list;
 }
 public int Count(CellList list, Point point)
 {
     var finder = new FindNeighboursOfCellAtPosition();
     IEnumerable<Cell> cells = finder.Find(list, point);
     return cells.Count(c => c.State == CellState.Live);
 }
 public CellListToConwayModelWrapper(CellList initial)
 {
     list = initial;
 }