Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import deque
- num = int(input())
- directions = deque(input().split())
- matrix = []
- coal_ore = 0
- current_row = 0
- current_col = 0
- exit_condition = False
- for i in range(num):
- line = input().split()
- for j in range(len(line)):
- if line[j] == "c":
- coal_ore += 1
- elif line[j] == "s":
- current_row = i
- current_col = j
- matrix.append(line)
- while directions:
- direction = directions.popleft()
- if direction == "up":
- current_row -= 1
- elif direction == "down":
- current_row += 1
- elif direction == "left":
- current_col -= 1
- elif direction == "right":
- current_col += 1
- if 0 <= current_row < num and 0 <= current_col < num:
- if matrix[current_row][current_col] == "c":
- coal_ore -= 1
- matrix[current_row][current_col] = "*"
- if coal_ore == 0:
- print(f"You collected all coal! ({current_row}, {current_col})")
- break
- elif matrix[current_row][current_col] == "e":
- print(f"Game over! ({current_row}, {current_col})")
- exit_condition = True
- break
- else:
- if direction == "up":
- current_row += 1
- elif direction == "down":
- current_row -= 1
- elif direction == "left":
- current_col += 1
- elif direction == "right":
- current_col -= 1
- if not exit_condition and coal_ore > 0:
- print(f"{coal_ore} pieces of coal left. ({current_row}, {current_col})")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement