Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def check_valid_index(row, col):
- if 0 <= row < SIZE and 0 <= col < SIZE:
- return True
- return False
- def player_position(matrix):
- for i in range(len(matrix)):
- for j in range(len(matrix[0])):
- if matrix[i][j] == "A":
- return i, j
- return None
- def move_player(direction, steps):
- curr_row, curr_col = player_position(matrix)
- new_row, new_col = curr_row, curr_col
- if direction == "left":
- new_row, new_col = curr_row, curr_col - steps
- elif direction == "right":
- new_row, new_col = curr_row, curr_col + steps
- elif direction == "up":
- new_row, new_col = curr_row - steps, curr_col
- elif direction == "down":
- new_row, new_col = curr_row + steps, curr_col
- if check_valid_index(new_row, new_col) and matrix[new_row][new_col] == ".":
- matrix[new_row][new_col] = "A"
- matrix[curr_row][curr_col] = "."
- def shoot_target(direction):
- player_row, player_col = player_position(matrix)
- next_row, next_col = player_row + directions[direction][0], player_col + directions[direction][1]
- while check_valid_index(next_row, next_col):
- if matrix[next_row][next_col] == "x":
- matrix[next_row][next_col] = "."
- return next_row, next_col
- elif matrix[next_row][next_col] == ".":
- next_row += directions[direction][0]
- next_col += directions[direction][1]
- else:
- break
- return None
- SIZE = 5
- matrix = [[el for el in input().split()] for _ in range(SIZE)]
- count_of_targets = sum(row.count("x") for row in matrix)
- n_commands = int(input())
- directions = {
- "up": (-1, 0),
- "down": (1, 0),
- "left": (0, -1),
- "right": (0, 1),
- }
- targets_shot = []
- for _ in range(n_commands):
- command, *info = input().split()
- if command == "move":
- direction = info[0]
- steps = int(info[1])
- move_player(direction, steps)
- elif command == "shoot":
- direction = info[0]
- target = shoot_target(direction)
- if target:
- targets_shot.append(target)
- if count_of_targets == len(targets_shot):
- print(f"Training completed! All {count_of_targets} targets hit.")
- else:
- print(f"Training not completed! {count_of_targets - len(targets_shot)} targets left.")
- if targets_shot:
- for target in targets_shot:
- print(list(target))
Advertisement
Comments
-
- Липсва ти тази проверка
- "If at any point there are no targets left, end the program"
Add Comment
Please, Sign In to add comment