Advertisement
go6odn28

2_clear_skies.py

Jun 11th, 2024
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.00 KB | None | 0 0
  1. def next_move(direction, row, col, rows):
  2.     moves = {
  3.         "up": (-1, 0),
  4.         "down": (1, 0),
  5.         "left": (0, -1),
  6.         "right": (0, 1)
  7.     }
  8.  
  9.     d_row, d_col = moves[direction]
  10.     row = (row + d_row)
  11.     col = (col + d_col)
  12.     return row, col
  13.  
  14. def fill_the_field_and_find_jet_position(size, j_row, j_col, enemies):
  15.     field = []
  16.     for r in range(size):
  17.         row = list(input())
  18.         field.append(row)
  19.         if "J" in row:
  20.             j_row = r
  21.             j_col = row.index("J")
  22.         if "E" in row:
  23.             enemies += row.count("E")
  24.  
  25.     return field, j_row, j_col, enemies
  26.  
  27.  
  28. def main():
  29.     size = int(input())
  30.     jet_row, jet_col = None, None
  31.     enemies = 0
  32.     field, jet_row, jet_col, enemies = fill_the_field_and_find_jet_position(size, jet_row, jet_col, enemies)
  33.     jet_armour = 300
  34.     line = ' '
  35.  
  36.     while line:
  37.         line = input()
  38.  
  39.         next_row, next_col = next_move(line, jet_row, jet_col, size)
  40.         field[jet_row][jet_col] = "-"
  41.  
  42.         if field[next_row][next_col] == "E":
  43.             field[next_row][next_col] = "-"
  44.             enemies -= 1
  45.             if enemies == 0:
  46.                 print("Mission accomplished, you neutralized the aerial threat!")
  47.                 jet_row, jet_col = next_row, next_col
  48.                 field[jet_row][jet_col] = "J"
  49.                 break
  50.             else:
  51.                 jet_armour -= 100
  52.                 if jet_armour <= 0:
  53.                     jet_row, jet_col = next_row, next_col
  54.                     field[jet_row][jet_col] = "J"
  55.                     print(f"Mission failed, your jetfighter was shot down! Last coordinates [{jet_row}, {jet_col}]!")
  56.                     break
  57.  
  58.         elif field[next_row][next_col] == "R":
  59.             jet_armour = 300
  60.             field[next_row][next_col] = "-"
  61.  
  62.         jet_row, jet_col = next_row, next_col
  63.         field[jet_row][jet_col] = "J"
  64.  
  65.     for row_ in field:
  66.         print(''.join(row_))
  67.  
  68.  
  69. if __name__ == "__main__":
  70.     main()
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement