"""
COMP 102 - Extra Activity 1, explained: K2, the small game we build in class.
Fakhir Shaheen, Sections A and B, Fall 2026, Forman Christian University.

Three camps on K2, one above the other.  Commands: look (l), north (n),
south (s) and quit.  Reach the summit to win.
"""

# The mountain: one name per camp, separated by |.  Camp 0 is the lowest.
NAMES = "Base Camp|Camp Four|Summit"
# One description per camp, separated by | in the same way.
DESCS = (
    "Tents on the Baltoro glacier. The ridge climbs north."
    + "|A ledge of blue ice. Base Camp is south, the summit north."
    + "|The top of K2. Clouds lie below you on every side."
)
# Two characters per camp, north then south: a camp number, or - for none.
EXITS = "1-" + "20" + "-1"
SUMMIT = 2

# What the climb remembers from one command to the next.
room = 0
show = True
turns = 0
won = False
leaving = False

# One pass of this loop is one command.
while True:
    # Describe the camp, but only after a move or a look.
    if show:
        # Walk along NAMES counting the | marks; keep the letters of camp room.
        field = 0
        name = ""
        for ch in NAMES:
            if ch == "|":
                field = field + 1
            elif field == room:
                name = name + ch
        print("--- " + name + " ---")
        # The description comes out of DESCS the same way.
        field = 0
        desc = ""
        for ch in DESCS:
            if ch == "|":
                field = field + 1
            elif field == room:
                desc = desc + ch
        print(desc)
        show = False

    # Read a command; n, s and l are short for north, south and look.
    command = input("> ")
    if command == "n":
        command = "north"
    elif command == "s":
        command = "south"
    elif command == "l":
        command = "look"

    # One branch per command.  The wind swallows any other word, free.
    understood = True
    if command == "look":
        show = True
    elif command == "quit":
        leaving = True
    elif command == "north" or command == "south":
        # Direction number: north 0, south 1.  Each camp has two exits.
        d = 0
        if command == "south":
            d = 1
        way = EXITS[room * 2 + d]
        if way == "-":
            print("You can't climb that way.")
        else:
            room = int(way)
            show = True
            if room == SUMMIT:
                won = True
    else:
        print("The wind takes your words.")
        understood = False

    # End of the pass: a win or a quit leaves at once, and is not counted.
    if won or leaving:
        break
    if understood:
        turns = turns + 1

# After the loop: the ending.
if won:
    print("You stand on the summit of K2.")
else:
    print("You climb down to the valley.")
print(f"Turns: {turns}.")
