Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def valid_move(row_, col_, size):
- valid_range = range(0, size)
- if row_ in valid_range and col_ in valid_range:
- return True
- n = int(input())
- tea_bags = 0
- matrix = []
- alice_row, alice_col = None, None
- for row in range(n):
- matrix.append(input().split())
- for col in range(n):
- if matrix[row][col] == "A":
- alice_row, alice_col = row, col
- is_over = False
- while tea_bags < 10 and not is_over:
- command = input()
- if command == 'up':
- next_row, next_col = alice_row - 1, alice_col
- matrix[alice_row][alice_col] = "*"
- if valid_move(next_row, next_col, n):
- if matrix[next_row][next_col] != "R":
- if matrix[next_row][next_col] != "." and matrix[next_row][next_col] != "*":
- tea_bags += int(matrix[next_row][next_col])
- matrix[next_row][next_col] = "*"
- alice_row -= 1
- else:
- matrix[next_row][next_col] = "*"
- is_over = True
- break
- else:
- is_over = True
- break
- elif command == "left":
- next_row, next_col = alice_row, alice_col - 1
- matrix[alice_row][alice_col] = "*"
- if valid_move(next_row, next_col, n):
- if matrix[next_row][next_col] != "R":
- if matrix[next_row][next_col] != "." and matrix[next_row][next_col] != "*":
- tea_bags += int(matrix[next_row][next_col])
- matrix[next_row][next_col] = "*"
- alice_col -= 1
- else:
- matrix[next_row][next_col] = "*"
- is_over = True
- break
- else:
- is_over = True
- break
- elif command == "right":
- next_row, next_col = alice_row, alice_col + 1
- matrix[alice_row][alice_col] = "*"
- if valid_move(next_row, next_col, n):
- if matrix[next_row][next_col] != "R":
- if matrix[next_row][next_col] != "." and matrix[next_row][next_col] != "*":
- tea_bags += int(matrix[next_row][next_col])
- matrix[next_row][next_col] = "*"
- alice_col += 1
- else:
- matrix[next_row][next_col] = "*"
- is_over = True
- break
- else:
- is_over = True
- break
- elif command == "down":
- next_row, next_col = alice_row + 1, alice_col
- matrix[alice_row][alice_col] = "*"
- if valid_move(next_row, next_col, n):
- if matrix[next_row][next_col] != "R":
- if matrix[next_row][next_col] != "." and matrix[next_row][next_col] != "*":
- tea_bags += int(matrix[next_row][next_col])
- matrix[next_row][next_col] = "*"
- alice_row += 1
- else:
- matrix[next_row][next_col] = "*"
- is_over = True
- break
- else:
- is_over = True
- break
- if tea_bags >= 10:
- print("She did it! She went to the party.")
- else:
- print("Alice didn't make it to the tea party.")
- for row in range(n):
- print(*matrix[row])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement