Example #1
0
 public neighbors(blackDot centerPoint)
 {
     neighborsCoords = new neighborCoordinates[4]
     {
         new neighborCoordinates(centerPoint.y - 1, centerPoint.x),
         new neighborCoordinates(centerPoint.y, centerPoint.x + 1),
         new neighborCoordinates(centerPoint.y + 1, centerPoint.x),
         new neighborCoordinates(centerPoint.y, centerPoint.x - 1)
     };
 }
Example #2
0
 static private void exploreNeighbors(neighbors neighborsCoords, List <blackDot> blackDotsList, Queue <blackDot> unexploredDotsQueue)
 {
     foreach (neighborCoordinates neighbor in neighborsCoords)
     {
         if (blackDotsList.Any(dot => dot.y == neighbor.y && dot.x == neighbor.x && dot.isMapped == false && dot.isInQue == false))
         {
             blackDot newUnexploredPartOfTheIsland = blackDotsList.Find(dot => dot.y == neighbor.y && dot.x == neighbor.x);
             unexploredDotsQueue.Enqueue(newUnexploredPartOfTheIsland);
             newUnexploredPartOfTheIsland.isInQue = true;
         }
     }
 }
Example #3
0
        // next procedure starts exploratrion from a firstPoint and than maps an island with all other connected black dots

        static private void islandMapper(blackDot firstDot, List <blackDot> blackDotsList)
        {
            Queue <blackDot> unexploredDotsQueue = new Queue <blackDot>();

            unexploredDotsQueue.Enqueue(firstDot);


            while (unexploredDotsQueue.Count > 0)
            {
                blackDot  currentDot            = unexploredDotsQueue.Dequeue();
                neighbors neighborsOfCurrentDot = new neighbors(currentDot);

                exploreNeighbors(neighborsOfCurrentDot, blackDotsList, unexploredDotsQueue);

                currentDot.isMapped = true;
            }
        }