Skip to content

💡 [Feature]: Adding Manual Solver & Step Feature In Tower of Hanoi CLI version #565

@developer-yash03

Description

@developer-yash03

Problem Statement

The current Python CLI version of the Tower of Hanoi (Tower-of-Hanoi.py) only performs an automated, instantaneous solve. It lacks the rich interactivity found in the web-app version:

  1. Users cannot manually play the puzzle.
  2. There is no way to step through or pause the automatic solver.
  3. An Undo feature is missing.
  4. The visualization is represented as raw Python lists (Tower A: [3, 2, 1]) instead of a user-friendly graphical or ASCII art interface.

Proposed Enhancement

Just like the Web-App version enhanced in PR #483,
Enhance the Python CLI game by adding:

  • Interactive Mode: Let users play the game manually by selecting source and destination towers.
  • Manual/Step-by-Step & Delayed Solver: Allow users to either watch the solver with a short delay between moves or step through it manually (e.g., by pressing Enter).
  • Undo Move Support: Keep a history of moves so users can undo their mistakes during manual play.
  • ASCII Art Rendering: Render the towers and disks vertically using ASCII characters for a much clearer visual representation.

Suggested Implementation

  1. Main Menu: Add a menu prompt at startup:
    • [1] Play Manually
    • [2] Auto-Solve (Step-by-Step / Animated)
    • [3] Exit
  2. ASCII Visualization: Implement a helper function draw_towers(towers, n) that prints the towers vertically (e.g., representing disks of size d using d blocks like ===).
  3. Interactive Loop:
    • Prompt the user: Enter move (e.g., 'A B' to move, 'U' to undo, 'Q' to quit).
    • Maintain a history stack of moves [(from_tower, to_tower), ...]. Pop from this stack to reverse moves when the user enters U.
    • Validate moves: ensure the source tower is not empty and the disk being moved is smaller than the top disk of the destination tower.
  4. Auto-Solver with Control:
    • Modify the solving loop to accept a step-interval input or pause for keypresses (input("Press Enter for next move...")) before executing each step.

  • I am a registered GSSoC 2026 contributor.
  • I would like to implement this feature myself.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions