-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyBot_v2_split.py
More file actions
208 lines (174 loc) · 8.72 KB
/
MyBot_v2_split.py
File metadata and controls
208 lines (174 loc) · 8.72 KB
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
import hlt
import logging
import os
from collections import OrderedDict
######Made two lists of ships to do two different things at the same time#####
game = hlt.Game("SheckyBotv2_split")
logging.info("Go Shecky bot")
def largest_dockable_planet(plan):
# logging.info("test" + str(plan))
if plan:
return max([planet for planet in plan if not planet.is_owned()], key=lambda x: x.radius)
else:
return None
turn_num = 0
while True:
game_map = game.update_map()
command_queue = []
my_ships = game_map.get_me().all_ships()
my_id = game_map.get_me().id
for ship in my_ships:
shipid = ship.id
if ship.docking_status != ship.DockingStatus.UNDOCKED:
continue
entities_by_distance = game_map.nearby_entities_by_distance(ship)
entities_by_distance = OrderedDict(sorted(entities_by_distance.items(), key=lambda x: x[0]))
closest_empty_planets = [entities_by_distance[distance][0] for distance in entities_by_distance if isinstance(entities_by_distance[distance][0], hlt.entity.Planet) and not entities_by_distance[distance][0].is_owned()]
closest_owned_planets = [entities_by_distance[distance][0] for distance in entities_by_distance if isinstance(entities_by_distance[distance][0], hlt.entity.Planet) and entities_by_distance[distance][0].is_owned()]
my_planets = []
### have bots chase me when they get to a certain distance ###
### can do distance to coordinates for diff coordinance ###
for planet in closest_owned_planets:
if planet.owner.id == my_id:
my_planets.append(planet)
my_planets_not_full = []
for planet in my_planets:
if not planet.is_full():
my_planets_not_full.append(planet)
my_planets_full = []
for planet in my_planets:
if planet.is_full():
my_planets_full.append(planet)
enemy_planets_not_full = []
for planet in closest_owned_planets:
if planet.owner.id != my_id:
if not planet.is_full():
enemy_planets_not_full.append(planet)
enemy_planets_owned = []
for planet in closest_owned_planets:
if planet.owner.id != my_id:
enemy_planets_owned.append(planet)
closest_enemy_ships = [entities_by_distance[distance][0] for distance in entities_by_distance if isinstance(entities_by_distance[distance][0], hlt.entity.Ship) and entities_by_distance[distance][0] not in my_ships]
if len(my_ships) <= 3:
if len(closest_empty_planets) > 0:
if shipid % 2 == 0:
target_planet = largest_dockable_planet(closest_empty_planets)
if target_planet:
if ship.can_dock(target_planet):
command_queue.append(ship.dock(target_planet))
else:
navigate_command = ship.navigate(
ship.closest_point_to(target_planet),
game_map,
speed=int(hlt.constants.MAX_SPEED),
ignore_ships=False)
if navigate_command:
command_queue.append(navigate_command)
else:
continue
elif shipid % 2 != 0:
target_planet = closest_empty_planets[0]
if target_planet:
if ship.can_dock(target_planet):
command_queue.append(ship.dock(target_planet))
else:
navigate_command = ship.navigate(
ship.closest_point_to(target_planet),
game_map,
speed=int(hlt.constants.MAX_SPEED),
ignore_ships=False)
if navigate_command:
command_queue.append(navigate_command)
else:
continue
elif len(closest_enemy_ships) > 0:
target_ship = closest_enemy_ships[0]
navigate_command = ship.navigate(
ship.closest_point_to(target_ship),
game_map,
speed=int(hlt.constants.MAX_SPEED),
ignore_ships=False)
if navigate_command:
command_queue.append(navigate_command)
elif len(my_ships) > 3:
if len(my_ships) > len(closest_enemy_ships) + 2:
target_ship = closest_enemy_ships[0]
navigate_command = ship.navigate(
ship.closest_point_to(target_ship),
game_map,
speed=int(hlt.constants.MAX_SPEED),
ignore_ships=False)
if navigate_command:
command_queue.append(navigate_command)
elif len(my_ships) <= len(closest_enemy_ships) + 2:
if len(closest_empty_planets) >= 6:
target_planet = largest_dockable_planet(closest_empty_planets)
if target_planet:
if ship.can_dock(target_planet):
command_queue.append(ship.dock(target_planet))
else:
navigate_command = ship.navigate(
ship.closest_point_to(target_planet),
game_map,
speed=int(hlt.constants.MAX_SPEED),
ignore_ships=False)
if navigate_command:
command_queue.append(navigate_command)
# elif len(closest_enemy_ships) > 0:
# target_ship = closest_enemy_ships[0]
# navigate_command = ship.navigate(
# ship.closest_point_to(target_ship),
# game_map,
# speed=int(hlt.constants.MAX_SPEED / 1.25),
# ignore_ships=False)
# if navigate_command:
# command_queue.append(navigate_command)
elif len(closest_empty_planets) == 5:
target_planet = largest_dockable_planet(closest_empty_planets)
if target_planet:
if ship.can_dock(target_planet):
command_queue.append(ship.dock(target_planet))
else:
navigate_command = ship.navigate(
ship.closest_point_to(target_planet),
game_map,
speed=int(hlt.constants.MAX_SPEED),
ignore_ships=False)
if navigate_command:
command_queue.append(navigate_command)
elif len(closest_empty_planets) == 1:
target_planet = closest_empty_planets[0]
if target_planet:
if ship.can_dock(target_planet):
command_queue.append(ship.dock(target_planet))
else:
navigate_command = ship.navigate(
ship.closest_point_to(target_planet),
game_map,
speed=int(hlt.constants.MAX_SPEED / 1.5),
ignore_ships=False)
if navigate_command:
command_queue.append(navigate_command)
elif len(closest_enemy_ships) > 0:
target_ship = closest_enemy_ships[0]
navigate_command = ship.navigate(
ship.closest_point_to(target_ship),
game_map,
speed=int(hlt.constants.MAX_SPEED),
ignore_ships=False)
if navigate_command:
command_queue.append(navigate_command)
elif len(closest_enemy_ships) > 0:
target_ship = closest_enemy_ships[0]
navigate_command = ship.navigate(
ship.closest_point_to(target_ship),
game_map,
speed=int(hlt.constants.MAX_SPEED),
ignore_ships=False)
if navigate_command:
command_queue.append(navigate_command)
#####
turn_num += 1
game.send_command_queue(command_queue)
# turn over
# game over