예제 #1
0
        public override void Execute(CellInterface cell)
        {
            ValidateCell(cell);

            var neighbours      = NeighbourCalculator.retrieveNeighbours(cell.rowIndex, cell.columnIndex);
            var aliveNeighbours = neighbours.Where(n => n.isAlive).ToList();

            if (aliveNeighbours.Count() < 2 || aliveNeighbours.Count() > 3)
            {
                cell.isAlive = false;
            }
        }
예제 #2
0
        /*
         * Overrides the 'abstract' method in CellRule.cs
         */
        public override void Execute(CellInterface cell)
        {
            this.ValidateCell(cell);

            //'var' is an implicit type declaration that is chosen by the compiler, not the developer.
            var neighbours = NeighbourCalculator.retrieveNeighbours(cell.rowIndex, cell.columnIndex);

            //'Where' is used to "filter" an IEnumerable collection.
            var aliveNeighbours = neighbours.Where(n => n.isAlive);

            //If a cell has three neighbours exactly, make it alive.
            if (aliveNeighbours.Count() == 3)
            {
                cell.isAlive = true;
            }
        }