Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def next_move(direction, row, col, rows):
- moves = {
- "up": (-1, 0),
- "down": (1, 0),
- "left": (0, -1),
- "right": (0, 1)
- }
- d_row, d_col = moves[direction]
- row = (row + d_row)
- col = (col + d_col)
- return row, col
- def fill_the_field_and_find_jet_position(size, j_row, j_col, enemies):
- field = []
- for r in range(size):
- row = list(input())
- field.append(row)
- if "J" in row:
- j_row = r
- j_col = row.index("J")
- if "E" in row:
- enemies += row.count("E")
- return field, j_row, j_col, enemies
- def main():
- size = int(input())
- jet_row, jet_col = None, None
- enemies = 0
- field, jet_row, jet_col, enemies = fill_the_field_and_find_jet_position(size, jet_row, jet_col, enemies)
- jet_armour = 300
- line = ' '
- while line:
- line = input()
- next_row, next_col = next_move(line, jet_row, jet_col, size)
- field[jet_row][jet_col] = "-"
- if field[next_row][next_col] == "E":
- field[next_row][next_col] = "-"
- enemies -= 1
- if enemies == 0:
- print("Mission accomplished, you neutralized the aerial threat!")
- jet_row, jet_col = next_row, next_col
- field[jet_row][jet_col] = "J"
- break
- else:
- jet_armour -= 100
- if jet_armour <= 0:
- jet_row, jet_col = next_row, next_col
- field[jet_row][jet_col] = "J"
- print(f"Mission failed, your jetfighter was shot down! Last coordinates [{jet_row}, {jet_col}]!")
- break
- elif field[next_row][next_col] == "R":
- jet_armour = 300
- field[next_row][next_col] = "-"
- jet_row, jet_col = next_row, next_col
- field[jet_row][jet_col] = "J"
- for row_ in field:
- print(''.join(row_))
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement