Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def is_in_range(row, col , n):
- if 0 <= row < n and 0 <= col < n:
- return True
- return False
- N = 5
- MY_POSITION = "A"
- TARGETS = "x"
- matrix = []
- current_position = ()
- targets_count = 0
- total_targets = 0
- for row_index in range(N):
- current_row = [el for el in input().split()]
- if MY_POSITION in current_row:
- column_index = current_row.index(MY_POSITION)
- current_position = (row_index, column_index)
- if TARGETS in current_row:
- for count in current_row:
- if TARGETS == count:
- targets_count += 1
- matrix.append(current_row)
- directions = {
- "up": (-1, 0),
- "down": (1, 0),
- "left": (0, -1),
- "right": (0, 1)
- }
- number_of_commands = int(input())
- targets_hit_position = []
- training_completed = False
- for _ in range(number_of_commands):
- if targets_count <= 0:
- training_completed = True
- break
- command = input().split()
- current_row = int(current_position[0])
- current_col = int(current_position[1])
- if command[0] == "shoot":
- position = command[1]
- for shooting in directions:
- if shooting == position:
- next_row = current_row + directions[shooting][0]
- next_col = current_col + directions[shooting][1]
- while is_in_range(next_row, next_col, N):
- if matrix[next_row][next_col] == "x":
- targets_hit_position.append([next_row, next_col])
- matrix[next_row][next_col] = "."
- targets_count -= 1
- total_targets += 1
- if targets_count <= 0:
- training_completed = True
- break
- break
- next_row += directions[shooting][0]
- next_col += directions[shooting][1]
- break
- elif command[0] == "move":
- position = command[1]
- steps = int(command[2])
- for moving in directions:
- if moving == position:
- potential_row = current_row + directions[moving][0]
- potential_col = current_col + directions[moving][1]
- for moves in range(steps-1):
- if is_in_range(potential_row, potential_col , N):
- if matrix[potential_row][potential_col] != "x":
- potential_row += directions[moving][0]
- potential_col += directions[moving][1]
- else:
- break
- if is_in_range(potential_row, potential_col, N):
- if matrix[potential_row][potential_col] != "x":
- matrix[current_row][current_col] = "."
- current_row = potential_row
- current_col = potential_col
- matrix[current_row][current_col] = "A"
- else:
- break
- if training_completed:
- print(f"Training completed! All {total_targets} targets hit.")
- else:
- print(f"Training not completed! {targets_count} targets left.")
- print('\n'.join([str(el) for el in targets_hit_position]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement