コード例 #1
0
        private void DiscoverNeighboursAndIncrementCount(VisitablePoint aliveCellPoint)
        {
            if (aliveCellPoint.X < _gameUniverse.GridXAxisCount)
            {
                Point immediateRight = new Point(aliveCellPoint.X + 1, aliveCellPoint.Y);
                IncrementAliveCountIfUnvisitedAliveNeighbour(aliveCellPoint, immediateRight);
            }

            if (aliveCellPoint.X > 1)
            {
                Point immediateLeft = new Point(aliveCellPoint.X - 1, aliveCellPoint.Y);
                IncrementAliveCountIfUnvisitedAliveNeighbour(aliveCellPoint, immediateLeft);
            }

            if (aliveCellPoint.Y > 1)
            {
                Point immediateTop = new Point(aliveCellPoint.X, aliveCellPoint.Y - 1);
                IncrementAliveCountIfUnvisitedAliveNeighbour(aliveCellPoint, immediateTop);
            }

            if (aliveCellPoint.Y < _gameUniverse.GridYAxisCount)
            {
                Point immediateBottom = new Point(aliveCellPoint.X, aliveCellPoint.Y + 1);
                IncrementAliveCountIfUnvisitedAliveNeighbour(aliveCellPoint, immediateBottom);
            }

            if (aliveCellPoint.X < _gameUniverse.GridXAxisCount && aliveCellPoint.Y > 1)
            {
                Point diagonalTopRight = new Point(aliveCellPoint.X + 1, aliveCellPoint.Y - 1);
                IncrementAliveCountIfUnvisitedAliveNeighbour(aliveCellPoint, diagonalTopRight);
            }

            if (aliveCellPoint.X < _gameUniverse.GridXAxisCount && aliveCellPoint.Y < _gameUniverse.GridYAxisCount)
            {
                Point diagonalBottomRight = new Point(aliveCellPoint.X + 1, aliveCellPoint.Y + 1);
                IncrementAliveCountIfUnvisitedAliveNeighbour(aliveCellPoint, diagonalBottomRight);
            }

            if (aliveCellPoint.X > 1 && aliveCellPoint.Y > 1)
            {
                Point diagonalTopLeft = new Point(aliveCellPoint.X - 1, aliveCellPoint.Y - 1);
                IncrementAliveCountIfUnvisitedAliveNeighbour(aliveCellPoint, diagonalTopLeft);
            }

            if (aliveCellPoint.X > 1 && aliveCellPoint.Y < _gameUniverse.GridYAxisCount)
            {
                Point diagonalBottomLeft = new Point(aliveCellPoint.X - 1, aliveCellPoint.Y + 1);
                IncrementAliveCountIfUnvisitedAliveNeighbour(aliveCellPoint, diagonalBottomLeft);
            }
        }
コード例 #2
0
        private void IncrementAliveCountIfUnvisitedAliveNeighbour(VisitablePoint aliveCellPoint, Point point)
        {
            if (IsAlivePoint(point))
            {
                //currently alive neighbor
                if (!IsVisitedPoint(point))
                {
                    IncrementNeighborCount(aliveCellPoint, point, true);
                }
            }

            //currently Dead neighbor
            else
            {
                IncrementNeighborCount(point);
            }
        }
コード例 #3
0
 private void MarkAliveCellPointAsVisited(VisitablePoint aliveCellPoint)
 {
     _aliveCellPoints.
     Single(cell => cell.X == aliveCellPoint.X && cell.Y == aliveCellPoint.Y).IsVisited = true;
 }
コード例 #4
0
 private void IncrementNeighborCount(VisitablePoint aliveCellPoint, Point Point, bool useDictionaryForCurrentlyAlivePoints = false)
 {
     IncrementNeighborCount(aliveCellPoint.Point, true);
     IncrementNeighborCount(Point, true);
 }