Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MATRIX_SIZE = int(input())
- matrix = []
- spaceship = []
- for r in range(MATRIX_SIZE):
- matrix.append(input().split())
- for c in range(MATRIX_SIZE):
- if matrix[r][c] == 'S':
- spaceship = [r, c]
- matrix[r][c] = '.'
- is_lost = False
- is_accomplished = False
- units = 100
- moves = {
- "up": (-1, 0),
- "down": (1, 0),
- "left": (0, -1),
- "right": (0, 1)
- }
- while units >= 5:
- command = input()
- units -= 5
- current_row = spaceship[0]
- current_col = spaceship[1]
- move = moves[command]
- new_row = spaceship[0] + move[0]
- new_col = spaceship[1] + move[1]
- if 0 <= new_row < MATRIX_SIZE and 0 <= new_col < MATRIX_SIZE:
- if matrix[new_row][new_col] == 'P':
- # if matrix[current_row][current_col] != 'R':
- # matrix[current_row][current_col] = '.'
- is_accomplished = True
- print(f"Mission accomplished! The spaceship reached Planet B with {units} resources left.")
- break
- elif matrix[new_row][new_col] == 'M':
- # matrix[new_row][new_col] = '.'
- units -= 5
- elif matrix[new_row][new_col] == 'R':
- units = min(100, units + 10)
- spaceship = [new_row, new_col]
- continue
- # if units < 5:
- # spaceship = [new_row, new_col]
- # break
- spaceship = [new_row, new_col]
- if matrix[new_row][new_col] != 'R':
- matrix[new_row][new_col] = '.'
- else:
- is_lost = True
- break
- if units < 5 and not is_accomplished and not is_lost: # Добавих проверката - not is_lost
- r, c = spaceship
- matrix[r][c] = 'S'
- print(f"Mission failed! The spaceship was stranded in space.")
- elif is_lost and not is_accomplished:
- r, c = spaceship
- matrix[r][c] = 'S'
- print(f"Mission failed! The spaceship was lost in space.")
- for r in matrix:
- print(" ".join(r))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement