--- HANOI ---

Written by Sander Alsema for the 10-liner competition 2017.
Language: Commodore 64 Basic v2
Category: PUR-80


I prefer VICE, but you can use any emulator that works with *.d64 files.
If you haven't installed it yet, it can be downloaded from their website.

Here's how to use it:
 Click : - File
         - Attach disk image -> Drive 8
 Select: Tenliner.d64
 Click : Attach

Now, just as you would with a normal Commodore 64, you can type:
 LOAD"$",8           (to load the directory)
 LOAD"HANOI",8       (to load the HANOI game)
 LOAD"HANOI(LONG)",8 (to load the LONGVERSION of the HANOI game)
 LIST                (to view the directory or game listing)
 RUN                 (to run the game)

Be aware that you are now using a virtual Commodore 64 keyboard.
Therefore the keys will differ slightly from your physical keyboard:
use <SHIFT> '2' to display quotation marks.
use <SHIFT> '8' to display '('.
use <SHIFT> '9' to display ')'.

---

HANOI is a puzzle game, based on the towers of Hanoi.

According to the legend, an order of Buddhist monks in Hanoi has been working
on a very ambitious task. They have three poles and a collection of discs of
different sizes. Every disc has a hole in the middle, so that it can be placed
on one of the poles. Originally all discs were placed on the first tower.
The monks believe that when all discs are transferred to the third tower, they
will enter Nirvana.

Now, just by playing this game, you too can find enlightment!

The objective of the game: Move all discs from tower 1 to tower 3.

You can only move 1 disc at a time, from one tower to another.
Bigger discs can NOT be placed on smaller discs, the other way round is fine.

The player first types a number (1-3), to indicate which tower to move from.
The player then types a second number (1-3), to indicate which tower to move to.
If the player's move is illegal, he will be told so and has to enter a new move.

After the last move the player will be congratulated and can begin again.

---

I used a two-dimensional array to represent the towers.
The first number indicates the tower.
The second number indicates the level of each tower.
The cells where the second number is zero, point to the uppermost discs.


Line 0: Allocate memory for virtual towers.
	Fill first 'tower' with 'discs' (values that represent them).
	Clear the second tower.
	Clear the third tower.
	Use a variable for screen memory access to reduce line space in program.
	Set moves to zero.
	Set border colour to blue.

Line 1: Clear the screen.
	Display "MOVES:" in the top left corner, followed by the number of moves.
	Next text display will be 2 lines below previous.
	Place the indicating number for each tower on the screen.
	Build each tower from the ground up, starting with a pole in the middle.

Line 2: Check each tower level for discs.
	When found, display them over the pole, to the right and to the left.

Line 3: If the third tower is full then:
	- Display "WELL DONE!" on the screen.
	- Wait a short while.
	- Clear the keyboard buffer.
	- Start the game all over again.

Line 4: Display "WHERE FROM?" on the screen.
	Go 11 screen places back to the left, so that it can be over written.
	Read the keyboard.
	Turn keyboard stroke into a number (from).
	If that number is not 1, 2 or 3 then repeat this line.

Line 5: Display "WHERE TO?  " on the screen.
	Go 11 screen places back to the left, so that it can be over written.
	Read the keyboard.
	Turn keyboard stroke into a number (to).
	If that number is not 1, 2 or 3 then repeat this line.

Line 6: Set wrong to zero (meaning false).
	Adjust the 'from' number.
	Adjust the 'to' number.
	If the 'from' tower is empty or equal to the 'to' tower then wrong is true.

Line 7: If wrong is not yet true then check the 'to' tower for discs.
	If the top disc of the 'from' tower is too big then wrong is true.

Line 8: If wrong then:
	- Display "FALSE MOVE!" on the screen.
	- Go 11 screen places back to the left, so that it can be over written.
	- Wait a short while.
	- Go back to line 4 for a retry.

Line 9: Make the 'to' tower taller.
	The top disc of the 'from' tower is now the top disc of the 'to' tower.
	Make the 'from' tower smaller.
	Increase moves by 1.
	Go back to line 1 for the next move.
