Пример #1
0
 /// <summary>
 /// Connects a given node to the closest X nodes
 /// </summary>
 /// <param name="node">The node that needs to be connected</param>
 /// <param name="numberOfConnections">The limit on the number of connections that 
 /// a given node can be connected to</param>
 private void MakeConnection(Node node, UInt16 numberOfConnections)
 {
     foreach (Node possibleConnectionNode in Milestones.
         Select(o => o).
         Where(o => o != node && o.Edges.Count < numberOfConnections).
         OrderBy(o => o.Distance(node)))
     {
         Edge edge = new Edge(node, possibleConnectionNode);
         if (edge.Link(Obstacles))
         {
             possibleConnectionNode.Edges.Add(edge);
             node.Edges.Add(edge);
             if (node.Edges.Count >= numberOfConnections)
                 break;
         }
     }
 }
Пример #2
0
        /// <summary>
        /// 
        /// </summary>
        private void GenerateEvenConnections()
        {
            List<Node> previousColumn = new List<Node>();
            List<Node> currentColumn = new List<Node>();

            // Make connections along the X coordinate
            foreach (Node node in Milestones.OrderBy(o => o.Y).OrderBy(o => o.X))
            {
                // There are other nodes that we can make connections to
                if (currentColumn.Count != 0)
                {
                    // Now we figure out what near by nodes we need to connect to

                    // If the node is starting a new column
                    if (currentColumn.Last().Y >= node.Y)
                    {
                        // place the "currentColumn" as the previous column and
                        // create a new current column
                        previousColumn = currentColumn;
                        currentColumn = new List<Node>();
                    }
                    else // we are continueing along the same column
                    {
                        // create an edge to the previous node since we are on the same column
                        Edge edge = new Edge(node, currentColumn.Last());
                        if (edge.Link(Obstacles))
                            edge.MakeConnection();
                    }

                    // Make connections to the nodes from the previous column
                    foreach (Node previousNode in previousColumn.
                        Where(o => o.Y == node.Y - 1
                            || o.Y == node.Y
                            || o.Y == node.Y + 1))
                    {
                        Edge previousColumnEdge = new Edge(node, previousNode);
                        if (previousColumnEdge.Link(Obstacles))
                            previousColumnEdge.MakeConnection();
                    }
                }
                // Add the node to the current column list
                currentColumn.Add(node);
            }
        }