Skip to content

Commit b1cd004

Browse files
committed
idk
1 parent d2ce44a commit b1cd004

File tree

4 files changed

+519
-58
lines changed

4 files changed

+519
-58
lines changed

sample_scripts/sample1.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import random
2+
import math
3+
4+
name = "sample1"
5+
6+
7+
def moveTo(x, y, Pirate):
8+
position = Pirate.getPosition()
9+
if position[0] == x and position[1] == y:
10+
return 0
11+
if position[0] == x:
12+
return (position[1] < y) * 2 + 1
13+
if position[1] == y:
14+
return (position[0] > x) * 2 + 2
15+
if random.randint(1, 2) == 1:
16+
return (position[0] > x) * 2 + 2
17+
else:
18+
return (position[1] < y) * 2 + 1
19+
20+
21+
def ActPirate(pirate):
22+
up = pirate.investigate_up()
23+
down = pirate.investigate_down()
24+
left = pirate.investigate_left()
25+
right = pirate.investigate_right()
26+
x, y = pirate.getPosition()
27+
pirate.setSignal("")
28+
s = pirate.trackPlayers()
29+
30+
if (
31+
(up == "island1" and s[0] != "myCaptured")
32+
or (up == "island2" and s[1] != "myCaptured")
33+
or (up == "island3" and s[2] != "myCaptured")
34+
):
35+
s = up[-1] + str(x) + "," + str(y - 1)
36+
pirate.setTeamSignal(s)
37+
38+
if (
39+
(down == "island1" and s[0] != "myCaptured")
40+
or (down == "island2" and s[1] != "myCaptured")
41+
or (down == "island3" and s[2] != "myCaptured")
42+
):
43+
s = down[-1] + str(x) + "," + str(y + 1)
44+
pirate.setTeamSignal(s)
45+
46+
if (
47+
(left == "island1" and s[0] != "myCaptured")
48+
or (left == "island2" and s[1] != "myCaptured")
49+
or (left == "island3" and s[2] != "myCaptured")
50+
):
51+
s = left[-1] + str(x - 1) + "," + str(y)
52+
pirate.setTeamSignal(s)
53+
54+
if (
55+
(right == "island1" and s[0] != "myCaptured")
56+
or (right == "island2" and s[1] != "myCaptured")
57+
or (right == "island3" and s[2] != "myCaptured")
58+
):
59+
s = right[-1] + str(x + 1) + "," + str(y)
60+
pirate.setTeamSignal(s)
61+
62+
63+
if pirate.getTeamSignal() != "":
64+
s = pirate.getTeamSignal()
65+
l = s.split(",")
66+
x = int(l[0][1:])
67+
y = int(l[1])
68+
69+
return moveTo(x, y, pirate)
70+
71+
else:
72+
return random.randint(1, 4)
73+
74+
75+
def ActTeam(team):
76+
l = team.trackPlayers()
77+
s = team.getTeamSignal()
78+
79+
team.buildWalls(1)
80+
team.buildWalls(2)
81+
team.buildWalls(3)
82+
83+
if s:
84+
island_no = int(s[0])
85+
signal = l[island_no - 1]
86+
if signal == "myCaptured":
87+
team.setTeamSignal("")

sample_scripts/sample2.py

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
import random
2+
import math
3+
4+
name = "sample2"
5+
6+
def moveTo(x, y, Pirate):
7+
position = Pirate.getPosition()
8+
if position[0] == x and position[1] == y:
9+
return 0
10+
if position[0] == x:
11+
return (position[1] < y) * 2 + 1
12+
if position[1] == y:
13+
return (position[0] > x) * 2 + 2
14+
if random.randint(1, 2) == 1:
15+
return (position[0] > x) * 2 + 2
16+
else:
17+
return (position[1] < y) * 2 + 1
18+
19+
20+
def moveAway(x, y, Pirate):
21+
position = Pirate.getPosition()
22+
if position[0] == x and position[1] == y:
23+
return random.randint(1, 4)
24+
if random.randint(1, 2) == 1:
25+
return (position[0] < x) * 2 + 2
26+
else:
27+
return (position[1] > y) * 2 + 1
28+
29+
def circleAround(x, y, radius, Pirate, initial="abc", clockwise=True):
30+
position = Pirate.getPosition()
31+
rx = position[0]
32+
ry = position[1]
33+
pos = [[x + i, y + radius] for i in range(-1 * radius, radius + 1)]
34+
pos.extend([[x + radius, y + i] for i in range(radius - 1, -1 * radius - 1, -1)])
35+
pos.extend([[x + i, y - radius] for i in range(radius - 1, -1 * radius - 1, -1)])
36+
pos.extend([[x - radius, y + i] for i in range(-1 * radius + 1, radius)])
37+
if [rx, ry] not in pos:
38+
if initial != "abc":
39+
return moveTo(initial[0], initial[1], Pirate)
40+
if rx in [x + i for i in range(-1 * radius, radius + 1)] and ry in [
41+
y + i for i in range(-1 * radius, radius + 1)
42+
]:
43+
return moveAway(x, y, Pirate)
44+
else:
45+
return moveTo(x, y, Pirate)
46+
else:
47+
index = pos.index([rx, ry])
48+
return moveTo(
49+
pos[(index + (clockwise * 2) - 1) % len(pos)][0],
50+
pos[(index + (clockwise * 2) - 1) % len(pos)][1],
51+
Pirate,
52+
)
53+
54+
def radius(pirate, x, y, x1, y1, r):
55+
pos = []
56+
for i in range(x1 - r, x1 + r + 1):
57+
for j in range(y1 - r, y1 + r + 1):
58+
pos.append((i, j))
59+
t = 0
60+
if (x, y) in pos:
61+
62+
circleAround(x1, y1, r, pirate)
63+
else:
64+
return moveAway(x1, y1, pirate)
65+
66+
67+
def ActPirate(pirate):
68+
up = pirate.investigate_up()
69+
down = pirate.investigate_down()
70+
left = pirate.investigate_left()
71+
right = pirate.investigate_right()
72+
x, y = pirate.getPosition()
73+
s = pirate.trackPlayers()
74+
tmp1 = ""
75+
tmp2 = ""
76+
tmp3 = ""
77+
tmp4 = ""
78+
if (
79+
(up == "island1" and s[0] != "myCaptured")
80+
or (up == "island2" and s[1] != "myCaptured")
81+
or (up == "island3" and s[2] != "myCaptured")
82+
):
83+
s = up[-1] + str(x) + "," + str(y - 1)
84+
tmp1 = up[-1] + str(x - 2) + "," + str(y - 1)
85+
tmp2 = up[-1] + str(x + 2) + "," + str(y - 1)
86+
tmp3 = up[-1] + str(x) + "," + str(y - 3)
87+
tmp4 = up[-1] + str(x) + "," + str(y + 1)
88+
89+
pirate.setTeamSignal(s)
90+
91+
if (
92+
(down == "island1" and s[0] != "myCaptured")
93+
or (down == "island2" and s[1] != "myCaptured")
94+
or (down == "island3" and s[2] != "myCaptured")
95+
):
96+
s = down[-1] + str(x) + "," + str(y + 1)
97+
tmp1 = up[-1] + str(x - 2) + "," + str(y + 1)
98+
tmp2 = up[-1] + str(x + 2) + "," + str(y + 1)
99+
tmp3 = up[-1] + str(x) + "," + str(y - 1)
100+
tmp4 = up[-1] + str(x) + "," + str(y + 3)
101+
pirate.setTeamSignal(s)
102+
103+
if (
104+
(left == "island1" and s[0] != "myCaptured")
105+
or (left == "island2" and s[1] != "myCaptured")
106+
or (left == "island3" and s[2] != "myCaptured")
107+
):
108+
s = left[-1] + str(x - 1) + "," + str(y)
109+
tmp1 = up[-1] + str(x - 3) + "," + str(y - 1)
110+
tmp2 = up[-1] + str(x + 1) + "," + str(y - 1)
111+
tmp3 = up[-1] + str(x - 1) + "," + str(y - 3)
112+
tmp4 = up[-1] + str(x - 1) + "," + str(y + 1)
113+
pirate.setTeamSignal(s)
114+
115+
if (
116+
(right == "island1" and s[0] != "myCaptured")
117+
or (right == "island2" and s[1] != "myCaptured")
118+
or (right == "island3" and s[2] != "myCaptured")
119+
):
120+
s = right[-1] + str(x + 1) + "," + str(y)
121+
tmp1 = up[-1] + str(x - 1) + "," + str(y - 1)
122+
tmp2 = up[-1] + str(x + 3) + "," + str(y - 1)
123+
tmp3 = up[-1] + str(x + 1) + "," + str(y - 3)
124+
tmp4 = up[-1] + str(x + 1) + "," + str(y + 1)
125+
pirate.setTeamSignal(s)
126+
127+
if tmp1 != "":
128+
pirate.setSignal(tmp1)
129+
ln = 1
130+
elif tmp2 != "":
131+
pirate.setSignal(tmp2)
132+
rn = 1
133+
elif tmp3 != "":
134+
pirate.setSignal(tmp3)
135+
un = 1
136+
elif tmp4 != "":
137+
pirate.setSignal(tmp4)
138+
dn = 1
139+
140+
if pirate.getSignal() != "":
141+
s2 = pirate.getSignal()
142+
l2 = s2.split(",")
143+
x2 = int(l2[0][1:])
144+
y2 = int(l2[1])
145+
position = pirate.getPosition()
146+
if position[0] == x2 and position[1] == y2:
147+
return 0
148+
return moveTo(x2, y2, pirate)
149+
150+
else:
151+
return random.randint(1, 4)
152+
153+
154+
def ActTeam(team):
155+
pass

0 commit comments

Comments
 (0)