This is primarily a digital design exercise. Verilog is the tool you will use to explore and test your design ideas - but the real effort is in creating a digital architecture.
You are going to implement a "Tower of Hanoi" move generator.
This game is well-known and so the web has many references. The origin of the problem is described here and its inventor is described here - and you can play the game here . In the emacs-based editor, you can watch a game run by typing: ESC x hanoi RETURN to run it with the default number of rings or ESC 5 ESC x hanoi RETURN to run it with, for example, 5 rings; students in the GateWay laboratory will find an entry for Hanoi under the Verilog menu in their editor.
In brief, this is a classical problem used to illustrate recursive programming techniques - however, a paper has recently been published by Chedid and Mogi[1] which shows how the algorithm may be converted to a simple iterative form which, in turn, seems to underpin a digital architecture for generating the sequence of moves. The iterative algorithm is reproduced below from [1] (in a sort of pseudo-Pascal) for information:
{ Move stack from peg 1 to peg 3 } Procedure ITERATIVE_HANOI: Let FromPeg, ToPeg be array [1 ... n] of 1 ... 3; Set FromPeg to {1, 1, 1, 1, ... 1} If n is odd then Set ToPeg to {3, 2, 3, 2, ... 3} Else Set ToPeg to {2, 3, 2, 3, ... 3} For i := 1 to (2^(n-1)) do begin Find the largest d (1 <= d <= n) such that i mod 2^(d-1) = 0 Move disk d from peg FromPeg[d] to peg ToPeg[d]; case[FromPeg[d], ToPeg[d]] of [1,2] FromPeg[d] := 2 ToPeg[d] := 3; [2,1] FromPeg[d] := 1 ToPeg[d] := 3; [1,3] FromPeg[d] := 3 ToPeg[d] := 2; [3,1] FromPeg[d] := 1 ToPeg[d] := 2; [2,3] FromPeg[d] := 3 ToPeg[d] := 1; [3,2] FromPeg[d] := 2 ToPeg[d] := 1; end; {case} end; {for} end; {procedure}
Your task is to design a digital circuit (down to gate-level: booleans and a purely synchronous Dtype) which generates the moves for a 5 disc Tower of Hanoi game. You may, if you wish, discuss/consider how this design could be adapted for different numbers of discs - but the main thrust of your work should be for the number 5.
There are two deliverables:
Please note: the latter will be marked for the design method, the clarity of the code and the excellence of the digital design.
I have a solution - and in creating my solution I did certain things which helped me. Your solution may be different from mine and so these hints may not apply to you but, for what they are worth, here they are:
Good luck - and HAPPY NEW YEAR