 # range_day

Jan 30th, 2023
699
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. n = 5
2. matrix = []
3. all_targets = 0
4. hit_targets = 0
5. hit_pos = []
6. shooter_pos = ()
7. directions = {
8.     "up": (-1, 0),
9.     "down": (1, 0),
10.     "left": (0, -1),
11.     "right": (0, 1),
12. }
13. for r in range(n):
14.     matrix.append(input().split())
15.     for c in range(n):
16.         if matrix[r][c] == 'A':
17.             shooter_pos = (r, c)
18.         if matrix[r][c] == 'x':
19.             all_targets += 1
20.
21. number_of_commands = int(input())
22. for command in range(number_of_commands):
23.     action = input().split()
24.     if action == 'move':
25.         direction = action
26.         steps = int(action)
27.         next_pos_row = (shooter_pos + (directions[direction] * steps))
28.         next_pos_col = (shooter_pos + (directions[direction] * steps))
29.         if not (0 <= next_pos_row < len(matrix) and 0 <= next_pos_col < len(matrix)):
30.             continue
31.         if matrix[next_pos_row][next_pos_col] == 'x':
32.             continue
33.         shooter_pos = (next_pos_row, next_pos_col)
34.     elif action == 'shoot':
35.         shoot_direction = action
36.         shooting_row = shooter_pos + directions[shoot_direction]
37.         shooting_col = shooter_pos + directions[shoot_direction]
38.         while 0 <= shooting_row < len(matrix) and 0 <= shooting_col < len(matrix):
39.
40.             if not matrix[shooting_row][shooting_col] == 'x':
41.                 shooting_row += directions[shoot_direction]
42.                 shooting_col += directions[shoot_direction]
43.                 continue
44.             hit_targets += 1
45.             hit_pos.append([shooting_row, shooting_col])
46.             matrix[shooting_row][shooting_col] = '.'
47.
48.             break
49. if all_targets != hit_targets:
50.     print(f"Training not completed! {all_targets - hit_targets} targets left.")
51.     print(*hit_pos, sep='\n')
52. else:
53.     print(f'Training completed! All {hit_targets} targets hit.')
54.     print(*hit_pos, sep='\n')