Exemple #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();
            }
        private IEnumerable <Vertex2D> getConnectionsLeaped(PathFinder2D <Vertex2D> finder, Vertex2D getCameFrom, Vertex2D current)
        {
            //if (count > 20) yield break;
            this.activeFinder = finder;

            var dir   = new Vector2(1, 0);
            var right = new Vector2(0, 1);

            Vertex2D nRight;
            Vertex2D nLeft;

            nRight = doJump(current, right, dir);
            nLeft  = doJump(current, -right, dir);

            if (nRight != null)
            {
                yield return(nRight);
            }
            if (nLeft != null)
            {
                yield return(nLeft);
            }

            var top    = findHorizontalJump(current, dir, right);
            var bottom = findHorizontalJump(current, dir, right);

            if (top != null)
            {
                yield return(top);
            }
            if (bottom != null)
            {
                yield return(bottom);
            }
        }
 public IEnumerable <Vertex2D> GetConnectedNodes(PathFinder2D <Vertex2D> finder, Vertex2D current)
 {
     count++;
     //var cameFrom = finder.GetCameFrom(current);
     //if (cameFrom == null) return getConnectionsAll(current);
     //return getConnectionsLeaped(finder, null, current);
     return(getConnectionsAll(current));
 }
Exemple #4
0
        public PathfinderVisualizer(DX11Game game, PathFinder2D <T> finder, Action <LineManager3DLines, T, Color4> renderFunction)
        {
            this.game           = game;
            this.renderFunction = renderFunction;
            finder.Begin       += finder_Begin;
            finder.SelectNode  += finder_SelectNode;
            finder.EnqueueNode += finder_EnqueueNode;

            //lines = new LineManager3DLines(game.Device);
            //lines.SetMaxLines(1024 * 64);
        }
            public PathRendererSimulator()
            {
                Data = TW.Data.GetSingleton <MyData>();
                p    = new PathFinder2D <Vertex2D>();

                viz = new PathfinderVisualizer <Vertex2D>(TW.Graphics, p,
                                                          delegate(LineManager3DLines lines, Vertex2D d, Color4 c)
                {
                    TW.Graphics.LineManager3D.AddCenteredBox(
                        (d.Position.ToXZ() + new Vector3(0.5f, 0, 0.5f)) *
                        grid.NodeSize,
                        grid.NodeSize * 0.6f, c);
                    if (p.GetCameFrom(d) != null)
                    {
                        TW.Graphics.LineManager3D.AddLine((p.GetCameFrom(d).Position.ToXZ() + new Vector3(0.5f, 0, 0.5f)) *
                                                          grid.NodeSize, (d.Position.ToXZ() + new Vector3(0.5f, 0, 0.5f)) *
                                                          grid.NodeSize, c);
                    }
                });
            }
Exemple #6
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);
                    }
                }
            }
 public IEnumerable <Waypoint> GetConnectedNodes(PathFinder2D <Waypoint> finder, Waypoint current)
 {
     return(current.Edges.Select(e => e.Target));
 }