Advertisement
horozov86

blind_man

Jun 6th, 2023
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.73 KB | None | 0 0
  1. def find_my_cooridnates(r, c, mtrx):
  2.     for row in range(r):
  3.         for col in range(c):
  4.             if mtrx[row][col] == "B":
  5.                 return [row, col]
  6.  
  7. def check_my_next_position(my_row, my_col, current_matrix):
  8.     if 0 <= my_row < len(current_matrix) and 0 <= my_col < len(current_matrix[0]):
  9.         next_position = current_matrix[my_row][my_col]
  10.         if next_position == "O":
  11.             return False
  12.         elif next_position == "-":
  13.             return [my_row, my_col], current_matrix, 0
  14.         elif next_position == "P":
  15.             current_matrix[my_row][my_col] = "-"
  16.             return [my_row, my_col], current_matrix, 1
  17.  
  18.  
  19. n, m = map(int, input().split())
  20.  
  21. matrix = []
  22. for _ in range(n):
  23.     matrix.append(input().split())
  24.  
  25.  
  26. my_coordinates = find_my_cooridnates(n, m, matrix)
  27. matrix[my_coordinates[0]][my_coordinates[1]] = "-"
  28. result = False
  29. touched_opponents = 0
  30. moves_made = 0
  31.  
  32. while True:
  33.     if touched_opponents == 3:
  34.         break
  35.  
  36.     command = input()
  37.     if command == 'Finish':
  38.         break
  39.  
  40.     if command == 'up':
  41.         result = check_my_next_position(my_coordinates[0] - 1, my_coordinates[1], matrix)
  42.     elif command == 'down':
  43.         result = check_my_next_position(my_coordinates[0] + 1, my_coordinates[1], matrix)
  44.     elif command == 'left':
  45.         result = check_my_next_position(my_coordinates[0], my_coordinates[1] - 1, matrix)
  46.     elif command == 'right':
  47.         result = check_my_next_position(my_coordinates[0], my_coordinates[1] + 1, matrix)
  48.  
  49.     if result:
  50.         my_coordinates, matrix, touches = result
  51.         touched_opponents += touches
  52.         moves_made += 1
  53.  
  54. print("Game over!")
  55. print(f"Touched opponents: {touched_opponents} Moves made: {moves_made}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement