Example #1
0
        public List <Node> FindNeighbours(Node currentNode)
        {
            if (!IsInitialized || AllNodes.Length == 0 || !currentNode.IsInitialized)
            {
                throw new Exception("Is not initialized");
            }
            if (currentNode.IsUnavailable ?? false)
            {
                throw new Exception("currentNode is Unavailable");
            }

            var actualNeighbours = new ConcurrentBag <Node>();

            currentNode.NeighboursIndexes(SizeX, SizeY).AsParallel().ForAll(p => {
                try {
                    var node = AllNodes.GetValue(p.X, p.Y) as Node;
                    if (node == null)
                    {
                        return;
                    }
                    if (node.IsInitialized && !(node.IsUnavailable ?? false))
                    {
                        actualNeighbours.Add(node);
                    }
                } catch (Exception e) {
                    Console.Write(e);
                }
            });

            currentNode.SetNeighbours(actualNeighbours.OrderBy(x => x.Id).ToList(), this);
            return(currentNode.Neighbours);
        }
Example #2
0
 public void SetObstacles(NodePosition[] obstacalesPostions)
 {
     obstacalesPostions.AsParallel().ForAll(x => {
         try {
             var node = AllNodes.GetValue(x.X, x.Y) as Node;
             if (node == null)
             {
                 return;
             }
             node.IsUnavailable = true;
             AllNodes.SetValue(node, x.X, x.Y);
         } catch (Exception e) {
             Console.WriteLine(e);
         }
     });
 }
Example #3
0
 public List <Node> FindPath(NodePosition start, NodePosition end)
 {
     if (!IsInitialized)
     {
         throw new Exception("First you need to Initialize the grid.");
     }
     try {
         var startNode = AllNodes.GetValue(start.X, start.Y) as Node;
         var endNode   = AllNodes.GetValue(end.X, end.Y) as Node;
         return(FindPath(startNode, endNode));
     } catch (IndexOutOfRangeException error) {
         Console.WriteLine(error);
         throw;
     } catch (Exception ex) {
         Console.WriteLine(ex);
         throw;
     }
 }