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