=======================================================
"TENLINER CAVE ADVENTURE" - A ZX81 GAME BY EINAR SAUKAS
=======================================================

---------
BACKSTORY
---------

As a young warrior apprentice, you have been chosen by the village elders to
seek out the evil menace that lurks in some nearby caves. Once found, use any
means at your disposal to defeat it... Good luck on your quest!


--------
COMMANDS
--------

This is a very simple tiny text adventure for the ZX81, coded in 10 lines only.
It recognizes the following commands:

    NORTH
    SOUTH
    EAST
    WEST
    INVENTORY
    LOOK
    LOOK <object>
    GET <object>
    OPEN <object>
    KILL <object>


-----
ABOUT
-----

This game was adapted from "1 Line Cave Adventure", originally developed by
Digital Prawn and myself (Einar Saukas) for the ZX-Spectrum in 2007. An almost
complete solution for our original game is available here:

    http://www.solutionarchive.com/game/id%2C5064/

The original game was already very small. Even so, it was quite challenging to 
port it to the ZX81 in 10 lines of code, mainly because the ZX81 only accepts a
single instruction per command line. Even worse, due to the line length 
restriction in this category, the instruction responsible for the main game
logic had to be broken into 3 separate lines, which means the entire game had to
be implemented using 8 instructions only!

The main solution was concatenating the entire game state into a single string
variable X$, and modeling the game logic as a finite state machine such that a
single formula updates the entire game state at once, in a single instruction,
based on player movement and action. This core game logic is assisted by another
2 formulas. The first formula validates and calculates player movement based on
player input and current location, execute in a single instruction. The second
formula validates and calculates player action based on player input, current
location, and game state, executed in a single instruction although "broken"
into 3 program lines because this last formula was too long.

Another problem was, the full list of text responses exceeds the imposed line
length limit. For this reason, the same string variable X$ is also used to
store some of these responses.

The complete list of variables is as follows:

    X$ = current game state, where:
        X$(1) = player location (1=cave, 2=pit, 3=hall, 4=lake)
        X$(2) = chest (0=closed, 1=open)
        X$(3) = inventory (0=nothing, 1=key, 2=sword)
        X$(4 TO ) = partial list of text responses
    U$ = player command
    M = player movement (from -2 to 2)
    A = player action (from 0 to 12)

The purpose of each program line is described below:

    Line 1: Initialize game state (location=1, chest=0, inventory=0)
    Line 2: Print current player location
    Line 3: Input player command
    Line 4: Validate and calculate player movement
    Lines 5 to 7: Validate and calculate player action
    Line 8: Update game state
    Line 9: Print game response
    Line 10: Repeat until player wins or dies

Easy, right? =:)


-------
CREDITS
-------

  "TENLINER CAVE ADVENTURE" for the ZX81 
    by Einar Saukas (c) 2016.

  Based on "1 Line Cave Adventure" for the ZX-Spectrum
    by Digital Prawn and Einar Saukas (c) 2007.
