Tower Of Hanoi Program In C Using Graphics

Tower Of Hanoi - Graphics in C Hello Friends, This is simple Tutorial about Graphics in C with example program 'Tower of Hanoi' problem. Hope you all know about tower of Hanoi problem. If you don't know, google it:) or visit this wikipedia page: Tower Of Hanoi. Draw a Hanoi in C graphic with Code. A single mouse click will be handled then the program will hit the. Tagged c graphic towers-of-hanoi or ask your.

23 Oct 2008CPOL
Shows how to solve Towers of Hanoi puzzle visually using Win32 and C++

Introduction

Towers of Hanoi is a puzzle game where there are three stands, each holds number of plates.
The idea here is that you have to move plates in the first stand to the third one, while moving plates you must consider:

  1. Size order, meaning when moving a plate you can't put it on a smaller one.
  2. Only one plate can be moved at each step.
Tower of hanoi program in java

Please note that I used the recursive method.

Announcing West Coast Express Travelling to a PC near you soon, First Class Simulations is pleased to announce the imminent arrival of West Coast Express (London to Birmingham Part 1). Developed by the UK's leading Train Sim team, European Bahn, the West Coast Main Line is the busiest mixed traffic railway in the UK. West Coast Express Part 1: London to Birmingham - Add-On for MS Train Simulator (PC CD): West Coast Express: Amazon.co.uk: PC & Video Games. From Excalibur's range of train simulator add-ons, the West Coast Express adds 120 miles of track and more than 25 stations to Microsoft Train Simulator for PC. West coast express transportation.

Background

Formally, Towers of Hanoi recursive function was given by :

And here is a conceptual image :

Using the Program

When you launch the application, you will see the next screen:

Then you have to select whether to let the program step into the solution automatically or not.

Using the Code

While implementing the program, I faced a problem in separating steps since I used the recursive version, so I decided to keep the recursive way. But the call to Hanoi method will happen just first time when 'next' or 'solve' button is pressed. Inside the Hanoi method, I stored the states of the solution, meaning each time a call happens, the solution of the current step is stored in a list of integers. Since each step in the Hanoi method requires 4 parameters as mentioned above, 4 integers represent parameter is added to the list. Then each time SolveNextStep method is called, the program reads from the list 4 items that represent the state.

Available classes are as follows:

Toshiba external dvd drive. 8x DVD+RW / 24x CD-Rewritable Supported disc: DVD-RAM, DVD±R, DVD±RW, DVD±R DL, CD-R, CD-RW, CD-ROM Buffer memory: 2 MB Application support: Microsoft® Windows® XP, Windows Vista®, Windows® 7 WinDVD® (DVD player), BurnNow™ (Burning CD/DVD) Dimension: 14.8 x 2.0 x 14.5 cm Weight: 325 g System requirement: Microsoft® Windows® XP (SP 1.0 or above) Windows Vista®, Windows® 7 Intel® Pentium® 4 2GHz or above Intel® Atom™ Processor 1.6GHz, 256MB RAM or higher (1GB recommended) USB 2.0 port Box content: Portable SuperMulti Drive USB Y-Cable CD (incl. 5x DVD-RAM / 6x DVD-RW, ±R DL Max. 8x DVD±R, ±RW, ±R DL Write Speed Max.

  1. HanoiDrawer
  2. PlateGUIInfo
  3. Tools

Anyway I'll describe methods in HanoiDrawer class that are responsible directly for solving the puzzle.

HanoiDrawer Class

Improvements

Code
  • The user has the ability to drag and drop the plates, then the program should verify user choice.

Sample Program In C Language

Notices

Tower Of Hanoi Algorithm

  • I tried to focus into the main idea of how I implemented the puzzle to ease understanding of my code. I didn't mention anything about window related tasks.
  • Conceptual image is created by MG from Wikipedia:

Tower Of Hanoi C++ Program

History

  • v1.0 14/7/2007: Main core and functionality