Ejemplo n.º 1
0
        public void MoveDisks(int n, Tower dest, Tower buffer)
        {
            if (n > 0)
            {
                MoveDisks(n - 1, buffer, dest);
                MoveTopToTower(dest);
                buffer.MoveDisks(n - 1, dest, this);

                if (Verbose)
                {
                    PrintTower();
                    dest.PrintTower();
                    buffer.PrintTower();
                }
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var t1 = new Tower {
                Name = "Tower 1", Verbose = true
            };
            var t2 = new Tower {
                Name = "Tower 2", Verbose = true
            };
            var t3 = new Tower {
                Name = "Tower 3", Verbose = true
            };

            t1.Add(6);
            t1.Add(5);
            t1.Add(4);
            t1.Add(3);
            t1.Add(2);
            t1.Add(1);

            Console.WriteLine("BEFORE GAME");
            t1.PrintTower();
            t2.PrintTower();
            t3.PrintTower();

            Console.WriteLine("MOVING DISKS");
            t1.MoveDisks(t1.Count, dest: t2, buffer: t3);

            Console.WriteLine("AFTER GAME");
            t1.PrintTower();
            t2.PrintTower();
            t3.PrintTower();

            Console.WriteLine("MOVING DISKS BACK TO ORIGINAL");
            t2.MoveDisks(t2.Count, dest: t1, buffer: t3);

            Console.WriteLine("AFTER GAME");
            t1.PrintTower();
            t2.PrintTower();
            t3.PrintTower();
        }