public class OpenL { public int Current { get; set; } public int Parent { get; set; } public float F { get; set; } public float G { get; set; } } //Algorytm A* Punkt poczatek = punkty.punkty[0]; Punkt koniec = punkty.punkty[1]; Punkt sasiad = punkty.punkty[0]; int index = 0; int koszt = 1000; int koszt_save = 1000; bool bylo = false; int index_save = 0; var xd = new OpenL { }; //Heuristic H odleglosc(Node, End); //Movement cost G odleglosc(currentNode, neighbour); //Total cost F F = H(neighbourToEnd) + G; List OpenList = new List(); // a priority queue of nodes to be transversed (Parent, cost F, cumulative G). List OpenList2 = new List(); // a priority queue of nodes to be transversed (Parent, cost F, cumulative G). List ClosedList = new List(); // a list of nodes already transversed. OpenList.Add(new OpenL { Current = 0, Parent = 0, F = odleglosc(poczatek, koniec) + 0, G = 0 }); do { foreach (var item in OpenList) { for (int i = 0; i < punkty.rozmiar - 1; ++i) { xd = new OpenL { Current = item.Current, Parent = item.Parent, F = item.F, G = item.G }; jest_droga = false; bylo = false; index = item.Current; Punkt currentNode = punkty.punkty[index]; Punkt neighbour = punkty.punkty[i]; int odl = odleglosc(currentNode, neighbour); if (odl != 0 && odl < odl_max) { jest_droga = true; line(currentNode, neighbour); if (jest_droga) { foreach (var item2 in OpenList2) { if (item2.Current == i) bylo = true; } if (!bylo) { OpenList2.Add(new OpenL { Current = i, Parent = index, F = odleglosc(neighbour, koniec) + odl, G = odl }); } koszt = odleglosc(neighbour, koniec) + odl; if (koszt < koszt_save) { index_save = index; koszt_save = koszt; } } } sasiad = punkty.punkty[index_save]; using (var graphics = Graphics.FromImage(image1)) { graphics.DrawLine(bluePen, currentNode.x, currentNode.y, sasiad.x, sasiad.y); pictureBox1.Image = image1; pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; } } } OpenList2 = OpenList; OpenList.Remove(xd); OpenList2.Remove(xd); } while ((sasiad.x != koniec.x) && (sasiad.y != koniec.y));