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.
- 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. โธ๏ธ
โถ๏ธ โ
- 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. ๐
- 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. ๐ฉ
- 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. ๐ข
- 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. โก๏ธ
- 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. โธ๏ธ
โถ๏ธ โ
To use this project, you need a web environment. Follow these steps to get started:
git clone https://github.com/your-username/tower-of-hanoi.git