Beispiel #1
0
        /// <summary>
        /// Main loop of flood spilling. Takes positions from the queue, visits them and spreads the flood from them,
        /// processing and adding to queue some of their neighbours.
        /// </summary>
        /// <returns>True if execution has been stopped by meeting a stop condition. False if ran out of elements in queue.</returns>
        private bool RunFlood()
        {
            bool startingPositionCausedStop = OperateOnStartingPosition();

            if (startingPositionCausedStop)
            {
                return(true);
            }

            while (PositionsToVisit.Any())
            {
                int currentX, currentY;
                PositionsToVisit.Dequeue(out currentX, out currentY);

                // visiting position that we just got from queue
                SpreadingPositionVisitor?.Invoke(currentX, currentY);
                if (SpreadingPositionStopCondition != null && SpreadingPositionStopCondition(currentX, currentY))
                {
                    return(true);
                }

                // spreading from visited position
                int  markToGive          = CalculateMark(currentX, currentY);
                bool neighbourCausedStop = SpreadToNeighbours(currentX, currentY, markToGive);
                if (neighbourCausedStop)
                {
                    return(true);
                }
            }
            return(false);
        }