public Prohledavacka(Stav pocatecniStav, Vektor cil, bool[,] bludiste) { this.cil = cil; this.bludiste = bludiste; aktualniStav = pocatecniStav; frontaStavu.Enqueue(aktualniStav); }
public static Stav PrectiSkladiste(out bool[,] bludiste, out Vektor cil) { Vektor skladnik = null, bedna = null; bludiste = new bool[10, 10]; cil = null; for (int y = 0; y < 10; y++) { for (int x = 0; x < 10; x++) { int c = Console.Read(); switch (c) { case 'X': bludiste[x, y] = true; break; case 'C': cil = new Vektor(x, y); break; case 'S': skladnik = new Vektor(x, y); break; case 'B': bedna = new Vektor(x, y); break; } } Console.ReadLine(); } return(new Stav(skladnik, bedna, 0)); }
void PohniSeSmerem(Vektor smer) { Vektor novySkladnik = aktualniStav.Skladnik.Posun(smer); Vektor novaBedna = aktualniStav.Bedna; if (JeTamZed(novySkladnik) || (JeTamBedna(novySkladnik) && !LzePosunoutBednuSmerem(smer))) { return; } if (JeTamBedna(novySkladnik)) { novaBedna = novaBedna.Posun(smer); } Stav novyStav = new Stav(novySkladnik, novaBedna, aktualniStav.Vzdalenost + 1); frontaStavu.Enqueue(novyStav); }
bool LzePosunoutBednuSmerem(Vektor smer) { Vektor posun = aktualniStav.Bedna.Posun(smer); return(!JeTamZed(posun)); }
bool JeTamBedna(Vektor kde) { return(kde.Equals(aktualniStav.Bedna)); }
bool JeTamZed(Vektor kde) { return(kde.X < 0 || kde.X >= 10 || kde.Y < 0 || kde.Y >= 10 || bludiste[kde.X, kde.Y]); }
public Stav(Vektor skladnik, Vektor bedna, int vzdalenost) { Skladnik = skladnik; Bedna = bedna; Vzdalenost = vzdalenost; }
public Vektor Posun(Vektor kam) { return(new Vektor(X + kam.X, Y + kam.Y)); }