Skip to content

ErfanZmp/Extended-Hanoi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Extended Towers of Hanoi Visualization

Overview

This project is an interactive visualization of the Extended Towers of Hanoi problem, a variation of the classic Towers of Hanoi puzzle. Built using Python and the customtkinter library, it provides a graphical interface to demonstrate the algorithm's solution with animated disk movements across three towers. Users can select the number of disks, control animation speed, and pause, resume, or reset the simulation.

The Extended Towers of Hanoi introduces a more complex sequence of moves compared to the traditional version, making it an engaging tool for exploring recursive algorithms and their visual representation.

Features

  • Interactive GUI: A clean, modern interface built with customtkinter for selecting disk count and controlling the simulation.
  • Animated Visualization: Smooth animations of disk movements between towers, with customizable speed via a slider.
  • Dynamic Disk Colors: Each disk is assigned a random color for better visual distinction.
  • Control Options: Start, pause, resume, reset, and return to the home screen for a seamless user experience.
  • Threaded Execution: Uses threading to ensure smooth animations without freezing the GUI.
  • Responsive Design: Adapts to various screen sizes with a minimum window size of 750x650 pixels.

Requirements

To run this project, ensure you have the following installed:

  • Python 3.8+
  • customtkinter library

Install the required library using:

pip install customtkinter

Installation

  1. Clone the repository:
    git clone https://github.com/ErfanZmp/Extended-Hanoi.git
  2. Navigate to the project directory:
    cd Extended-Hanoi
  3. Install dependencies:
    pip install customtkinter
  4. Run the application:
    python main.py

Usage

  1. Launch the application using python main.py.
  2. On the home screen, select the number of disks (1–10) from the dropdown menu and click "Run."
  3. In the main interface:
    • Use the Start/Pause/Resume button to control the simulation.
    • Use the Reset button to restart the simulation with the selected number of disks.
    • Adjust the animation speed using the slider (1–25).
    • Click Back to return to the home screen.
    • Click Exit to close the application.
  4. Watch the animated solution to the Extended Towers of Hanoi problem as disks move between towers A, B, and C.

Project Structure

  • main.py: Entry point of the application, initializes the GUI and handles navigation between home and main frames.
  • hanoi.py: Implements the Extended Towers of Hanoi algorithm and the standard Hanoi algorithm for recursive solving.
  • models.py: Defines the Disk, Tower, and Move classes for managing the game state and animations.

Algorithm Details

The Extended Towers of Hanoi algorithm (ExHanoi) extends the classic Towers of Hanoi by introducing additional moves for each disk size. For n disks:

  • If n = 1, a specific sequence of five moves is executed to transfer the disk.
  • For n > 1, the algorithm recursively solves for n-1 disks, calls the standard Hanoi algorithm for intermediate steps, and performs additional moves.

The standard Hanoi algorithm is used as a subroutine within ExHanoi to handle specific move sequences. The visualization animates each move, showing disks being lifted, moved horizontally, and placed on the target tower.

Screenshots

Below are some screenshots of the Extended Towers of Hanoi visualization in action:

Home Screen

Home Screen Select the number of disks to start the simulation.

Simulation in Progress

Simulation Screen Watch the disks move between towers A, B, and C.

Paused State

Paused Screen Pause the simulation to inspect the current state.

Contributing

Contributions are welcome! To contribute:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix:
    git checkout -b feature/your-feature-name
  3. Commit your changes:
    git commit -m "Add your feature description"
  4. Push to your branch:
    git push origin feature/your-feature-name
  5. Open a pull request with a detailed description of your changes.

Please ensure your code follows the existing style and includes appropriate comments.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgments

  • Built with customtkinter for a modern GUI experience.
  • Inspired by the classic Towers of Hanoi puzzle and its extended variations.

Contact

For questions or feedback, please open an issue on GitHub or contact erfanzamirpour@gmail.com.


Happy puzzling!

About

Graphical Representation of Extended Hanoi Algorithm

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages