Пример #1
0
        /// <summary>
        /// Marking
        /// </summary>
        private void MarkIsolatedAreas(IOsnowaContext context)
        {
            var           floodSpiller  = new FloodSpiller();
            PositionFlags positionFlags = context.PositionFlags;
            var           stopwatch     = Stopwatch.StartNew();

            byte areaIndex        = 0;
            byte biggestAreaIndex = 0;
            int  maxArea          = 0;

            for (int probeX = 0; probeX < context.PositionFlags.XSize; probeX += 10)
            {
                for (int probeY = 0; probeY < context.PositionFlags.YSize; probeY += 10)
                {
                    bool     isFine       = false;
                    int      totalVisited = 0;
                    Position start        = new Position(probeX, probeY);
                    var      parameters   = new FloodParameters(start.x, start.y)
                    {
                        Qualifier =
                            (x, y) => positionFlags.IsWalkable(x, y),
                        NeighbourProcessor = (x, y, mark) =>
                        {
                            if (!isFine)
                            {
                                isFine     = true;
                                areaIndex += 1;
                            }
                            totalVisited += 1;
                        }
                    };
                    int[,] markMatrix = new int[context.PositionFlags.XSize, context.PositionFlags.YSize];
                    floodSpiller.SpillFlood(parameters, markMatrix);
                    if (totalVisited > 50)
                    {
                        // BUG looks like areas are not isolated, all are of same size of the whole island!
                        // Debug.Log("visited " + totalVisited + "from " + start.x + ", " + start.y + " with index " + areaIndex);
                    }
                    if (totalVisited > maxArea)
                    {
                        maxArea          = totalVisited;
                        biggestAreaIndex = areaIndex;
                    }
                }
            }
            Debug.Log("biggest isolated area index: " + biggestAreaIndex);
            Debug.Log("biggest isolated area index: " + maxArea);
            Debug.Log("marking isolated areas took: " + stopwatch.ElapsedMilliseconds);
        }
Пример #2
0
 public bool IsWalkable(Position position)
 {
     return(_positionFlags.IsWalkable(position));
 }