-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.py
229 lines (192 loc) · 6.87 KB
/
script.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
import random
import math
name = "script"
def moveTo(x, y, Pirate):
position = Pirate.getPosition()
if position[0] == x and position[1] == y:
return 0
if position[0] == x:
return (position[1] < y) * 2 + 1
if position[1] == y:
return (position[0] > x) * 2 + 2
if random.randint(1, 2) == 1:
return (position[0] > x) * 2 + 2
else:
return (position[1] < y) * 2 + 1
def moveAway(x, y, Pirate):
position = Pirate.getPosition()
if position[0] == x and position[1] == y:
return random.randint(1, 4)
if random.randint(1, 2) == 1:
return (position[0] < x) * 2 + 2
else:
return (position[1] > y) * 2 + 1
def circleAround(x, y, radius, Pirate, initial="abc", clockwise=True):
position = Pirate.getPosition()
rx = position[0]
ry = position[1]
pos = [[x + i, y + radius] for i in range(-1 * radius, radius + 1)]
pos.extend([[x + radius, y + i] for i in range(radius - 1, -1 * radius - 1, -1)])
pos.extend([[x + i, y - radius] for i in range(radius - 1, -1 * radius - 1, -1)])
pos.extend([[x - radius, y + i] for i in range(-1 * radius + 1, radius)])
if [rx, ry] not in pos:
if initial != "abc":
return moveTo(initial[0], initial[1], Pirate)
if rx in [x + i for i in range(-1 * radius, radius + 1)] and ry in [
y + i for i in range(-1 * radius, radius + 1)
]:
return moveAway(x, y, Pirate)
else:
return moveTo(x, y, Pirate)
else:
index = pos.index([rx, ry])
return moveTo(
pos[(index + (clockwise * 2) - 1) % len(pos)][0],
pos[(index + (clockwise * 2) - 1) % len(pos)][1],
Pirate,
)
def checkIsland(pirate):
up = pirate.investigate_up()
down = pirate.investigate_down()
left = pirate.investigate_left()
right = pirate.investigate_right()
if (up[0:-1] == "island" or down[0:-1] == "island") and (left[0:-1] == "island" or right[0:-1] == "island"):
return True
else:
return False
def ActPirate(pirate):
# complete this function
up = pirate.investigate_up()
down = pirate.investigate_down()
left = pirate.investigate_left()
right = pirate.investigate_right()
x, y = pirate.getPosition()
pirate.setSignal("")
s = pirate.trackPlayers()
if (
(up == "island1" and s[0] != "myCaptured")
or (up == "island2" and s[1] != "myCaptured")
or (up == "island3" and s[2] != "myCaptured")
):
s = up[-1] + str(x) + "," + str(y - 1)
b += 1
pirate.setSignal("left")
if (
(down == "island1" and s[0] != "myCaptured")
or (down == "island2" and s[1] != "myCaptured")
or (down == "island3" and s[2] != "myCaptured")
):
s = down[-1] + str(x) + "," + str(y + 1)
b += 1
pirate.setSignal("left")
if (
(left == "island1" and s[0] != "myCaptured")
or (left == "island2" and s[1] != "myCaptured")
or (left == "island3" and s[2] != "myCaptured")
):
s = left[-1] + str(x - 1) + "," + str(y)
b += 1
pirate.setSignal("left")
if (
(right == "island1" and s[0] != "myCaptured")
or (right == "island2" and s[1] != "myCaptured")
or (right == "island3" and s[2] != "myCaptured")
):
s = right[-1] + str(x + 1) + "," + str(y)
b += 1
pirate.setSignal("left")
if (
(up == "island1" and s[0] == "myCaptured")
or (up == "island2" and s[1] == "myCaptured")
or (up == "island3" and s[2] == "myCaptured")
):
pirate.setSignal("left")
if (
(right == "island1" and s[0] == "myCaptured")
or (right == "island2" and s[1] == "myCaptured")
or (right == "island3" and s[2] == "myCaptured")
):
# pirate.SetTeamSignal(s)
pirate.setSignal("left")
if (
(down == "island1" and s[0] == "myCaptured")
or (down == "island2" and s[1] == "myCaptured")
or (down == "island3" and s[2] == "myCaptured")
):
s = down[-1] + str(x) + "," + str(y + 1)
pirate.setSignal("left")
if (
(left == "island1" and s[0] == "myCaptured")
or (left == "island2" and s[1] == "myCaptured")
or (left == "island3" and s[2] == "myCaptured")
):
pirate.setSignal("left")
if (up == "friend"):
if checkIsland(pirate) and b<= 4:
pirate.setSignal("left")
else:
s = up[-1] + str(x) + "," + str(y + 1)
pirate.setSignal("move")
if (down == "friend"):
if checkIsland(pirate) and b<= 4:
pirate.setSignal("left")
else:
s = up[-1] + str(x) + "," + str(y - 1)
pirate.setSignal("move")
if (left == "friend"):
if checkIsland(pirate) and b<= 4:
pirate.setSignal("left")
else:
s = up[-1] + str(x - 1) + "," + str(y)
pirate.setSignal("move")
if (right == "friend" ) :
if checkIsland(pirate) and b<= 4:
pirate.setSignal("left")
else:
s = up[-1] + str(x + 1) + "," + str(y)
pirate.setSignal("move")
if (up != "friend" and up != "enemy" ):
if checkIsland(pirate) and b<= 4:
pirate.setSignal("left")
else:
pirate.setSignal("random")
if (down != "friend" and down != "enemy"):
if checkIsland(pirate) and b<= 4:
pirate.setSignal("left")
else:
pirate.setSignal("random")
if (left != "friend" and left != "enemy" ):
if checkIsland(pirate) and b<= 4:
pirate.setSignal("left")
else:
pirate.setSignal("random")
if (right != "friend" and right != "enemy"):
if checkIsland(pirate) and b<= 4:
pirate.setSignal("left")
else:
pirate.setSignal("random")
if pirate.getSignal() =="left":
return 0
elif pirate.getSignal() == "move":
s = pirate.GetCurrentTeamSignal()
l = s.split(",")
x = int(l[0][1:])
y = int(l[1])
return moveTo(x, y, pirate)
elif pirate.getSignal() == "random":
return random.randint(1,4)
pass
def ActTeam(team):
if team.getTotalPirates()>150 & team.getTotalRum()>50 & team.getTotalGunpowder()>50:
# complete this function
l = team.trackPlayers()
s = team.getTeamSignal()
team.buildWalls(1)
team.buildWalls(2)
team.buildWalls(3)
if s:
island_no = int(s[0])
signal = l[island_no - 1]
if signal == "myCaptured":
team.setTeamSignal("")
pass