Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def in_range(row, col, size):
- if 0 <= row < 5 and 0 <= col < 5:
- return True
- return False
- matrix = []
- for row in range(5):
- matrix.append([el for el in input().split()])
- for row in range(5):
- for col in range(5):
- if matrix[row][col] == "A":
- start_row = row
- start_col = col
- counter = 0
- for row in range(5):
- for col in range(5):
- if matrix[row][col] == "x":
- counter += 1
- directions = {
- "up": [-1, 0],
- "down": [1, 0],
- "left": [0, -1],
- "right": [0, 1]}
- n = int(input())
- target = []
- for i in range(n):
- commands = input().split()
- command = commands[0]
- direction = commands[1]
- if command == "shoot":
- next_row = start_row + directions[direction][0]
- next_col = start_col + directions[direction][1]
- if in_range(next_row, next_col, 5):
- if matrix[next_row][next_col] == "x":
- target.append([next_row, next_col])
- matrix[next_row][next_col] = "."
- elif command == "move":
- step = int(commands[2])
- next_row = start_row + (directions[direction][0]) * step
- next_col = start_col + (directions[direction][1]) * step
- if in_range(next_row, next_col, 5):
- if matrix[next_row][next_col] == ".":
- matrix[next_row][next_col] = "A"
- start_row += (directions[direction][0]) * step
- start_col += (directions[direction][1]) * step
- if len(target) == counter:
- print(f"Training completed! All {counter} targets hit.")
- [print(el) for el in target]
- else:
- print(f"Training not completed! {counter - len(target)} targets left.")
- [print(el) for el in target]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement