コード例 #1
0
            public Vertex2D GetExplorationNeighbour(Vertex2D current)
            {
                var currDist = minWaypointDistance(current);
                var finder   = new PathFinder2D <Vertex2D>
                {
                    ConnectionProvider = new GridConnectionProvider()
                    {
                        Grid = provider.Grid, Heuristic = (a, b) => 0
                    },
                    StopCondition = n => minWaypointDistance(n) > WaypointDistance || Vector2.Distance(n.Position, current.Position) > 20
                };

                var path = finder.FindPath(current, new Vertex2D(new Vector2(4856984, 45684984)));

                if (minWaypointDistance(current) > minWaypointDistance(path.Last()))
                {
                    return(null);
                }
                if (path == null)
                {
                    return(null);
                }
                return(path.Last());

                //return provider.GetConnectedNodes(current).OrderBy(o => -minWaypointDistance(o)).FirstOrDefault();
            }
コード例 #2
0
            private void processWaypoints()
            {
                foreach (Waypoint wp in TW.Data.GetChangesOfType <Waypoint>().Where(c => c.Change == ModelChange.Added).Select(c => c.ModelObject))
                {
                    var start = provider.GetVertex(wp.Position);

                    foreach (Waypoint wpTo in getWaypoints())
                    {
                        if (wpTo == wp)
                        {
                            continue;
                        }

                        var goal = provider.GetVertex(wpTo.Position);

                        var finder = new PathFinder2D <Vertex2D> {
                            ConnectionProvider = provider
                        };
                        finder.StopCondition = n => finder.GetCurrentCost(n) > WaypointDistance * 2f;
                        var path = finder.FindPath(start, goal);
                        if (path == null)
                        {
                            continue;
                        }
                        if (path.Last() != goal)
                        {
                            continue;
                        }

                        var edge = new Waypoint.Edge {
                            Target = wpTo, Distance = finder.GetCurrentCost(path[path.Count - 2])
                        };
                        wp.Edges.Add(edge);
                    }
                }
            }