-
Notifications
You must be signed in to change notification settings - Fork 0
/
Angels_and_Devils.py
142 lines (114 loc) · 3.37 KB
/
Angels_and_Devils.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
def createMatrix(row, col, val=0):
mat = []
while len(mat)<row:
m = []
while len(m)<col:
m.append(val)
mat.append(m)
return mat
def printMatrix(mat, index=0):
for i in range(index, len(mat)):
for j in range(index, len(mat[i])):
print(mat[i][j], end=" ")
print()
def kill(x,y, dev, dev_pos):
mat = createMatrix(13, 13)
xi_r, xi_c, og_r, og_c, ze_r, ze_c;
for i in range(3):
if(dev[i]=='X'):
xi_r = dev_pos[i][0], xi_c = dev_pos[i][1];
if(dev[i]=='O'):
og_r = dev_pos[i][0], og_c = dev_pos[i][1];
if(dev[i]=='Z'):
ze_r = dev_pos[i][0], ze_c = dev_pos[i][1];
// ZeeSnake mov direction
bool flag = true, down = true, right = true;
// movement direction for Angel
char move;
if(x==1) move='d';
else if(x==12) move='u';
else if(y==1) move='r';
else move='l';
for(int i=1; i<=12; i++) {
// mark as visited
mat[ze_r][ze_c] = -1;
// cout<<i<<endl;
// cout<<move<<endl;
// cout<<"x:"<<x<<" "<<"y:"<<y<<endl;
// cout<<"og_r:"<<og_r<<" "<<"og_c:"<<og_c<<endl;
// cout<<"xi_r:"<<xi_r<<" "<<"xi_c:"<<xi_c<<endl;
// cout<<"ze_r:"<<ze_r<<" "<<"ze_c:"<<ze_c<<endl;
// For ZeeSnake
if(mat[x][y]==-1) {
char ch = 'A'+y-1;
cout<<ch<<x<<endl;
return;
}
// moving ZeeSnake
if(flag) {
// down/up
if(ze_r==12) down = false;
if(ze_r==1) down = true;
if(down) ze_r++;
else ze_r--;
flag = false;
}
else {
// right/left
if(ze_c==12) right = false;
if(ze_c==1) right = true;
if(right) ze_c++;
else ze_c--;
flag = true;
}
// For xixi
if(((xi_r%2==xi_c%2) == (x%2==y%2)) && i==xi_r) {
char ch = 'A'+y-1;
cout<<ch<<x<<endl;
return;
}
// For Ogre
if(i==2) {
bool kill = false;
if(og_r+1==x && og_c==y) kill = true;
else if(og_r-1==x && og_c==y) kill = true;
else if(og_r==x && og_c+1==y) kill = true;
else if(og_r==x && og_c-1==y) kill = true;
else if(og_r-1==x && og_c-1==y) kill = true;
else if(og_r+1==x && og_c+1==y) kill = true;
else if(og_r+1==x && og_c-1==y) kill = true;
else if(og_r-1==x && og_c+1==y) kill = true;
if(kill) {
char ch = 'A'+y-1;
cout<<ch<<x<<endl;
return;
}
}
else if(i==3 && og_r==x && og_c==y) {
char ch = 'A'+y-1;
cout<<ch<<x<<endl;
return;
}
// movement direction of Angel
if(move=='d') x++;
if(move=='u') x--;
if(move=='r') y++;
if(move=='l') y--;
}
cout<<"SS"<<endl;
return;
def solve():
# angel
angel = input()
y = ord(angel[0])-65+1
x = int(angel[1:])
#print(x,y)
# devils
dev = list(input().split(','))
#print(dev)
# devil's corresponding positions
dev_pos = list(map(lambda p:(int(p[1:]), ord(p[0])-65+1), input().split(',')))
#print(dev_pos)
kill(x,y, dev, dev_pos)
if __name__=='__main__':
solve()