Advertisement
pacho_the_python

miner

Jun 2nd, 2022
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.56 KB | None | 0 0
  1. from collections import deque
  2. num = int(input())
  3.  
  4. directions = deque(input().split())
  5. matrix = []
  6. coal_ore = 0
  7. current_row = 0
  8. current_col = 0
  9. exit_condition = False
  10. for i in range(num):
  11.     line = input().split()
  12.     for j in range(len(line)):
  13.         if line[j] == "c":
  14.             coal_ore += 1
  15.         elif line[j] == "s":
  16.             current_row = i
  17.             current_col = j
  18.     matrix.append(line)
  19.  
  20. while directions:
  21.     direction = directions.popleft()
  22.  
  23.     if direction == "up":
  24.         current_row -= 1
  25.     elif direction == "down":
  26.         current_row += 1
  27.     elif direction == "left":
  28.         current_col -= 1
  29.     elif direction == "right":
  30.         current_col += 1
  31.  
  32.     if 0 <= current_row < num and 0 <= current_col < num:
  33.         if matrix[current_row][current_col] == "c":
  34.             coal_ore -= 1
  35.             matrix[current_row][current_col] = "*"
  36.             if coal_ore == 0:
  37.                 print(f"You collected all coal! ({current_row}, {current_col})")
  38.                 break
  39.         elif matrix[current_row][current_col] == "e":
  40.             print(f"Game over! ({current_row}, {current_col})")
  41.             exit_condition = True
  42.             break
  43.     else:
  44.         if direction == "up":
  45.             current_row += 1
  46.         elif direction == "down":
  47.             current_row -= 1
  48.         elif direction == "left":
  49.             current_col += 1
  50.         elif direction == "right":
  51.             current_col -= 1
  52.  
  53. if not exit_condition and coal_ore > 0:
  54.     print(f"{coal_ore} pieces of coal left. ({current_row}, {current_col})")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement