Advertisement
viligen

alice_in_wonderland

Jan 24th, 2022
1,110
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def valid_move(row_, col_, size):
  2.     valid_range = range(0, size)
  3.     if row_ in valid_range and col_ in valid_range:
  4.         return True
  5.  
  6.  
  7. n = int(input())
  8. tea_bags = 0
  9. matrix = []
  10. alice_row, alice_col = None, None
  11. for row in range(n):
  12.     matrix.append(input().split())
  13.     for col in range(n):
  14.         if matrix[row][col] == "A":
  15.             alice_row, alice_col = row, col
  16.  
  17. is_over = False
  18. while tea_bags < 10 and not is_over:
  19.     command = input()
  20.  
  21.     if command == 'up':
  22.         next_row, next_col = alice_row - 1, alice_col
  23.         matrix[alice_row][alice_col] = "*"
  24.         if valid_move(next_row, next_col, n):
  25.             if matrix[next_row][next_col] != "R":
  26.                 if matrix[next_row][next_col] != "." and matrix[next_row][next_col] != "*":
  27.                     tea_bags += int(matrix[next_row][next_col])
  28.  
  29.                 matrix[next_row][next_col] = "*"
  30.                 alice_row -= 1
  31.  
  32.             else:
  33.                 matrix[next_row][next_col] = "*"
  34.                 is_over = True
  35.                 break
  36.         else:
  37.             is_over = True
  38.             break
  39.  
  40.     elif command == "left":
  41.         next_row, next_col = alice_row, alice_col - 1
  42.         matrix[alice_row][alice_col] = "*"
  43.         if valid_move(next_row, next_col, n):
  44.             if matrix[next_row][next_col] != "R":
  45.                 if matrix[next_row][next_col] != "." and matrix[next_row][next_col] != "*":
  46.                     tea_bags += int(matrix[next_row][next_col])
  47.  
  48.                 matrix[next_row][next_col] = "*"
  49.                 alice_col -= 1
  50.  
  51.             else:
  52.                 matrix[next_row][next_col] = "*"
  53.                 is_over = True
  54.                 break
  55.         else:
  56.             is_over = True
  57.             break
  58.     elif command == "right":
  59.         next_row, next_col = alice_row, alice_col + 1
  60.         matrix[alice_row][alice_col] = "*"
  61.         if valid_move(next_row, next_col, n):
  62.             if matrix[next_row][next_col] != "R":
  63.                 if matrix[next_row][next_col] != "." and matrix[next_row][next_col] != "*":
  64.                     tea_bags += int(matrix[next_row][next_col])
  65.  
  66.                 matrix[next_row][next_col] = "*"
  67.                 alice_col += 1
  68.  
  69.             else:
  70.                 matrix[next_row][next_col] = "*"
  71.                 is_over = True
  72.                 break
  73.         else:
  74.             is_over = True
  75.             break
  76.     elif command == "down":
  77.         next_row, next_col = alice_row + 1, alice_col
  78.         matrix[alice_row][alice_col] = "*"
  79.         if valid_move(next_row, next_col, n):
  80.             if matrix[next_row][next_col] != "R":
  81.                 if matrix[next_row][next_col] != "." and matrix[next_row][next_col] != "*":
  82.                     tea_bags += int(matrix[next_row][next_col])
  83.  
  84.                 matrix[next_row][next_col] = "*"
  85.                 alice_row += 1
  86.  
  87.             else:
  88.                 matrix[next_row][next_col] = "*"
  89.                 is_over = True
  90.                 break
  91.         else:
  92.             is_over = True
  93.             break
  94.  
  95. if tea_bags >= 10:
  96.     print("She did it! She went to the party.")
  97. else:
  98.     print("Alice didn't make it to the tea party.")
  99.  
  100. for row in range(n):
  101.     print(*matrix[row])
  102.  
  103.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement