Advertisement
mbratanov

02. Bomb Has Been Planted

Oct 20th, 2024
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.77 KB | None | 0 0
  1. n, m = (int(x) for x in input().split(", "))
  2. time_left = 16
  3. defuse_time = 4
  4. map_matrix = []
  5. ct_position = None
  6. bomb_position = None
  7. directions = {"up": (-1, 0), "down": (1, 0), "left": (0, -1), "right": (0, 1)}
  8.  
  9. for r in range(n):
  10.     row_data = list(input())
  11.     map_matrix.append(row_data)
  12.     for c in range(m):
  13.         if row_data[c] == "C":
  14.             ct_position = (r, c)
  15.         if row_data[c] == "B":
  16.             bomb_position = (r, c)
  17.  
  18. while time_left > 0:
  19.     command = input()
  20.     if command == "defuse":
  21.         if ct_position == bomb_position:
  22.             if time_left >= defuse_time:
  23.                 map_matrix[ct_position[0]][ct_position[1]] = "D"
  24.                 time_left -= defuse_time
  25.                 print("Counter-terrorist wins!")
  26.                 print(f"Bomb has been defused: {time_left} second/s remaining.")
  27.                 break
  28.             else:
  29.                 map_matrix[ct_position[0]][ct_position[1]] = "X"
  30.                 time_needed = defuse_time - time_left
  31.                 print(f"Terrorists win!\nBomb was not defused successfully!\nTime needed: {time_needed} second/s.")
  32.                 break
  33.         else:
  34.             time_left -= 2
  35.             continue
  36.     else:
  37.         row = directions[command][0] + ct_position[0]
  38.         col = directions[command][1] + ct_position[1]
  39.         if row in range(n) and col in range(m):
  40.             current_cell_value = map_matrix[row][col]
  41.             ct_position = (row, col)
  42.             if current_cell_value == "T":
  43.                 map_matrix[row][col] = "*"
  44.                 print("Terrorists win!")
  45.                 break
  46.     time_left -= 1
  47. else:
  48.     print("Terrorists win!\nBomb was not defused successfully!\nTime needed: 0 second/s.")
  49. for row in map_matrix:
  50.     print(*row, sep="")
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement