-
Notifications
You must be signed in to change notification settings - Fork 18
/
script.py
73 lines (62 loc) · 2.16 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
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
pass
def ActTeam(team):
# complete this function
pass