private void saveLogs(long elapsedMs, IList <Vector2> sciezka)
        {
            using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"pomiar\logs-times.txt", true))
            {
                file.WriteLine("Najkrotsza droga A czas[ms]: " + elapsedMs);
            }
            string fileName = @"pomiar\A-wyniki.txt";

            using (System.IO.StreamWriter file = new System.IO.StreamWriter(fileName))
            {
                if (sciezka != null)
                {
                    file.WriteLine("Wypisanie po algorytmie: ");
                    file.WriteLine("Sciezka: ");
                    foreach (var el in sciezka)
                    {
                        file.Write(el + " (" + ServiceData.posInTable(el) + ") " + ", ");
                    }
                }
                else
                {
                    file.WriteLine("Sciezka nie znaleziona ");
                }
            }
        }
        public IList <Vector2> FindWay(Vector2 from, Vector2 to, MapData map, bool useList)
        {
            IList <Vector2> list  = new List <Vector2>();
            int             DEST  = ServiceData.posInTable(to);
            int             START = ServiceData.posInTable(from);
            //Debug.Log("start " + START + " dest " + DEST);

            var watch = System.Diagnostics.Stopwatch.StartNew();

            int wielkoscGrafu = ServiceData.NewTabLength;

            // int[] odl = new int[ServiceData.NewTabLength];         // aktualna najmniejsza odleglosc
            int[] odleglosc = new int[wielkoscGrafu];
            int[] poprzedni = new int[wielkoscGrafu];
            int[] wezly     = new int[wielkoscGrafu];

            for (int i = 0; i < ServiceData.NewTabLength; i++)
            {
                odleglosc[i] = poprzedni[i] = ServiceData.INF;
                wezly[i]     = i;
            }

            odleglosc[START] = 0;

            if (!useList)
            {
                do
                {
                    int najmniejsza   = wezly[0];
                    int smallestIndex = 0;
                    for (int i = 1; i < wielkoscGrafu; i++)
                    {
                        if (odleglosc[wezly[i]] < odleglosc[najmniejsza])
                        {
                            najmniejsza   = wezly[i];
                            smallestIndex = i;
                        }
                    }
                    wielkoscGrafu--;
                    wezly[smallestIndex] = wezly[wielkoscGrafu];

                    //Debug.Log("wywolanie ");
                    if (odleglosc[najmniejsza] == ServiceData.INF || najmniejsza == DEST)
                    {
                        //Debug.Log("break | dist " + odleglosc[najmniejsza] + " smallest " + najmniejsza);
                        break;
                    }


                    for (int i = 0; i < wielkoscGrafu; i++)
                    {
                        int v       = wezly[i];
                        int newDist = odleglosc[najmniejsza] + ServiceData.macierzSasiedztwa[najmniejsza][v];
                        if (newDist < odleglosc[v])
                        {
                            odleglosc[v] = newDist;
                            poprzedni[v] = najmniejsza;
                        }
                    }
                } while (wielkoscGrafu > 0);
            }
            else
            {
                do
                {
                    int najmniejsza   = wezly[0];
                    int smallestIndex = 0;
                    for (int i = 1; i < wielkoscGrafu; i++)
                    {
                        if (odleglosc[wezly[i]] < odleglosc[najmniejsza])
                        {
                            najmniejsza   = wezly[i];
                            smallestIndex = i;
                        }
                    }
                    wielkoscGrafu--;
                    wezly[smallestIndex] = wezly[wielkoscGrafu];

                    //Debug.Log("wywolanie ");
                    if (odleglosc[najmniejsza] == ServiceData.INF || najmniejsza == DEST)
                    {
                        //Debug.Log("break | dist " + odleglosc[najmniejsza] + " smallest " + najmniejsza);
                        break;
                    }

                    foreach (var i in ServiceData.listaIncydencji[najmniejsza])
                    {
                        int v       = wezly[i];
                        int waga    = ServiceData.listaIncydencji[najmniejsza].Where(f => f == v).FirstOrDefault();
                        int newDist = odleglosc[najmniejsza] + (waga == 0 ? ServiceData.INF : 1);
                        if (newDist < odleglosc[v])
                        {
                            odleglosc[v] = newDist;
                            poprzedni[v] = najmniejsza;
                        }
                    }
                } while (wielkoscGrafu > 0);
            }



            watch.Stop();
            var elapsedMs = watch.ElapsedMilliseconds;

            int[] sciezka = OdtworzSciezke(poprzedni, START, DEST);
            saveLogs(elapsedMs, odleglosc, poprzedni, wezly, sciezka, useList);
            foreach (var elem in sciezka)
            {
                list.Add(ServiceData.posInTableToVector(elem));
                //Debug.Log("pkt " + ServiceData.posInTableToVector(elem));
            }
            return(list);
        }
        public IList <Vector2> FindWay(Vector2 from, Vector2 to, MapData map, bool useList)
        {
            IList <Vector2> list  = new List <Vector2>();
            int             DEST  = ServiceData.posInTable(to);
            int             START = ServiceData.posInTable(from);
            //Debug.Log("start " + START + " dest " + DEST);

            var watch = System.Diagnostics.Stopwatch.StartNew();

            Queue <int> q             = new Queue <int>();
            int         wielkoscGrafu = ServiceData.NewTabLength;

            // int[] odl = new int[ServiceData.NewTabLength];         // aktualna najmniejsza odleglosc
            int[] odleglosc = new int[wielkoscGrafu];
            int[] poprzedni = new int[wielkoscGrafu];
            int[] wezly     = new int[wielkoscGrafu];

            for (int i = 0; i < ServiceData.NewTabLength; i++)
            {
                odleglosc[i] = poprzedni[i] = ServiceData.INF;
                wezly[i]     = i;
            }

            odleglosc[START] = 0;

            if (!useList)
            {
                for (int i = 1; i < wielkoscGrafu - 1; i++)
                {
                    for (int w1 = 0; w1 < wielkoscGrafu; w1++)
                    {
                        for (int w2 = 0; w2 < wielkoscGrafu; w2++)
                        {
                            if (ServiceData.macierzSasiedztwa[w1][w2] != 0)
                            {
                                int tmp = odleglosc[w2] + ServiceData.macierzSasiedztwa[w1][w2];
                                if (odleglosc[w1] > tmp)
                                {
                                    odleglosc[w1] = tmp;
                                    poprzedni[w1] = w2;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                for (int i = 1; i < wielkoscGrafu - 1; i++)
                {
                    for (int w1 = 0; w1 < wielkoscGrafu; w1++)
                    {
                        foreach (var w2 in ServiceData.listaIncydencji[w1])
                        {
                            int waga = w2;
                            if (waga != 0)
                            {
                                //Debug.Log(" waga "+ waga + " w2 " + w2 + " w1 " + w1);
                                int tmp = odleglosc[w2] + 1;
                                // Debug.Log(" ustawiam " + odleglosc[w1] + " odl" + (odleglosc[w2] + 1));
                                if (odleglosc[w1] > tmp)
                                {
                                    odleglosc[w1] = tmp;
                                    poprzedni[w1] = w2;
                                }
                            }
                        }
                    }
                }
            }



            watch.Stop();
            var elapsedMs = watch.ElapsedMilliseconds;

            int[] sciezka = OdtworzSciezke(poprzedni, START, DEST);
            saveLogs(elapsedMs, odleglosc, poprzedni, wezly, sciezka, useList);
            foreach (var elem in sciezka)
            {
                list.Add(ServiceData.posInTableToVector(elem));
                //Debug.Log("pkt " + ServiceData.posInTableToVector(elem));
            }
            return(list);
        }