private void InspectBlock(int x, int y, ref bool Found, ref bool Searching, ref AStarRec ClosestgPoint) { int num; if ((x == this.Source.X) && (y == this.Source.Y)) { num = 0; } else { num = this.Grid[x, y]; } for (int i = 0; i <= this.Freedom; i++) { int num2 = x + OffSets[i].DX; int num3 = y + OffSets[i].DY; if ((num2 == this.Goal.X) && (num3 == this.Goal.Y)) { Found = true; return; } if (((((num2 >= 0) && (num3 >= 0)) && ((num2 < this.MaxX) && (num3 < this.MaxY))) && ((num2 != this.Source.X) || (num3 != this.Source.Y))) && (this.Grid[num2, num3] == 0)) { int num5 = this.InspectBlockCallback(num2, num3, x, y, this.Argument); int num4 = (num + OffSets[i].Cost) + num5; switch (num5) { case -1: break; case 0: Found = false; Searching = false; return; default: AStarRec rec; this.Grid[num2, num3] = num4; if ((Math.Abs((int)(this.Goal.X - num2)) + Math.Abs((int)(this.Goal.Y - num3))) < ClosestgPoint.w) { ClosestgPoint.pt.X = num2; ClosestgPoint.pt.Y = num3; ClosestgPoint.w = Math.Abs((int)(this.Goal.X - num2)) + Math.Abs((int)(this.Goal.Y - num3)); } rec.pt = new Point(); rec.pt.X = num2; rec.pt.Y = num3; rec.w = num4; this.AStack.Add(rec); break; } } } }
private void LookForPath() { bool searching = false; bool found = false; AStarRec closestgPoint = new AStarRec(); closestgPoint.w = 2147483647; do { if (!searching) { this.InspectBlock(this.Source.X, this.Source.Y, ref found, ref searching, ref closestgPoint); searching = true; } else { if (this.AStack.Count == 0) { throw new Exception(string.Format("Could not calculate path from [" + this.Source.X + "," + this.Source.Y + "] to [" + this.Goal.X + "," + this.Goal.Y + "]")); } int index = 0; for (int i = 0; i < this.AStack.Count; i++) { if (this.AStack[i].w < this.AStack[index].w) { index = i; } } int x = this.AStack[index].pt.X; int y = this.AStack[index].pt.Y; int w = this.AStack[index].w; this.AStack.RemoveAt(index); this.InspectBlock(x, y, ref found, ref searching, ref closestgPoint); } } while (!found); }