/// <summary> /// Waits until the ghost can indeed move and sets everything up so that he can start moving /// </summary> /// <returns></returns> IEnumerator BeginningCoroutine() { yield return(new WaitUntil(() => CanIStart())); movementMode = MovementMode.Scatter; target = UpdadeTarget(); pathToObjective = astar.FindPath(currentNode, GetClosesteNode(target)); targetNode = pathToObjective[pathToObjective.Count - 1]; StartCoroutine(MovetoNextNod()); }
private void R_NEW_POS(SocketIOEvent obj) { Debugger.Log(obj); if (!isInited) { Init(); isInited = true; } int id = -1; r_new_pos = obj.data["R_NEW_POS"]; r_new_pos.GetField(ref id, "ID"); if (id != -1 && id != 0) { agentTargetPosition = FindNextValidPosition(id); AStarAlgorithm.FindInfo info = new AStarAlgorithm.FindInfo() { StartPosition = agentRemote.CurrentPosition, EndPosition = agentTargetPosition, DoneCallback = FindPathDoneCallback }; aStarAlgorithm.FindPath(info); } }
private NodePath RunAstar(DefinitionNodeGrid definitionNodeGrid, Point2 gridStart, Point2 gridEnd, out bool succes) { var aStarAlgorithm = new AStarAlgorithm(definitionNodeGrid.NodeCount, new EuclideanDistance()); var start = definitionNodeGrid.NodeGrid.ToIndex(gridStart.X, gridStart.Y); var end = definitionNodeGrid.NodeGrid.ToIndex(gridEnd.X, gridEnd.Y); var pathfindingNetwork = new AstarNodeNetwork(definitionNodeGrid, new BrushfireClearanceGenerator(definitionNodeGrid, 5)); var pathRequest = PathRequest.Create(Substitute.For <IPathfinder <IPath> >(), start, end, PathfindaxCollisionCategory.Cat1); return(aStarAlgorithm.FindPath(pathfindingNetwork, pathRequest, out succes)); }
public void FindPath_InitializedNodegrid_PathLengthIsNot0(DefinitionNodeGrid definitionNodeGrid, int x1, int y1, int x2, int y2) { var aStarAlgorithm = new AStarAlgorithm(); var start = definitionNodeGrid.NodeGrid[x1, y1]; var end = definitionNodeGrid.NodeGrid[x1, y1]; var pathfindingNetwork = new AstarNodeNetwork(definitionNodeGrid, new GridClearanceGenerator(definitionNodeGrid, 5)); var pathRequest = new PathRequest <IPath>(start, end); var path = aStarAlgorithm.FindPath(pathfindingNetwork, pathRequest, out var _); Assert.AreEqual(path.Path.Length > 0, true); }
public void StratPathFindinAlgorithm() { pathFind.interactable = false; resetCurrentPath.interactable = true; clearAll.interactable = true; gridController.PathGridState = PathGridState.PathFind; gridController.InitGraf(); Vector2Int goalPosition = new Vector2Int(gridController.GoalPos.x, gridController.GoalPos.y); Vector2Int startPosition = new Vector2Int(gridController.StartPos.x, gridController.StartPos.y); IHeuristicEstimate heuristic = HeuristicFactory.СreateHeuristic(heuristicType, breakerType, startPosition, float.Parse(heuristicCoeffField.text)); float timeDelay = float.Parse(delayBeforeSteps.text); AStarAlgorithm algorithm = new AStarAlgorithm(gridMarkerController, heuristic, timeDelay); pathFindingAlgorithmCoroutine = StartCoroutine(algorithm.FindPath(gridController.GetStartVertex(), gridController.GetGoalVertex())); }
private void Run() { Defaults.Load(); MeasureTime(() => { Console.WriteLine("Reading network file..."); _streets = OsmStreetSystem.LoadSystem("K:\\OsmData\\schleswig-holstein-latest.sn"); Console.WriteLine("Finished."); }); GC.Collect(); var start = _streets.Waypoints[3444465853]; var end = _streets.Waypoints[620793260]; Console.WriteLine(); Console.WriteLine($"Trying to find path from {start.Id} to {end.Id}"); Console.WriteLine($"Direct distance: {start.DistanceTo(end):##.000} km"); Console.WriteLine(); Console.WriteLine("Using Dijkstra's allgorithm."); var dijkstra = new DijkstraAlgorithm(); var astar = new AStarAlgorithm(); Console.WriteLine(" --------- DIJKSTRA ----------"); for (int i = 0; i < 3; i++) { MeasureTime(() => { Console.WriteLine($"[{i}] Looking for a path in the graph...."); var p = dijkstra.FindPath(start, end); Console.WriteLine($"Finished in {dijkstra.Steps} steps."); Console.WriteLine($"Inspected {dijkstra.InspectedNodes}, visited {dijkstra.VisitedNodes}"); if (p != null) { Console.WriteLine($"Found a path. {p.Waypoints.Count} waypoints. {p.Length:##.000} km."); } else { Console.WriteLine("No path found."); } }); } Console.WriteLine(" --------- A-STAR ----------"); for (int i = 0; i < 3; i++) { MeasureTime(() => { Console.WriteLine($"[{i}] Looking for a path in the graph...."); var p = astar.FindPath(start, end); Console.WriteLine($"Finished in {astar.Steps} steps."); Console.WriteLine($"Inspected {astar.InspectedNodes}, visited {astar.VisitedNodes}"); if (p != null) { Console.WriteLine($"Found a path. {p.Waypoints.Count} waypoints. {p.Length:##.000} km."); } else { Console.WriteLine("No path found."); } }); } Console.ReadLine(); }
public NodePath FindLongPath() { return(_algorithm.FindPath(_astarNodeNetwork, _longPathRequest, out var succes)); }
public WaypointPath FindLongPath() { return(_algorithm.FindPath(_astarNodeNetwork, _longPathRequest)); }