-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathECBot-3.py
More file actions
87 lines (56 loc) · 2.32 KB
/
Copy pathECBot-3.py
File metadata and controls
87 lines (56 loc) · 2.32 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
import hlt
import logging
game = hlt.Game("ECBot-3")
logging.info("Starting ECBot-1")
turno = 0
while True:
turno += 1
command_queue = []
game_map = game.update_map()
my_ships = game_map.get_me().all_ships()
logging.info(len(my_ships))
for ship in my_ships:
if len(my_ships) > 25:
if ship.id % 2 == turno % 2:
continue
if ship.docking_status != ship.DockingStatus.UNDOCKED:
# Skip this ship
continue
entities_by_distance = game_map.nearby_entities_by_distance(ship)
distances_list = sorted([key for key in entities_by_distance])
planets_by_distance = []
not_owned_planets_by_distance = []
enemy_ships_by_distance = []
for distance in distances_list:
for entity in entities_by_distance[distance]:
if isinstance(entity, hlt.entity.Planet):
planets_by_distance.append(entity)
elif isinstance(entity, hlt.entity.Ship) and entity not in my_ships:
enemy_ships_by_distance.append(entity)
not_owned_planets_by_distance = [planet for planet in planets_by_distance if not planet.is_owned()]
for planet in planets_by_distance:
if ship.can_dock(planet) and not planet.is_full():
command_queue.append(ship.dock(planet))
break
if len(not_owned_planets_by_distance) > 0:
navigate_command = ship.navigate(
ship.closest_point_to(not_owned_planets_by_distance[0]),
game_map,
speed=int(hlt.constants.MAX_SPEED),
ignore_ships=False)
if navigate_command:
command_queue.append(navigate_command)
break
elif len(enemy_ships_by_distance) > 0:
navigate_command = ship.navigate(
ship.closest_point_to(enemy_ships_by_distance[0]),
game_map,
speed=int(hlt.constants.MAX_SPEED),
ignore_ships=False)
if navigate_command:
command_queue.append(navigate_command)
break
break
game.send_command_queue(command_queue)
#Fin del turno
#Fin del juego