2
2
import logging
3
3
from operator import itemgetter
4
4
5
- game = hlt .Game ("D4m0b0t - v2b - rewrite & flow restructuring" )
5
+ game = hlt .Game ("D4m0b0t - v2.1b - rewrite & flow restructuring" )
6
6
7
7
def docked_actions (current_ship ):
8
8
"""
@@ -36,41 +36,21 @@ def docked_actions(current_ship):
36
36
undock_process_list [current_ship ] = current_ship .planet
37
37
command_queue .append (ship .undock (current_ship .planet ))
38
38
39
- def undocked_actions (current_ship ):
39
+ def target_planet (current_ship , planets_ranked_by_distance , planets_ranked_ours_by_docked , planets_ranked_untapped ):
40
40
"""
41
- Determine what to do with the undocked ship
41
+ Determine if a planet is a viable target for mining; create the navigation command if so
42
42
:param Ship current_ship:
43
- :return: command to append to the command_queue
44
- :rtype: List
43
+ :param List of Tuples planets_ranked_by_distance:
44
+ :param List of Tuples planets_ranked_ours_by_docked:
45
+ :param List of Tuples planets_ranked_untapped:
46
+ :return: navigation command for command_queue or None
47
+ :rtype: String or None
45
48
"""
46
- if DEBUGGING ['method_entry' ]:
47
- log .debug ("undocked_actions():" )
48
-
49
- if DEBUGGING ['ship_loop' ]:
50
- log .debug ("-+=Undocked ship #" + str (current_ship .id ) + "=+-" )
51
-
52
- #did we just complete undocking?
53
- if current_ship in undock_process_list .keys ():
54
- if DEBUGGING ['docking_procedures' ]:
55
- log .debug (" - completed undocking" )
56
-
57
- undock_process_list .remove (current_ship )
58
-
59
- success = False
60
- ranked_planets_by_distance = entity_sort_by_distance (current_ship , game_map .all_planets ())
61
- ranked_our_planets_by_docked = planet_sort_ours_by_docked (game_map .all_planets ())
62
- enemies = get_enemy_ships ()
63
49
navigate_command = None
64
50
65
- #avoid boobytraps in our considerations
66
- #if len(planets_to_avoid) > 0:
67
- ranked_untapped_planets = remove_tapped_planets (ranked_planets_by_distance , planets_to_avoid )
68
- #else:
69
- # ranked_untapped_planets = ranked_planets_by_distance
70
-
71
51
#do we navigate to a planet, reinforce, or go offensive?
72
52
#navigate to a planet or begin docking (this also currently handles reinforcing)
73
- for potential_planet in remove_held_planets (ranked_untapped_planets ):
53
+ for potential_planet in remove_held_planets (planets_ranked_untapped ):
74
54
if (potential_planet ['entity_object' ] in targeted_list ) or \
75
55
(potential_planet ['entity_object' ].num_docking_spots == len (potential_planet ['entity_object' ].all_docked_ships ())):
76
56
if DEBUGGING ['targeting' ]:
@@ -85,7 +65,7 @@ def undocked_actions(current_ship):
85
65
navigate_command = current_ship .dock (potential_planet ['entity_object' ])
86
66
if potential_planet ['entity_object' ] in targeted_list :
87
67
if DEBUGGING ['planet_selection' ]:
88
- log .debug (" - removing planet #" + str (potential_planet ['entity_object' ].id + " from targeted_list" ) )
68
+ log .debug (" - removing planet #" + str (potential_planet ['entity_object' ].id ) + " from targeted_list" )
89
69
90
70
targeted_list .remove (potential_planet ['entity_object' ])
91
71
break
@@ -101,37 +81,117 @@ def undocked_actions(current_ship):
101
81
ignore_ships = False )
102
82
break
103
83
104
- if not navigate_command :
105
- #potential_angle = other_entities_in_vicinity(current_ship, enemies, ranked_untapped_planets[0]['distance'])
106
- if ALGORITHM ['offense' ]: # and potential_angle:
107
- #another entity is closer or at the same distance; we need to go offensive
108
- if DEBUGGING ['offense' ]:
109
- log .debug ("Engaging enemy" )
84
+ return navigate_command
110
85
111
- navigate_command = current_ship .navigate (
112
- current_ship .closest_point_to (entity_sort_by_distance (current_ship , enemies )[0 ]['entity_object' ]),
113
- game_map ,
114
- speed = default_speed ,
115
- ignore_ships = False )
116
- elif ALGORITHM ['reinforce' ] and len (ranked_our_planets_by_docked ) > 0 :
117
- #reinforce that sucker
118
- if DEBUGGING ['reinforce' ]:
119
- log .debug ("Reinforcing planet #" + str (ranked_our_planets_by_docked [0 ]['entity_object' ].id ))
120
-
121
- if current_ship .can_dock (ranked_our_planets_by_docked [0 ]['entity_object' ]):
122
- if DEBUGGING ['reinforce' ]:
123
- log .debug (" - docking @ planet #" + str (ranked_our_planets_by_docked [0 ]['entity_object' ].id ))
86
+ def go_offensive (current_ship , enemies ):
87
+ """
88
+ Returns navigation command for offense, or None if not the best course of action at this juncture
89
+ :param Ship current_ship:
90
+ :param List of Tuples enemies:
91
+ :return navigation_command or None:
92
+ :rtype: String or None
93
+ """
94
+ navigate_command = None
95
+
96
+ if DEBUGGING ['offense' ]:
97
+ log .debug ("Engaging enemy" )
98
+
99
+ closest_enemy = entity_sort_by_distance (current_ship , enemies )[0 ]['entity_object' ]
100
+
101
+ if ALGORITHM ['kamikaze' ]:
102
+ potential_kamikaze_angle = other_entities_in_vicinity (current_ship , enemies , 100 )
103
+
104
+ if DEBUGGING ['kamikaze' ]:
105
+ log .debug (" - potential_kamikaze_angle: " + str (potential_kamikaze_angle ))
106
+
107
+ if potential_kamikaze_angle :
108
+ if DEBUGGING ['kamikaze' ] and DEBUGGING ['offense' ]:
109
+ log .debug (" - going kamikaze" )
110
+
111
+ navigate_command = current_ship .thrust (hlt .constants .MAX_SPEED , potential_kamikaze_angle )
112
+
113
+ if not navigate_command :
114
+ if DEBUGGING ['offense' ]:
115
+ log .debug (" - engaging ship #" + str (closest_enemy .id ))
116
+
117
+ navigate_command = current_ship .navigate (
118
+ current_ship .closest_point_to (closest_enemy ),
119
+ game_map ,
120
+ speed = default_speed ,
121
+ ignore_ships = False )
122
+
123
+ return navigate_command
124
+
125
+ def reinforce_planet (current_ship , our_planets_by_docked , our_ranked_untapped_planets ):
126
+ """
127
+ Create navigation command to reinforce the nearest planet with an open docking spot
128
+ NOTE: This is currently not utilized, and almost certainly broken
129
+ :param Ship current_ship: derp
130
+ :param List our_planets_by_docked: List of Tuples
131
+ :param List our_ranked_untapped_planets: List of Tuples
132
+ :return String navigation_command:
133
+ :rtype: String
134
+ """
135
+ navigation_command = None
136
+
137
+ #reinforce that sucker
138
+ if DEBUGGING ['reinforce' ]:
139
+ log .debug ("Reinforcing planet #" + str (ranked_our_planets_by_docked [0 ]['entity_object' ].id ))
140
+
141
+ if current_ship .can_dock (ranked_our_planets_by_docked [0 ]['entity_object' ]):
142
+ if DEBUGGING ['reinforce' ]:
143
+ log .debug (" - docking @ planet #" + str (ranked_our_planets_by_docked [0 ]['entity_object' ].id ))
144
+
145
+ navigate_command = current_ship .dock (ranked_our_planets_by_docked [0 ]['entity_object' ])
146
+ else :
147
+ if DEBUGGING ['reinforce' ]:
148
+ log .debug (" - navigating to reinforce planet #" + str (ranked_untapped_planets [0 ]['entity_object' ]))
149
+
150
+ navigate_command = current_ship .navigate (
151
+ current_ship .closest_point_to (ranked_untapped_planets [0 ]['entity_object' ]),
152
+ game_map ,
153
+ speed = default_speed ,
154
+ ignore_ships = False )
155
+
156
+ return navigation_command
157
+
158
+ def undocked_actions (current_ship ):
159
+ """
160
+ Determine what to do with the undocked ship
161
+ :param Ship current_ship:
162
+ :return: command to append to the command_queue
163
+ :rtype: List
164
+ """
165
+ if DEBUGGING ['method_entry' ]:
166
+ log .debug ("undocked_actions():" )
167
+
168
+ if DEBUGGING ['ship_loop' ]:
169
+ log .debug ("-+=Undocked ship #" + str (current_ship .id ) + "=+-" )
170
+
171
+ #did we just complete undocking?
172
+ if current_ship in undock_process_list .keys ():
173
+ if DEBUGGING ['docking_procedures' ]:
174
+ log .debug (" - completed undocking" )
124
175
125
- navigate_command = current_ship .dock (ranked_our_planets_by_docked [0 ]['entity_object' ])
126
- else :
127
- if DEBUGGING ['reinforce' ]:
128
- log .debug (" - navigating to reinforce planet #" + str (ranked_untapped_planets [0 ]['entity_object' ]))
176
+ undock_process_list .remove (current_ship )
129
177
130
- navigate_command = current_ship .navigate (
131
- current_ship .closest_point_to (ranked_untapped_planets [0 ]['entity_object' ]),
132
- game_map ,
133
- speed = default_speed ,
134
- ignore_ships = False )
178
+ success = False
179
+ ranked_planets_by_distance = entity_sort_by_distance (current_ship , game_map .all_planets ())
180
+ ranked_our_planets_by_docked = planet_sort_ours_by_docked (game_map .all_planets ())
181
+ ranked_untapped_planets = remove_tapped_planets (ranked_planets_by_distance , planets_to_avoid )
182
+ enemies = get_enemy_ships ()
183
+
184
+ #get our command, if navigation to/docking with a planet is the best course of action
185
+ #else None
186
+ navigate_command = target_planet (current_ship , ranked_planets_by_distance , ranked_our_planets_by_docked , \
187
+ ranked_untapped_planets )
188
+
189
+ if not navigate_command :
190
+ #potential_angle = other_entities_in_vicinity(current_ship, enemies, ranked_untapped_planets[0]['distance'])
191
+ if ALGORITHM ['offense' ]: # and potential_angle:
192
+ navigate_command = go_offensive (current_ship , enemies )
193
+ elif ALGORITHM ['reinforce' ] and len (ranked_our_planets_by_docked ) > 0 :
194
+ navigate_command = reinforce_planet (current_ship , ranked_our_planets_by_docked , ranked_untapped_planets )
135
195
136
196
return navigate_command
137
197
@@ -200,15 +260,41 @@ def other_entities_in_vicinity(current_entity, other_entities, scan_distance):
200
260
:param Entity current_entity:
201
261
:param List other_entities:
202
262
:param integer scan_distance:
203
- :return: Angle between this entity and the first other found within collision risk area, or None
204
- :rtype: float
263
+ :return: Collision angle if any
264
+ :rtype: Collision angle or none
205
265
"""
206
266
if DEBUGGING ['method_entry' ]:
207
267
log .debug ("other_entities_in_vicinity()" )
208
-
268
+
269
+ #closest_docked_distance = scan_distance
270
+ target_planet = None
271
+
209
272
for other_entity in other_entities :
210
- if current_entity .calculate_distance_between (other_entity ) <= scan_distance :
211
- return current_entity .calculate_angle_between (other_entity )
273
+ #if other_entity.docking_status == current_entity.DockingStatus.DOCKED or \
274
+ # other_entity.docking_status == current_entity.DockingStatus.DOCKING:
275
+ if current_entity .planet :
276
+ continue
277
+
278
+ proximity = int (current_entity .calculate_distance_between (other_entity ))
279
+ if DEBUGGING ['kamikaze' ]:
280
+ log .debug ("\t - current_entity's proximity: " + str (proximity ) + " vs scan_distance: " + str (scan_distance ))
281
+
282
+ if proximity < scan_distance :
283
+ if DEBUGGING ['kamikaze' ]:
284
+ log .debug ("\t - proximity is less than scan_distance" )
285
+
286
+ if current_entity .docking_status == current_entity .DockingStatus .DOCKED or \
287
+ current_entity .docking_status == current_entity .DockingStatus .DOCKING :
288
+ if DEBUGGING ['kamikaze' ]:
289
+ log .debug ("\t \t - setting target_planet to current_entity.planet" )
290
+
291
+ target_planet = current_entity .planet
292
+ break
293
+ else :
294
+ continue
295
+
296
+ if target_planet :
297
+ return current_entity .calculate_angle_between (target_planet )
212
298
213
299
return None
214
300
@@ -268,17 +354,19 @@ def remove_tapped_planets(testing_planets, avoid_planets):
268
354
#constants
269
355
DEBUGGING = {
270
356
'ship_loop' : True ,
271
- 'docking_procedures' : True ,
272
- 'reinforce' : True ,
357
+ 'docking_procedures' : False ,
358
+ 'reinforce' : False ,
273
359
'offense' : True ,
360
+ 'kamikaze' : False ,
274
361
'planet_selection' : True ,
275
362
'targeting' : True ,
276
- 'boobytrapping' : True ,
363
+ 'boobytrapping' : False ,
277
364
'method_entry' : True
278
365
}
279
366
ALGORITHM = {
280
367
'reinforce' : False ,
281
368
'offense' : True ,
369
+ 'kamikaze' : False ,
282
370
'boobytrapping' : True
283
371
}
284
372
@@ -288,6 +376,7 @@ def remove_tapped_planets(testing_planets, avoid_planets):
288
376
planets_to_avoid = []
289
377
dock_process_list = {}
290
378
undock_process_list = {}
379
+ enemy_data = {}
291
380
292
381
#init
293
382
log = logging .getLogger (__name__ )
@@ -321,6 +410,3 @@ def remove_tapped_planets(testing_planets, avoid_planets):
321
410
#end per-ship iteration
322
411
323
412
game .send_command_queue (command_queue )
324
-
325
-
326
-
0 commit comments