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:
- Users cannot manually play the puzzle.
- There is no way to step through or pause the automatic solver.
- An Undo feature is missing.
- 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
- Main Menu: Add a menu prompt at startup:
[1] Play Manually
[2] Auto-Solve (Step-by-Step / Animated)
[3] Exit
- 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 ===).
- 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.
- 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.
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:
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:
Enter).Suggested Implementation
[1] Play Manually[2] Auto-Solve (Step-by-Step / Animated)[3] Exitdraw_towers(towers, n)that prints the towers vertically (e.g., representing disks of sizedusingdblocks like===).Enter move (e.g., 'A B' to move, 'U' to undo, 'Q' to quit).[(from_tower, to_tower), ...]. Pop from this stack to reverse moves when the user entersU.input("Press Enter for next move...")) before executing each step.