Advertisement
mbratanov

02. Beesy

Oct 14th, 2024
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.51 KB | None | 0 0
  1. n = int(input())
  2.  
  3. is_restored = False
  4. MINIMUM_REQUIRED_NECTAR = 30
  5. mat = []
  6. bee = []
  7. energy = 15
  8. nectar = 0
  9.  
  10. for row in range(n):
  11.     mat.append(list(input()))
  12.     for col in range(n):
  13.         if mat[row][col] == "B":
  14.             mat[row][col] = "-"
  15.             bee = [row, col]
  16.  
  17. directions = {
  18.     "up": (-1, 0),
  19.     "down": (1, 0),
  20.     "right": (0, 1),
  21.     "left": (0, -1)
  22. }
  23.  
  24. while True:
  25.     command = input()
  26.     row_move = (bee[0] + directions[command][0]) % n
  27.     col_move = (bee[1] + directions[command][1]) % n
  28.     bee = [row_move, col_move]
  29.  
  30.     energy -= 1
  31.     if mat[row_move][col_move].isdigit():
  32.         nectar += int(mat[row_move][col_move])
  33.         mat[row_move][col_move] = "-"
  34.  
  35.     elif mat[row_move][col_move] == "H":
  36.         if nectar >= MINIMUM_REQUIRED_NECTAR:
  37.             print(f"Great job, Beesy! The hive is full. Energy left: {energy}")
  38.         else:
  39.             print("Beesy did not manage to collect enough nectar.")
  40.         break
  41.  
  42.     if energy <= 0 and nectar < MINIMUM_REQUIRED_NECTAR:
  43.         print("This is the end! Beesy ran out of energy.")
  44.         break
  45.  
  46.     if energy <= 0 and nectar >= MINIMUM_REQUIRED_NECTAR:
  47.         if not is_restored:
  48.             diff = nectar - MINIMUM_REQUIRED_NECTAR
  49.             energy = diff
  50.             nectar = MINIMUM_REQUIRED_NECTAR
  51.             is_restored = True
  52.  
  53.     if energy <= 0:
  54.         print("This is the end! Beesy ran out of energy.")
  55.         break
  56.  
  57. mat[bee[0]][bee[1]] = "B"
  58.  
  59. [print(''.join(row)) for row in mat]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement