Python Programming Project
Tower of Hanoi
01. IntroductionOveriew
During this project, you will work to create a program which can render a visual demonstration of the Tower of Hanoi puzzle in pygame and create a solver which will help to solve the puzzle
Overall through the course of this project, you will learn several concepts such as recursion, recursive algorithms and list manipulation, which you will then combine to create your solver.
You will also learn how to code your own program in python through using pygame to render a visual representation of the game.
Tower of Hanoi (also known as Lucas’ Tower) is a famous mathematical game/puzzle introduced in the 19th century. In this project we will make use of the traditional version of the game with 3 poles.
The aim of our game is to pick up all of the plates from pole number 1 and move onto the last pole. Here we have 8 disk that stack on top of each other. If you find that simple, think again! There are certain rules we have to obey when we move our plates.
Rules:
1. You can pick up one plate and move it from pole to pole at any time.
2. You can only pick up disks that are on top of the stack.
3. Larger disks cannot be on top of smaller disk.
This can be seen in the diagram below
Rules Illustrations:
(Note: If the teacher has the actual game which the students can work with hands-on, it may help them in visualizing the game and its rules.)
In order to build our visual demonstration, we will be using the Python programming language.
In particular, we will be using a collections of tools (commonly called “libraries”) that has already been built for us: Pygame.
As the name suggests, it was made specifically to create games (think of lego blocks). They can aid us in to produce any sounds, visual graphics and interaction between the computer and the player that we desire.
As you may know, computer programs carry out a list of instructions called “Algorithm” in order to achieve its task. Efficient algorithms can help you to solve huge problems very quickly!
In this project, you first should learn how to solve the game, then express the steps in code so that the computer can also do it. Using strategic approaches will help you to solve your game much faster, as opposed to randomly moving the disks about. In this game, the minimum number of moves is exactly 2n – 1, n being the number of disks.
Consider: How do you know that it is 2n – 1?