Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def directions(position, direction, matrix):
- row, col = position
- matrix[row][col] = "-"
- moves = {'up': (-1, 0),
- 'down': (1, 0),
- 'left': (0, -1),
- 'right': (0, 1)}
- d_row, d_col = moves[direction]
- row = (row + d_row) % len(matrix)
- col = (col + d_col) % len(matrix[row])
- return row, col, matrix
- field_size = int(input())
- bee, hive, empty = 'B', 'H', '-'
- bee_energy = 15
- field = []
- found_hive = False
- nectar, nectar_max = 0, 30
- energy_restored = False
- position = (-1, -1)
- for row_ in range(field_size):
- line = list(input())
- if bee in line:
- position = (row_, line.index(bee))
- field.append(line)
- def print_matrix(matrix):
- for row in matrix:
- print("".join(map(str, row)))
- while bee_energy > 0 and not found_hive:
- if bee_energy <= 0:
- break
- direction = input()
- new_row, new_col, field = directions(position, direction, field)
- bee_energy -= 1
- position = (new_row, new_col)
- step = field[new_row][new_col]
- if step.isdigit():
- nectar += int(step)
- field[new_row][new_col] = empty
- if nectar >= nectar_max and bee_energy < 1:
- if not energy_restored:
- energy_restored = True
- energy_to_restore = nectar - nectar_max
- bee_energy += energy_to_restore
- nectar = nectar_max
- print(f"Energy restored! Energy added: {energy_to_restore}")
- elif step == hive:
- found_hive = True
- if bee_energy > 0:
- print(f"Great job, Beesy! The hive is full. Energy left: {bee_energy}")
- else:
- if nectar >= nectar_max:
- print(f"Great job, Beesy! The hive is full. Energy left: {bee_energy}")
- else:
- print("Beesy did not manage to collect enough nectar.")
- if bee_energy == 0:
- if nectar >= nectar_max and not found_hive:
- if not energy_restored: # Restore energy only once
- energy_restored = True
- energy_to_restore = nectar - nectar_max
- bee_energy += energy_to_restore
- nectar = nectar_max
- print(f"Energy restored! Energy added: {energy_to_restore}")
- else:
- print("This is the end! Beesy ran out of energy.")
- break
- else:
- print("This is the end! Beesy ran out of energy.")
- break
- field[position[0]][position[1]] = bee
- print_matrix(field)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement