public HexCoordsPathNode(MyHexCell coords, HexCoordsPathNode anchor, int fCost, int gCost) { this.coords = coords; this.anchor = anchor; this.fCost = fCost; this.gCost = gCost; }
public bool GetShortestAStarPathFor(MyHexCell start, MyHexCell dest) { MyHexCell tempRef = null; tempRef = start; HexCoordsPathNode temp = new HexCoordsPathNode(tempRef, null, 0, tempRef.pos.SSteps()); AddToOrUpdateOpen(temp); while (temp.coords != dest) { int lScore = LowestScoreInOpen(); if (lScore == -1) { return(false); } temp = open[lScore]; open.RemoveAt(lScore); closed.Add(temp); for (int i = 0; i < HexCoords.directions.Length; i++) { MyHexCell t = MyHexGrid.Instance.GetElementAt(temp.coords.pos + HexCoords.directions[i]); if (t && !InClosedList(t) && (t.pos.H - temp.coords.pos.H) <= allowedHeightDist) { AddToOrUpdateOpen(t, temp, temp.cost + t.costs, tempRef.pos.SSteps()); } } } while (temp.coords != start) { aStarPath.Add(temp.coords.pos); temp = temp.anchor; } aStarPath.Reverse(); return(true); }
bool AddToOrUpdateOpen(MyHexCell coords, HexCoordsPathNode anchor, int fCost, int gCost) { for (int i = 0; i < open.Count; i++) { if (coords == open[i].coords) { if (fCost < open[i].fCost) { open[i] = new HexCoordsPathNode(coords, anchor, fCost, gCost); return(true); } else { return(false); } } } open.Add(new HexCoordsPathNode(coords, anchor, fCost, gCost)); return(true); }
bool AddToOrUpdateOpen(HexCoordsPathNode hCPN) { for (int i = 0; i < open.Count; i++) { if (hCPN.coords == open[i].coords) { if (hCPN.gCost < open[i].gCost) { open[i] = hCPN; return(true); } else { return(false); } } } open.Add(hCPN); return(true); }