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<OpenL> OpenList = new List<OpenL>(); // a priority queue of nodes to be transversed (Parent, cost F, cumulative G).
List<OpenL> OpenList2 = new List<OpenL>(); // a priority queue of nodes to be transversed (Parent, cost F, cumulative G).
List<int> ClosedList = new List<int>(); // 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));
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}