***************
*KNIGHT'S TOUR*
***************

BASIC 10Liners 2018

Written in BASIC 2.0
Unexpanded VIC-20 version

Description:
Knight's tour mathematical problem inspired this game. The player moves a knight inside a chessboard. Target of the game is to visit every square of the chessboard only once. A knight can move "to a square that is two squares away horizontally and one square vertically, or two squares vertically and one square horizontally. The complete move therefore looks like the letter L. Unlike all other standard chess pieces, the knight can jump over all other pieces [...] to its destination square." (from wikipedia).
See wikipedia for further details:
https://en.wikipedia.org/wiki/Knight%27s_tour
https://en.wikipedia.org/wiki/Knight_(chess)

Controls:
Use joystick to move the cursor inside the chessboard and fire to confirm the next move of the knight.
Press "G" key to restart the game.

Running the program:
Download VICE (http://vice-emu.sourceforge.net/) then configure the VIC20 emulator:
1) VIC20 settings -> No expansion memory
2) Joystick settings (setup at your needs)
Run the VIC20 emulator then autostart the .d64 file containing the game. Enjoy!

Code explanation.
Lines 1-3: Variables, chessboard, graphics and environment setup. The chessboard is printed using the default ROM characters; beware that all spaces inside the print instruction at line 2 are shifted (<shift+space>). Shifted spaces look as normal spaces but have different video map codes; this difference is used on line 7 in order to prevent cursor's movement outside the chessboard.
Lines 4-5: Cursor's display. Reversed or normal characters effect is obtained adding or subtracting a constant on cursor's video memory location.
Line 6: Testing joystick and keyboard.
Line 7: Cursor position is changed if the joystick was moved. A comparison operator (=) is used ("true" returns -1) in order to avoid having multiple "if"s on multiple lines.
Line 8: Testing if cursor's position is a knight's valid move. The test is based on difference between last confirmed knight's position and cursor's position in terms of video memory locations. The absolute value function (ABS) is used to test symmetric movements.
Line 9: Move's confirmation behaviour and score's updating.
Line 10: End of main loop and score's display; the line contains the data defining the shape of the knight's character.