-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path05. Alice in Wonderland.py
66 lines (35 loc) · 1.4 KB
/
05. Alice in Wonderland.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
rows = int(input())
matrix = [[char for char in input().split()] for row in range(rows)]
columns = len(matrix[0])
score, movement = [0], {"up": [-1, 0], "down": [1, 0], "left": [0, -1], "right": [0, 1]}
def check_movement(row, col):
if 0 <= row < rows and 0 <= col < columns and matrix[row][col] != "R":
return True
print("Alice didn't make it to the tea party.")
rabit_row, rabit_col = find_position("R", False)
if rabit_row + rabit_col == row + col:
matrix[row][col] = "*"
show_result()
exit()
def find_position(symbol, alice=True):
for row in range(rows):
if symbol in matrix[row]:
col = matrix[row].index(symbol)
if alice:
matrix[row][col] = "*"
return row, col
alice_row, alice_col = find_position("A")
def alice_movement(row, col, movement_pos):
move_row, move_col = row + movement[movement_pos][0], col + movement[movement_pos][1]
if check_movement(move_row, move_col):
if matrix[move_row][move_col][-1].isdigit():
score[0] += int(matrix[move_row][move_col])
matrix[move_row][move_col] = "*"
return move_row, move_col
def show_result():
[print(*matrix[row]) for row in range(rows)]
while score[0] < 10:
move = input()
alice_row, alice_col = alice_movement(alice_row, alice_col, move)
print("She did it! She went to the party.")
show_result()