private void ProbourejSteny(Random rnd) { Bunka pokracovaciBunka = cesta.Pop(); do { if (pokracovaciBunka != null) { bool[] pouzite = pokracovaciBunka.vratPouzitiSousednichBunek(bludiste); int count = 0; for (int m = 0; m < pouzite.Length; m++) { if (pouzite[m]) { count++; } } if (count == 4) { pokracovaciBunka = null; continue; } bool[] otestovano = new bool[4]; int nahodnysmer = rnd.Next(0, 3); Point p3 = Bunka.getNewPosition(pokracovaciBunka.i, pokracovaciBunka.j, nahodnysmer); do { int g = 0; for (int k = 0; k < otestovano.Length; k++) { if (otestovano[k]) { g++; } } if (g == 4) { break; } int irandom = rnd.Next(0, 1000); if (irandom <= 250) { nahodnysmer = 0; } else if (irandom <= 500) { nahodnysmer = 1; } else if (irandom <= 750) { nahodnysmer = 2; } else if (irandom <= 1000) { nahodnysmer = 3; } p3 = Bunka.getNewPosition(pokracovaciBunka.i, pokracovaciBunka.j, nahodnysmer); int counter = 0; int correctSmer = -1; for (int c = 0; c < pouzite.Length; c++) { if (pouzite[c]) { counter++; } else { correctSmer = c; } } otestovano[nahodnysmer] = true; if (counter == 3) { nahodnysmer = correctSmer; } } while (pouzite[nahodnysmer] || !Bunka.jsemVBludisti(p3, bludiste)); Point p4 = Bunka.getNewPosition(pokracovaciBunka.i, pokracovaciBunka.j, nahodnysmer); if (!Bunka.jsemVBludisti(p4, bludiste)) { pokracovaciBunka = null; continue; } for (int a = 0; a < pouzite.Length; a++) { if (a != nahodnysmer) { if (!pouzite[a]) { Point p = Bunka.getNewPosition(pokracovaciBunka.i, pokracovaciBunka.j, a); if (Bunka.jsemVBludisti(p, bludiste)) { cesta.Push(bludiste[p.Y, p.X]); } } } } pokracovaciBunka.Pruchod[nahodnysmer] = true; Point p2 = Bunka.getNewPosition(pokracovaciBunka.i, pokracovaciBunka.j, nahodnysmer); pokracovaciBunka = bludiste[p2.Y, p2.X]; pokracovaciBunka.Pruchod[Bunka.InverzniSmer(nahodnysmer)] = true; if (animovatbludiste) { Invalidate(); System.Threading.Thread.Sleep(zdrzeni); Application.DoEvents(); } } else { pokracovaciBunka = cesta.Pop(); } } while (cesta.Count != 0); }