Skip to content

๐Ÿš€ Tower of Hanoi is an interactive, visually stunning puzzle game built with JavaScript & SVG! ๐Ÿงฉ Test your problem-solving skills and challenge yourself with smooth animations and step-by-step controls! ๐ŸŽฎ ๐Ÿ”— Play the game live: Live Demo ๐ŸŒ

Notifications You must be signed in to change notification settings

kanhaiya-22/Visualize-Tower-of-Hanoi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

5 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Tower of Hanoi - Interactive Puzzle Game ๐ŸŽฎ

Overview ๐ŸŒŸ

This project implements the classic Tower of Hanoi puzzle game using JavaScript and SVG (Scalable Vector Graphics). It includes an interactive interface with visual representations of disks and pegs, along with step-by-step controls, animations, and an optimized solution using dynamic programming.

Key Features โœจ

  • Interactive User Interface: Play the Tower of Hanoi game with a graphical SVG-based interface. ๐Ÿ–ผ๏ธ
  • Step-by-Step Mode: Allows users to control the game flow step-by-step. โฉ
  • Dynamic Programming: Optimized solution using dynamic programming for minimal moves. ๐Ÿ”ข
  • Disk Movement Animations: Smooth animations for moving disks between pegs. ๐ŸŽž๏ธ
  • Abort/Resume: Allows pausing, resuming, and aborting animations at any time. โธ๏ธ โ–ถ๏ธ โŒ

Technologies Used ๐Ÿ’ป

  • JavaScript (ES6+): For game logic, animations, and handling user interactions. ๐Ÿ”ฎ
  • SVG (Scalable Vector Graphics): For rendering the game's visual elements (disks, pegs, and base). ๐Ÿ–Œ๏ธ
  • HTML5: For structuring the game UI and appending the SVG elements. ๐ŸŒ
  • CSS: For basic styling, like rounding corners and adding drop shadows. ๐ŸŽจ
  • Async/Await: For handling asynchronous disk movements and animations. โณ
  • AbortController: To abort ongoing animations and allow user control over the game's flow. ๐Ÿšซ
  • Dynamic Programming: To calculate the optimal sequence of moves efficiently. ๐Ÿ“Š

How It Works ๐Ÿ”ง

1. Game Setup โš™๏ธ

  • The game is initialized with a configurable number of pegs and disks. ๐Ÿงฉ
  • Each disk is visually represented by a rectangle, and pegs are placed vertically. ๐ŸŸฆ
  • The base of the puzzle is rendered at the bottom. ๐ŸŸฉ

2. Game Logic ๐ŸŽฎ

  • The goal is to move all the disks from the first peg to the last peg, following the rules:
    • Only one disk can be moved at a time. ๐Ÿ”„
    • A larger disk cannot be placed on top of a smaller disk. ๐Ÿšซ
  • The solution is calculated using dynamic programming to minimize the number of moves. ๐Ÿ”ข

3. Disk Movement ๐ŸŽž๏ธ

  • Each disk's movement is animated with SVG's <animateMotion> tag. ๐Ÿƒโ€โ™‚๏ธ
  • The disk moves smoothly along a path calculated based on the starting and target peg positions. โžก๏ธ

4. Step-by-Step Mode โฉ

  • In step mode, users can manually progress the game one move at a time, providing more control over the puzzle-solving process. ๐Ÿ“…
  • Users can pause, resume, or abort the game at any time. โธ๏ธ โ–ถ๏ธ โŒ

Installation ๐Ÿ› ๏ธ

To use this project, you need a web environment. Follow these steps to get started:

1. Clone the Repository

git clone https://github.com/your-username/tower-of-hanoi.git

About

๐Ÿš€ Tower of Hanoi is an interactive, visually stunning puzzle game built with JavaScript & SVG! ๐Ÿงฉ Test your problem-solving skills and challenge yourself with smooth animations and step-by-step controls! ๐ŸŽฎ ๐Ÿ”— Play the game live: Live Demo ๐ŸŒ

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published