Advertisement
Onesible

Radioactive Mutant Vampire Bunnies

Jan 20th, 2024
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.80 KB | None | 0 0
  1. from copy import deepcopy
  2.  
  3. def bunny_move(matrix_move, matrix_copy):
  4.     for row1 in range(rows):
  5.         for col1 in range(cols):
  6.             if matrix_copy[row1][col1] == 'B':
  7.                 for x, y in directions.values():
  8.                     b_r, b_c = row1 + x, col1 + y
  9.  
  10.                     if 0 <= b_r < rows and 0 <= b_c < cols:
  11.                         matrix_move[b_r][b_c] = 'B'
  12.     return matrix_move
  13.  
  14. rows, cols = [int(n) for n in input().split()]
  15. matrix = [[el for el in input()] for _ in range(rows)]
  16. moves = input()
  17.  
  18. copy_matrix = deepcopy(matrix)
  19. position = []
  20.  
  21. directions = {
  22.     'L': [0, -1],
  23.     'R': [0, 1],
  24.     'U': [-1, 0],
  25.     'D': [1, 0],
  26. }
  27. player_found = False
  28. for row in range(rows):
  29.     for col in range(cols):
  30.         if matrix[row][col] == 'P':
  31.             position = [row, col]
  32.             matrix[row][col] = '.'
  33.             player_found = True
  34.             break
  35.     if player_found:
  36.         break
  37.  
  38. for move in moves:
  39.     move_direction = directions[move]
  40.     r, c = position[0] + move_direction[0], position[1] + move_direction[1]
  41.  
  42.     if 0 <= r < rows and 0 <= c < cols:
  43.         position = [r, c]
  44.         if matrix[r][c] == 'B':
  45.             matrix = bunny_move(matrix, copy_matrix)
  46.             copy_matrix = deepcopy(matrix)
  47.             [print(*row, sep='') for row in matrix]
  48.             print(f"dead: {r} {c}")
  49.             break
  50.  
  51.         matrix = bunny_move(matrix, copy_matrix)
  52.         copy_matrix = deepcopy(matrix)
  53.  
  54.         if matrix[r][c] == 'B':
  55.             [print(*row, sep='') for row in matrix]
  56.             print(f"dead: {r} {c}")
  57.             break
  58.  
  59.     else:
  60.         matrix = bunny_move(matrix, copy_matrix)
  61.         [print(*row, sep='') for row in matrix]
  62.         print(f"won: {r - move_direction[0]} {c - move_direction[1]}")
  63.         break
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement