public void FindPathTo(int to) { path = AStarPathFinding.FindPath(FindClosestNode(), to); path.CalcParams(); // Drawing path for debugging //path.DrawPath(); }
public void FindPath(int from, int to) { path = AStarPathFinding.FindPath(from, to); path.CalcParams(); // Drawing path for debugging //path.DrawPath(); }
/// <summary> /// Sprawdza czy istnieje ścieżka do celu - Astar /// </summary> /// <returns></returns> public bool checkIfPathExist() { grid.updateAllNodes(); var path = aStarPath.FindPath(Agent.transform.position, Target.transform.position); if (path.Count > 0) { return(true); } return(false); }
private static void WalkTheDungeon(Game gameInstance) { Logger.Info("Walking the dungeon..."); var pathFinder = new AStarPathFinding(); var movementProfile = new HumanoidMovement(); var visibilityMap = new VisibilityMap(gameInstance.Terrain.Width, gameInstance.Terrain.Height, null, null); var walkableLocations = gameInstance.Terrain.WalkableLocations(movementProfile).ToList(); FloodFill.Fill(gameInstance.Terrain, visibilityMap, movementProfile, walkableLocations[Rng.Next(walkableLocations.Count - 1)]); var walkableUnseenLocations = GetWalkableUnseenLocations(gameInstance.Terrain, visibilityMap, movementProfile).ToList(); while (walkableUnseenLocations.Count > 0) { var closestExploredLocation = GetClosestExploredLocation(gameInstance.Terrain, visibilityMap, movementProfile, walkableUnseenLocations[Rng.Next(walkableUnseenLocations.Count - 1)]); var closestUnexploredLocation = GetClosestUnexploredLocation(gameInstance.Terrain, visibilityMap, movementProfile, closestExploredLocation.Value); var movementPath = pathFinder.FindPath(gameInstance.Terrain, new List <IActor>(), new DiggerMovement(), closestExploredLocation.Value, closestUnexploredLocation.Value); foreach (var node in movementPath) { gameInstance.Terrain[node.Location] = new Floor(); visibilityMap[node.Location].WasSeen = true; } visibilityMap[closestUnexploredLocation.Value].WasSeen = false; FloodFill.Fill(gameInstance.Terrain, visibilityMap, movementProfile, closestUnexploredLocation.Value); walkableUnseenLocations = GetWalkableUnseenLocations(gameInstance.Terrain, visibilityMap, movementProfile).ToList(); } //digger.VisibilityMap.UpdateVisibilityMap(gameInstance.Terrain, gameInstance.LightMap, digger.Location.Coordinate); //var command = digger.Intellect.GetNextAction(); //while (command is MoveCommand) //{ // var result = command.Execute(); // if ((!result.Success) && (command is MoveCommand)) // { // // The move action failed // // Ask the actor for a default action on bump // var defaultBumpAction = digger.Intellect.GetDefaultBumpAction((MoveCommand)command); // if (defaultBumpAction != null) // defaultBumpAction.Execute(); // } // digger.VisibilityMap.UpdateVisibilityMap(gameInstance.Terrain, gameInstance.LightMap, digger.Location.Coordinate); // command = digger.Intellect.GetNextAction(); //} //gameInstance.RemoveActor(digger); Logger.Info("Dungeon walk complete."); }
// Start is called before the first frame update void Start() { player = GameObject.FindGameObjectWithTag("Player"); playerInSight = false; decisionMaking = GetComponent <GuardDecisionMaking>(); // Generate patrol path path = AStarPathFinding.FindPath(patrolFrom, patrolTo); path.CalcParams(); //path = AStarPathFinding.FindPath(0, 27); //path.CalcParams(); // Drawing path for debugging //path.DrawPath(); }
public void FindPathToRoom(int room) { int chosenNode = -1; //List<int> possibleNodes; switch (room) { case 0: //possibleNodes = new List<int>() {2,3,4}; //chosenNode = possibleNodes[Random.Range(0, 3)]; chosenNode = 27; break; case 1: //possibleNodes = new List<int>() { 14, 44 }; //chosenNode = possibleNodes[Random.Range(0, 2)]; chosenNode = 28; break; case 2: //possibleNodes = new List<int>() { 11, 12, 25, 26 }; //chosenNode = possibleNodes[Random.Range(0, 4)]; chosenNode = 29; break; case 3: //possibleNodes = new List<int>() { 14, 43 }; //chosenNode = possibleNodes[Random.Range(0, 4)]; chosenNode = 32; break; case 4: //possibleNodes = new List<int>() { 16, 45, 46, 47 }; //chosenNode = possibleNodes[Random.Range(0, 4)]; chosenNode = 31; break; case 5: //possibleNodes = new List<int>() { 16, 45, 46, 47 }; //chosenNode = possibleNodes[Random.Range(0, 4)]; chosenNode = 30; break; } path = AStarPathFinding.FindPath(FindClosestNode(), chosenNode); path.CalcParams(); // Drawing path for debugging //path.DrawPath(); }
public void FindPath(AStarPoint e) { if (pathTweener != null) { pathTweener.Kill(); } AStarPoint s = new AStarPoint((int)player.transform.position.x, (int)player.transform.position.y); List <AStarPoint> pathList; if (!AStarPathFinding.FindPath(s, e, out pathList)) { AudioManager.Instance.PlayClip(AudioManager.Instance.why); Anim.SetTrigger("Why"); return; } else { pathTweener = player.transform.DOPath(pathList.ToVector3Array(), pathList.Count * 0.15f); pathTweener.SetEase(Ease.Linear); pathTweener.OnComplete(() => pathTweener = null).OnKill(() => pathTweener = null); } }
public void SetTarget(Point target) { TargetPosition = target; var arr = new int[_map.Width, _map.Height]; for (var x = 0; x < _map.Width; x++) { for (var y = 0; y < _map.Height; y++) { if (_map.GetCellDepth(new Point(x, y)) <= Draft) { arr[x, y] = -1; } } } var path = AStarPathFinding.FindPath(arr, CurrentPosition, target); if (path == null) { return; } var pathQueue = new Queue <Point>(path); // Remove current position from path queue if (pathQueue.Peek() == CurrentPosition) { pathQueue.Dequeue(); } SetPath(pathQueue); SetState(new TransferState(this, _map, Cell.Size)); }