A visual, interactive implementation of both the classic Towers of Hanoi and an extended variant, built using JavaFX in IntelliJ IDEA.
Towers of Hanoi is a classic recursive puzzle involving:
- 3 pegs
- A stack of disks (different sizes) on one peg
- The goal: move the entire stack to another peg
- Only one disk may be moved at a time.
- Only the top disk can be moved.
- A larger disk may not be placed on a smaller one.
The minimum number of moves required is 2^n - 1
, where n
is the number of disks.
In this project, we implement not only the classic version, but also an Extended Towers of Hanoi variant — a custom recursive formulation that:
- Repeats the standard 3-step recursion, both forward and in reverse
- Does not aim for minimal move count, but instead emphasizes recursive depth and disk activity
- Produces a longer sequence of moves, showing off the process more dramatically
- Makes recursion behavior more visible
- Useful for educational demonstration
- Offers a contrast with the minimal-move classic version
- Enables a more engaging animation for larger disk counts
In code:
Hanoi(...)
: classic algorithm (minimal solution)exHanoi(...)
: extended version (longer, richer sequence)
- Choose number of disks at launch
- Visual board with animated pegs and disks
- Manual or automated solution playback
- Pause, resume, and restart functionality
- Clean JavaFX + FXML UI using JFoenix buttons
- Java 17+ or 21
- JavaFX (controls + FXML)
- JFoenix (for styled buttons)
- Built in IntelliJ IDEA
- Open the project in IntelliJ IDEA.
- Set the Project SDK to JDK 17 or newer.
- Run the
Main
class.