Esempio n. 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Problem hanojskih stolpov - Jernej Žagar");


            Console.WriteLine();
            byte i = 1;

            foreach (string stolp in Enum.GetNames(typeof(Tower)))
            {
                Console.WriteLine("     " + i + "   " + stolp);
                i++;
            }

            Console.WriteLine();
            Console.WriteLine("Izberi številko problema in pritisni Enter.");
            string izbira = Console.ReadLine();

            Console.WriteLine("Izberi število diskov in pritisni Enter.");
            string stDiskov = Console.ReadLine();
            int    discs    = Convert.ToInt32(stDiskov);

            Console.WriteLine("Izberi začetni stolp in pritisni Enter.");
            string startPeg = Console.ReadLine();
            byte   start    = Convert.ToByte(startPeg);

            Console.WriteLine("Izberi končni stolp in pritisni Enter.");
            string endPeg = Console.ReadLine();
            byte   final  = Convert.ToByte(endPeg);

            HanoiTower vrstaStolpa = HanoiTowerFactory.GetHanoiTower(izbira, discs, start, final);

            byte[] zacetnoStanje = ConvertNumbers.SetPosition(vrstaStolpa.Start, vrstaStolpa.Discs);


            Console.WriteLine("Začetek");
            DateTime dtStart = DateTime.Now;

            vrstaStolpa.DolzinaNajkrajsePoti(zacetnoStanje);

            DateTime dtEnd = DateTime.Now;

            Console.WriteLine("Konec");
            Console.WriteLine($"Čas izvajanja= {(dtEnd - dtStart).TotalSeconds}");
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            // Uporabnik izbere tip hanoiskega stolpa, ki ga shranimo v spremnljivko
            Console.WriteLine("Hanoi example ");
            HanoiType type = HanoiTypeModel.SelectHanoiType();

            // Uporabnik napiše število diskov, ki jih parsamo v int
            Console.Write("Enter number of discs: ");
            int k = int.Parse(Console.ReadLine());

            Console.WriteLine($"Running case: {type} with {k} discs:");

            // Delali bodo samo s štirimi stolpi
            int numPegs = 4;
            // Prikaz izvajanja časa programa
            Stopwatch sw = Stopwatch.StartNew();
            // Ustvarimo novi objekt tipa Hanoi, kateremu podamo prej določene spremnljivke
            //HanoiTowerSelection hanBasic = new HanoiTowerSelection(k, numPegs, type);
            // Na našem objektu kličemo funkcijo za določanje najkrajše poti
            // HanoiTowerFactory factory = null;
            HanoiTowerFactory factory2 = new HanoiTowerFactory();
            int length = factory2.HanoiTowerFactoryGet(k, numPegs, type);

            //type.HanoiTowerFactory();

            /* switch (type)
             * {
             *   case HanoiType.K13_01:
             *       {
             *           factory = new HanoiTypeK13_01(k, numPegs, type);
             *       }
             *
             *       break;
             *   case HanoiType.K13_12:
             *       {
             *           factory = new HanoiTypeK13_12(k, numPegs, type);
             *       }
             *       break;
             *
             *   case HanoiType.K13e_01:
             *   case HanoiType.K13e_12:
             *   case HanoiType.K13e_23:
             *   case HanoiType.K13e_30:
             *       {
             *           factory = new HanoiTypeK13e(k, numPegs, type);
             *       }
             *       break;
             *   case HanoiType.K4e_01:
             *   case HanoiType.K4e_12:
             *   case HanoiType.K4e_23:
             *       {
             *           factory = new HanoiTypeK4e(k, numPegs, type);
             *       }
             *       break;
             *   case HanoiType.C4_01:
             *   case HanoiType.C4_12:
             *       {
             *           factory = new HanoiTypeC4(k, numPegs, type);
             *       }
             *       break;
             *   case HanoiType.P4_01:
             *   case HanoiType.P4_12:
             *   case HanoiType.P4_23:
             *   case HanoiType.P4_31:
             *       {
             *           factory = new HanoiTypeP4(k, numPegs, type);
             *       }
             *       break;
             * }
             * //var length = factory.ProcessHanoiTowers(0, out _);*/

            Console.WriteLine();
            Console.WriteLine($"\n\nDimension: {k} ; Steps:  {length} ; Time {sw.Elapsed.TotalSeconds}");
            Console.WriteLine();

            Console.WriteLine();
            Console.WriteLine("Končano");
            Console.ReadLine();
        }