 # range_day

Jan 25th, 2022
699
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. def next_move(p_r, p_c, direction_, steps_):
2.     new_p_r, new_p_c = p_r, p_c
3.     if direction_ == 'up':
4.         new_p_r -= steps_
5.     elif direction_ == 'down':
6.         new_p_r += steps_
7.     elif direction_ == "left":
8.         new_p_c -= steps_
9.     elif direction_ == "right":
10.         new_p_c += steps_
11.     return new_p_r, new_p_c
12.
13.
14. def valid_idx(r, c, size_):
15.     return 0 <= r < size_ and 0 <= c < size_
16.
17.
18. size = 5
19. matrix = []
20. targets_total = 0
21. player_row, player_col = None, None
22.
23. for row in range(size):
24.     current_row = input().split()
25.     matrix.append(current_row)
26.     for col in range(size):
27.         if matrix[row][col] == "A":
28.             player_row, player_col = row, col
29.         elif matrix[row][col] == "x":
30.             targets_total += 1
31.
32. hit_targets_coords = []
33. targets_left = targets_total
34. n = int(input())
35.
36. for _ in range(n):
37.     command_line = input().split()
38.     if command_line == "shoot":
39.         direction = command_line
40.         next_row, next_col = player_row, player_col
41.         while True:
42.             next_row, next_col = next_move(next_row, next_col, direction, 1)
43.             if valid_idx(next_row, next_col, size):
44.                 if matrix[next_row][next_col] == "x":
45.                     targets_left -= 1
46.                     matrix[next_row][next_col] = "."
47.                     hit_targets_coords.append([next_row, next_col])
48.                     break
49.             else:
50.                 break
51.         if targets_left == 0:
52.             break
53.     else:
54.         direction, steps = command_line, int(command_line)
55.         next_row, next_col = next_move(player_row, player_col, direction, steps)
56.         if valid_idx(next_row, next_col, size):
57.             if matrix[next_row][next_col] == ".":
58.                 matrix[player_row][player_col] = "."
59.                 player_row, player_col = next_row, next_col
60.                 matrix[player_row][player_col] = "A"
61.
62. if not targets_left:
63.     print(f"Training completed! All {targets_total} targets hit.")
64.
65. else:
66.     print(f"Training not completed! {targets_left} targets left.")
67.
68. print(*[el for el in hit_targets_coords], sep='\n')
69.