Advertisement
desislava_topuzakova

Untitled

Sep 6th, 2024
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. def move(size, rw, cl, direct, step, mapp, mat):
  2. desired_row = rw + mapp[direct][0] * step
  3. desired_col = cl + mapp[direct][1] * step
  4. if 0 <= desired_row < size and 0 <= desired_col < size and mat[desired_row][desired_col] == '.':
  5. return desired_row, desired_col
  6. return rw, cl
  7.  
  8.  
  9. def shoot(size, rw, cl, direct, mapp, mat, tts, t_shot):
  10. while 0 <= rw < size and 0 <= cl < size:
  11. rw += mapp[direct][0]
  12. cl += mapp[direct][1]
  13. if 0 <= rw < size and 0 <= cl < size:
  14. if mat[rw][cl] == 'x':
  15. tts -= 1
  16. mat[rw][cl] = '.'
  17. t_shot.append([rw, cl])
  18. break
  19. return mat, tts, t_shot
  20.  
  21.  
  22. n = 5
  23. r, c = 0, 0
  24. targets = 0
  25. matrix = []
  26.  
  27.  
  28. for row in range(n):
  29. matrix.append(input().split())
  30. for col in range(n):
  31. if matrix[row][col] == 'A':
  32. r, c = row, col
  33. elif matrix[row][col] == 'x':
  34. targets += 1
  35.  
  36. targets_total = targets
  37. targets_shot = []
  38. mapper = {
  39. 'up': (-1, 0),
  40. 'down': (1, 0),
  41. 'left': (0, -1),
  42. 'right': (0, 1)
  43. }
  44. commands_num = int(input())
  45. for _ in range(commands_num):
  46. command = input().split()
  47. action = command[0]
  48. if action == 'move':
  49. direction, steps = command[1], int(command[2])
  50. r, c = move(n, r, c, direction, steps, mapper, matrix)
  51. else:
  52. direction = command[1]
  53. matrix, targets, targets_shot = shoot(n, r, c, direction, mapper, matrix, targets, targets_shot)
  54. if targets == 0:
  55. print(f"Training completed! All {targets_total} targets hit.")
  56. break
  57.  
  58. if targets:
  59. print(f"Training not completed! {targets} targets left.")
  60. [print(x) for x in targets_shot]
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement