The "Tower of Hanoi" is an ancient mathematical puzzle. It can be patiently solved in 2n-1 steps where n is the number of disks on the starting peg.

It has an equally elegant recursive solution that will just use a LOT of computational resources to complete.

For these reasons it is "painful" to watch it unfold in front of our eyes while doing nothing.

So we can enjoy the time by listening to some music

Design a Windows Forms App (.NET Framework).

It should allow users to enter the number of disks (textbox) and view in output the list of moves (multiline textbox).

The application has 4 buttons to perform the following:

  • Start solving the Hanoi Tower
  • Cancel the solution (there are multiple ways of solving this problem with various "levels" of success. E.g. in the class example, or looking at Cancellation Tokens https://docs.microsoft.com/en-us/dotnet/standard/parallel-programming/task-cancellation)
  • Start Playing the music (in loop, i.e: restarting automatically after it ends)
  • Stop Playing the music

The main challenge of this application is to perform the tasks in an "asynchronous" fashion.

IMPORTANT: Remember that every time you want to modify a GUI control from a thread/task that is not the one that originated that control you MUST use a MethodInvoker .

Starting the computation of the Hanoi Tower should leave the user the possibility to stop it, and interact with the rest of the application (e.g. the music).

The same should happen while playing music.

To Play a sound file from within a Windows Form Application please refer to https://docs.microsoft.com/en-us/dotnet/desktop/winforms/controls/how-to-play-a-sound-from-a-windows-form

Use the .wav file attached that comes from: https://freesound.org/people/sonsbcnintercultural/sounds/256120/

(I find traditional Persian music very soothing.)

Load the file from the binary folder (e.g this.Player.SoundLocation = @"soundexample.wav";)

Please notice how some method calls for SoundPlayer are already "asynchronous".

The Form should have appropriate Access shortcuts (see Chapter 15 Section 15.2) for the 4 buttons (like Alt+P should activate the 'Play Music' button).

The controls should be enabled/disabled depending on the currently available functionalities.

Display the current progress toward the solution of the Tower (choose appropriate controls/implementations e.g.: percentage labels and progressbars, Hint: we know exactly how many moves we have to do)

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.