Untitled

 avatar
unknown
python
5 months ago
1.3 kB
4
Indexable
# Read user input

n = int(input())

field = []
energy = 15
restored_energy = False
nectar = 0
bee_position = None

# Create the matrix
for row in range(n):
    row_data = list(input())
    field.append(row_data)
    for col in range(n):
        if row_data[col] == "B":
            bee_position = [row, col]

directions = {"up": (-1, 0), "down": (1, 0), "left": (0, -1), "right": (0, 1)}

# Logic
while True:
    command = input()
    row = (bee_position[0] + directions[command][0]) % n
    col = (bee_position[1] + directions[command][1]) % n
    current_symbol = field[row][col]

    old_position = bee_position
    bee_position = [row, col]
    field[row][col] = "B"
    field[old_position[0]][old_position[1]] = "-"

    energy -= 1

    if current_symbol.isdigit():
        nectar += int(current_symbol)
    elif current_symbol == "H":
        if nectar >= 30:
            print(f"Great job, Beesy! The hive is full. Energy left: {energy}")
        else:
            print("Beesy did not manage to collect enough nectar.")
        break

    if energy <= 0:
        if nectar >= 30 and not restored_energy:
            energy = nectar - 30
            nectar = 30
            restored_energy = True
        else:
            print("This is the end! Beesy ran out of energy.")
            break

for row in field:
    print(*row, sep="")
Editor is loading...
Leave a Comment