-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMybot.py
51 lines (36 loc) · 1.03 KB
/
Mybot.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
def do_turn(pw):
dis = dis1 = 999999
dest = dest1 = 1
if len(pw.my_planets()) == 0:
return
source = maxShips(pw.my_planets())
if len(pw.neutral_planets()) >= 1:
dest,dis = destPlanet(pw,source,pw.neutral_planets())
if len(pw.enemy_planets()) >= 1:
dest1,dis1 = destPlanet(pw,source,pw.enemy_planets())
"""pw.debug(dis)
pw.debug(dis1)"""
if dis > dis1:
dest = dest1
num_ships = source.num_ships() -1
pw.issue_order(source, dest, num_ships)
def destPlanet(pw, sorce, planets):
dest = planets[0]
min = pw.distance(sorce,dest)
for planet in planets:
dis = pw.distance(sorce,planet)
if(dis<min):
min = dis
dest = planet
return dest,min
def maxShips(planets):
max= 0
for planet in planets:
sh = planet.num_ships()
if sh > max:
max = sh
p = planet
elif sh == max:
if p.growth_rate()< planet.growth_rate():
p = planet
return p