IEnumerator TrouverPath2(Vector3 positionDépart, Vector3 positionCible) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); Vector3[] wayPoints = new Vector3[0]; bool pathSuccess = false; Node nodeDépart = Grille.NodePositionMonde(positionDépart); Node nodeCible = Grille.NodePositionMonde(positionCible); if (nodeCible.EstSurfacePourMarcher) //nodeDépart.EstSurfacePourMarcher && nodeCible.EstSurfacePourMarcher) { //List<Node> openSet = new List<Node>(Grille.TailleMax); Heap<Node> openSet = new Heap<Node>(Grille.TailleMax); HashSet<Node> closedSet = new HashSet<Node>(); openSet.Add(nodeDépart); while (openSet.Count > 0) { //Node nodeActuel = openSet[0]; //for (int i = 1; i < openSet.Count; ++i) //{ // if (openSet [i].FCost < nodeActuel.FCost || openSet [i].FCost == nodeActuel.FCost && openSet [i].HCost < nodeActuel.HCost) // { // nodeActuel = openSet [i]; // } //} //openSet.Remove (nodeActuel); Node nodeActuel = openSet.EnleverPremier(); closedSet.Add(nodeActuel); if (nodeActuel == nodeCible) { stopwatch.Stop(); Debug.Print("Path trouvé: " + stopwatch.ElapsedMilliseconds + " ms"); //RetracerPath(nodeDépart, nodeCible); //return; pathSuccess = true; break; } foreach (Node voisin in Grille.GetVoisins(nodeActuel)) { if (!voisin.EstSurfacePourMarcher || closedSet.Contains(voisin)) { continue; } int CoutNouveauMouvementVoisin = nodeActuel.GCost + GetDistance(nodeActuel, voisin); if (CoutNouveauMouvementVoisin < voisin.GCost || !openSet.Contains(voisin)) { voisin.GCost = CoutNouveauMouvementVoisin; voisin.HCost = GetDistance(voisin, nodeCible); voisin.Parent = nodeActuel; if (!openSet.Contains(voisin)) { openSet.Add(voisin); } else { openSet.UpdateObjet(voisin); } } } } } yield return null; // // // non if (pathSuccess) // // // non { // // // non wayPoints = RetracerPath2(nodeDépart, nodeCible); // // // non } // // // non RequêtePathManager.FinishingProcessingPath(wayPoints, pathSuccess); // // // non }