Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import deque
- def next_move(minerrow, minercol, command_):
- if command_ == "up":
- if minerrow - 1 >= 0:
- minerrow -= 1
- elif command_ == "down":
- if minerrow + 1 < n:
- minerrow += 1
- elif command_ == "right":
- if minercol + 1 < n:
- minercol += 1
- elif command_ == "left":
- if minercol - 1 >= 0:
- minercol -= 1
- return minerrow, minercol
- n = int(input())
- commands = deque(input().split())
- total_coals = 0
- miner_row, miner_col = None, None
- matrix = []
- for row in range(n):
- current_row = input().split()
- matrix.append(current_row)
- for element in current_row:
- if element == "c":
- total_coals += 1
- elif element == 's':
- miner_row = row
- miner_col = current_row.index(element)
- game_over = False
- while total_coals > 0 and commands:
- command = commands.popleft()
- miner_row, miner_col = next_move(miner_row, miner_col, command)
- if matrix[miner_row][miner_col] == 'e':
- game_over = True
- break
- elif matrix[miner_row][miner_col] == "c":
- total_coals -= 1
- matrix[miner_row][miner_col] = '*'
- if total_coals == 0:
- break
- if game_over:
- print(f"Game over! ({miner_row}, {miner_col})")
- elif total_coals == 0:
- print(f"You collected all coal! ({miner_row}, {miner_col})")
- else:
- print(f"{total_coals} pieces of coal left. ({miner_row}, {miner_col})")
Advertisement
Add Comment
Please, Sign In to add comment