Advertisement
horozov86

Blind Man’s Buff

Jun 7th, 2023
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.32 KB | None | 0 0
  1. def moving(row, col, direction):
  2.     if direction == "up":
  3.         return row - 1, col
  4.  
  5.     if direction == "down":
  6.         return row + 1, col
  7.  
  8.     if direction == "right":
  9.         return row, col + 1
  10.  
  11.     if direction == "left":
  12.         return row, col - 1
  13.  
  14.  
  15. rows, cols = [int(x) for x in input().split()]
  16. matrix = []
  17. player_row = 0
  18. player_col = 0
  19. for row in range(rows):
  20.     inner_list = input().split()
  21.     for col in range(cols):
  22.         if inner_list[col] == 'B':
  23.             player_row = row
  24.             player_col = col
  25.     matrix.append(inner_list)
  26. touched_opponents = 0
  27. moves = 0
  28. while True:
  29.     line = input()
  30.     if line == 'Finish' or touched_opponents == 3:
  31.         break
  32.     direction = line
  33.     next_row, next_col = moving(player_row, player_col, direction)
  34.     if next_row < 0 or next_col < 0 or next_row >= rows or next_col >= cols:
  35.         next_row, next_col = player_row, player_col
  36.  
  37.     if matrix[next_row][next_col] == 'O':
  38.         next_row, next_col = player_row, player_col
  39.         continue
  40.  
  41.     if matrix[next_row][next_col] == '-':
  42.         moves += 1
  43.  
  44.     if matrix[next_row][next_col] == 'P':
  45.         moves += 1
  46.         touched_opponents += 1
  47.         matrix[player_row][player_col] = '-'
  48.  
  49.  
  50. print("Game over!")
  51. print(f'Touched opponents: {touched_opponents} Moves made: {moves}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement