public static LinkedList <Hex> Pathfind(WorldMap w, Hex start, Hex goal) { if (!goal.b.Passable()) { return(null); } try { List <Hex> openHexes = new List <Hex>(); start.pathfind = new PathfindingInfo(); start.pathfind.gScore = 0; start.pathfind.fScore = fHeuristic(start, goal); openHexes.Add(start); while (openHexes.Count() > 0) { Hex cur = removeLowestFScore(openHexes); cur.pathfind.evaluated = true; if (cur == goal) { return(reconstructPath(goal)); } foreach (Hex n in cur.Neighbors()) { var tentativeGscore = cur.pathfind.gScore + 1; // All neighbors are 1 apart. if (n.pathfind == null) { n.pathfind = new PathfindingInfo(); } if (n.b.Passable() && tentativeGscore < n.pathfind.gScore) { openHexes.Add(n); //UnityEngine.Debug.Log(n.b.Passable() + " " + n.pathfind.ToString() + " " + tentativeGscore.ToString()); n.pathfind.cameFrom = cur; n.pathfind.gScore = tentativeGscore; n.pathfind.fScore = n.pathfind.gScore + fHeuristic(n, goal); } } } return(null); } finally { foreach (KeyValuePair <HexLoc, Hex> kv in w.map) { kv.Value.pathfind = null; } } }
private void setEv(Hex h, float value) { h.ev = value; float val = value - h.b.Dropoff(); foreach (Hex h2 in h.Neighbors()) { if (val > h2.ev) { setEv(h2, val); } } }