Example #1
0
        private bool GetOutOfGridCells(int cellIndex, SurroundingCells surroundingCells, ref bool checkLeft, ref bool checkRight,
                                       ref bool checkTop, ref bool checkBottom)
        {
            if (OnLeftColumn(cellIndex))
            {
                surroundingCells.TopLeftCell    = GridCell.MakeOutOfGridCell(cellIndex, RelativePosition.TopLeft);
                surroundingCells.LeftCell       = GridCell.MakeOutOfGridCell(cellIndex, RelativePosition.Left);
                surroundingCells.BottomLeftCell = GridCell.MakeOutOfGridCell(cellIndex, RelativePosition.BottomLeft);
                checkLeft = false;
            }
            else if (OnRightColumn(cellIndex))
            {
                surroundingCells.TopRightCell    = GridCell.MakeOutOfGridCell(cellIndex, RelativePosition.TopRight);
                surroundingCells.RightCell       = GridCell.MakeOutOfGridCell(cellIndex, RelativePosition.Right);
                surroundingCells.BottomRightCell = GridCell.MakeOutOfGridCell(cellIndex, RelativePosition.BottomRight);
                checkRight = false;
            }

            if (OnTopRow(cellIndex))
            {
                surroundingCells.TopLeftCell  = GridCell.MakeOutOfGridCell(cellIndex, RelativePosition.TopLeft);
                surroundingCells.TopCell      = GridCell.MakeOutOfGridCell(cellIndex, RelativePosition.Top);
                surroundingCells.TopRightCell = GridCell.MakeOutOfGridCell(cellIndex, RelativePosition.TopRight);
                checkTop = false;
            }
            else if (OnBottomRow(cellIndex))
            {
                surroundingCells.BottomLeftCell  = GridCell.MakeOutOfGridCell(cellIndex, RelativePosition.BottomLeft);
                surroundingCells.BottomCell      = GridCell.MakeOutOfGridCell(cellIndex, RelativePosition.Bottom);
                surroundingCells.BottomRightCell = GridCell.MakeOutOfGridCell(cellIndex, RelativePosition.BottomRight);
                checkBottom = false;
            }

            return(checkLeft);
        }
        public CellGrowthResult CalculateCellGrowth(BioCell cell, IPlayer player, SurroundingCells surroundingCells)
        {
            var emptyCells = surroundingCells.EmptyCells;

            var newCells = GrowNewCells(player, emptyCells);

            var newDeadCells = CheckForCellDeath(cell, player, surroundingCells);

            return(new CellGrowthResult(newCells, newDeadCells));
        }
Example #3
0
        private void GetInGridCells(int cellIndex, SurroundingCells surroundingCells,
                                    Dictionary <int, BioCell> currentLiveCells, Dictionary <int, BioCell> currentDeadCells, bool checkLeft,
                                    bool checkBottom, bool checkTop, bool checkRight)
        {
            if (checkLeft)
            {
                if (checkBottom)
                {
                    surroundingCells.BottomLeftCell = GetBottomLeftCell(cellIndex, currentLiveCells, currentDeadCells);
                }

                surroundingCells.LeftCell = GetLeftCell(cellIndex, currentLiveCells, currentDeadCells);

                if (checkTop)
                {
                    surroundingCells.TopLeftCell = GetTopLeftCell(cellIndex, currentLiveCells, currentDeadCells);
                }
            }

            if (checkTop)
            {
                //--skip top left cell as it's already been set or out of grid

                surroundingCells.TopCell = GetTopCell(cellIndex, currentLiveCells, currentDeadCells);

                if (checkRight)
                {
                    surroundingCells.TopRightCell = GetTopRightCell(cellIndex, currentLiveCells, currentDeadCells);
                }
            }

            if (checkRight)
            {
                //--skip top right cell as it's already been set or out of grid

                surroundingCells.RightCell = GetRightCell(cellIndex, currentLiveCells, currentDeadCells);

                if (checkBottom)
                {
                    surroundingCells.BottomRightCell = GetBottomRightCell(cellIndex, currentLiveCells, currentDeadCells);
                }
            }

            if (checkBottom)
            {
                //--skip bottom right cell as it's already been set or out of grid

                surroundingCells.BottomCell = GetBottomCell(cellIndex, currentLiveCells, currentDeadCells);

                //--skip bottom left as it's already been set or out of grid
            }
        }
        private List <BioCell> CheckForCellDeath(BioCell cell, IPlayer player, SurroundingCells surroundingCells)
        {
            var newDeadCells = new List <BioCell>();

            if (player.LiveCells >= MinimumLiveCellsForCellDeath &&
                (CellDiesOfStarvation(surroundingCells.SurroundedByLiveCells, player) || CellDiesRandomly(player)))
            {
                cell.Dead           = true;
                cell.PreviousPlayer = cell.Player;
                newDeadCells.Add(cell);
            }

            return(newDeadCells);
        }
Example #5
0
        public SurroundingCells GetSurroundingCells(
            BioCell bioCell,
            Dictionary <int, BioCell> currentLiveCells,
            Dictionary <int, BioCell> currentDeadCells)
        {
            var surroundingCells = new SurroundingCells();
            var checkLeft        = true;
            var checkTop         = true;
            var checkRight       = true;
            var checkBottom      = true;

            checkLeft = GetOutOfGridCells(bioCell.CellIndex, surroundingCells,
                                          ref checkLeft, ref checkRight, ref checkTop, ref checkBottom);

            GetInGridCells(bioCell.CellIndex, surroundingCells, currentLiveCells, currentDeadCells, checkLeft, checkBottom, checkTop, checkRight);

            return(surroundingCells);
        }
Example #6
0
        public CellGrowthResult RunCellGrowth(Dictionary <int, BioCell> currentLiveCells, Dictionary <int, BioCell> currentDeadCells)
        {
            SurroundingCells surroundingCells = _surroundingCellCalculator.GetSurroundingCells(this, currentLiveCells, currentDeadCells);

            return(Player.CalculateCellGrowth(this, surroundingCells));
        }