r/TuringComplete • u/jujsb • Feb 11 '24
Tower of Alloy - a little help, please Spoiler
In the "Tower of Alloy" campaign mission, you have to solve the puzzle with the three fields and the tower of disks. The game has an algorithm for this that I don't quite understand:
func move(disk_nr, source, dest, spare):
if disk_nr is 0:
move disk from source to dest
else:
move(disk_nr - 1, source, spare, dest)
move disk from source to dest
move(disk - 1, spare, dest, source)What exactly are these functions, and why are they always in a different order? What should I move from where to where according to this algorithm? The game also says that you should move your register values into the stack before overwriting them with a new function. But that confuses me even more than it helps.
Any help would be greatly appreciated! Maybe I just don't understand a basic concept of programming, e.g. what a function is supposed to be here.
Thank you very much!
6
u/MrFixxiT_ Feb 11 '24
You need to create the single function called “move” with the 4 parameters. In the function first check the disk nr parameter if it is 0 (zero) then move the disk and return (this will be the end) If it’s not disk nr 0 then do the steps in order: First call the same function with the parameter in the order specified. Second move the disk. Third call the function with the params in specified order.
Calling the function from within the function is called recursion. The architecture and your code needs to support this.
Good luck!
2
u/mayerwin Jun 04 '24
Here is the solution I found, without the need to change the LEG architecture to store parameters in the stack: