Esempio n. 1
0
        // Kdekoliv, kde si potrebuju vypsat seznamPozic v textovem formatu
        public string VratJakoText()
        {
            string result = "[";

            for (int i = 0; i < seznamPozic.Count(); ++i)
            {
                Pozice p = seznamPozic[i];
                result = result + p.VratJakoText();
            }
            result = result + "]";

            return(result.ToUpper());
        }
Esempio n. 2
0
        // pouziti pozdeji v metodach GenerujTahy, GenerujNejlepsiTah
        public bool vratTahZpet(Tah tah)
        {
            Pozice        odkud       = null;
            List <Pozice> seznamPozic = new List <Pozice>(tah.GetSeznamPozic);

            seznamPozic.Reverse();
            List <Pozice> preskoceneKameny = new List <Pozice>(tah.GetPreskoceneKameny);

            foreach (Pozice kam in seznamPozic)
            {
                if (odkud != null)
                {
                    Pozice preskocena = new Pozice();

                    if (preskoceneKameny.Count() == 0)
                    {
                        preskocena = null;
                    }
                    else
                    {
                        preskocena = preskoceneKameny.Last();
                        int index = preskoceneKameny.Count() - 1;
                        preskoceneKameny.RemoveAt(index);
                    }
                    if (!VratZpetPosunKamene(odkud, kam, preskocena))
                    {
                        MessageBox.Show("VYJIMKA: metoda vratTahZpet byla zavolana pro neplatny tah!");
                        MessageBox.Show("vratTahZpet Odkud: " + odkud.VratJakoText() + "vratTahZpet Kam: " + kam.VratJakoText() + "vratTahZpet preskocena: " + preskocena);

                        throw new Exception("metoda vratTahZpet byla zavolana pro neplatny tah!");
                    }
                }
                odkud = kam;
            }
            return(true);
        }