viligen

game_of_words_2

Feb 18th, 2022
678
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. def is_inside(r, c, size_):
  2.     if 0 <= r < size_ and 0 <= c < size_:
  3.         return True
  4.     return False
  5.  
  6.  
  7. string_line = input()
  8. size = int(input())
  9. field = []
  10. player_row, player_col = None, None
  11.  
  12. for row in range(size):
  13.     field.append(list(input()))
  14.     if "P" in field[row]:
  15.         player_row, player_col = row, field[row].index('P')
  16.  
  17. num = int(input())
  18. for _ in range(num):
  19.     command = input()
  20.     next_row, next_col = player_row, player_col
  21.     if command == "up":
  22.         next_row -= 1
  23.     elif command == "down":
  24.         next_row += 1
  25.     elif command == "left":
  26.         next_col -= 1
  27.     elif command == "right":
  28.         next_col += 1
  29.  
  30.     if not is_inside(next_row, next_col, size):
  31.         string_line = string_line[:-1]
  32.         continue
  33.     field[player_row][player_col] = '-'
  34.     if field[next_row][next_col] != '-':
  35.         string_line += field[next_row][next_col]
  36.     field[next_row][next_col] = 'P'
  37.     player_row, player_col = next_row, next_col
  38.  
  39. print(string_line)
  40. for row in field:
  41.     print(*row, sep='')
  42.  
Advertisement
Add Comment
Please, Sign In to add comment