-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyBot_v3_funct.py
More file actions
180 lines (127 loc) · 7.24 KB
/
MyBot_v3_funct.py
File metadata and controls
180 lines (127 loc) · 7.24 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
import hlt
import logging
from collections import OrderedDict
game = hlt.Game("SheckyBot_v3funct")
logging.info("Go Shecky bot")
#### TO DO. ADD GOING TO VULNERABLE PLANETS AND TEAM STUFF####
def largest_dockable_planet(planets):
if planets:
return max([planet for planet in planets if not planet.is_owned()], key=lambda x: x.radius)
else:
return None
def docking(target_planet, less_than):
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 + less_than),
ignore_ships=False)
if navigate_command:
command_queue.append(navigate_command)
def navigate_ship(target_ship):
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 = 0
#### Quadrant Centers of Map ####
TopL = hlt.entity.Position(60, 40)
TopR = hlt.entity.Position(180, 40)
BotR = hlt.entity.Position(180, 120)
BotL = hlt.entity.Position(60, 120)
center = hlt.entity.Position(120, 80)
Corners = [TopL, TopR, BotL, BotR]
while True:
game_map = game.update_map()
my_id = game_map.get_me().id
my_ships = game_map.get_me().all_ships()
all_planets = game_map.all_planets()
outside_planets = [planet for planet in all_planets if planet.id > 3]
players = game_map.all_players()
if len(players) == 2:
my_team_ships = my_ships
team_mate_id = my_id
else:
team_mate_id = None
if my_id == 0 or my_id == 1:
team_mate_id = my_id + 2
elif my_id == 2 or my_id == 3:
team_mate_id = my_id - 2
team_mate_ships = game_map.get_player(team_mate_id).all_ships()
my_team_ships = my_ships + team_mate_ships
# logging.info("my id:" + str(my_id))
# logging.info("teamid:" + str(team_mate_id))
# logging.info("my ships:" + str(len(my_ships)))
# logging.info("teamships: " + str(len(team_mate_ships)))
# logging.info("myteam" + str(len(my_team_ships)))
command_queue = []
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]))
### Ship info ###
my_undocked_ships = [ship for ship in my_ships if ship.docking_status == ship.DockingStatus.UNDOCKED]
my_docked_ships = [ship for ship in my_ships if ship.docking_status == ship.DockingStatus.DOCKED]
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_team_ships]
### Planet info ###
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 = [planet for planet in closest_owned_planets if planet.owner.id == my_id]
my_planets_full = [planet for planet in my_planets if planet.is_full()]
my_planets_not_full = [planet for planet in my_planets if not planet.is_full()]
my_team_planets = [planet for planet in closest_owned_planets if planet.owner.id == my_id or planet.owner.id == team_mate_id]
enemy_planets = [planet for planet in closest_owned_planets if planet.owner.id != my_id or planet.owner.id != team_mate_id]
vulnerable_enemy_planets = [planet for planet in enemy_planets if len(planet.all_docked_ships()) == 1]
vulnerable_enemy_ships = [ship for ship in vulnerable_enemy_planets]
logging.info("vul:" + str(len(vulnerable_enemy_planets)))
# continue
closest_planets = [entities_by_distance[distance][0] for distance in entities_by_distance if isinstance(entities_by_distance[distance][0], hlt.entity.Planet)]
closest_outside_planets = [planet for planet in closest_planets if planet.id > 3]
distance_between_my_ship_and_enemy_ship = ship.calculate_distance_between(closest_enemy_ships[0])
##### GAME TIME #####
##### I pretty much tested out every theory with every list in every order that I could think of...easily spend over a week just testing that out and came up with this final answer as winning the most #####
if turn_num <= 6 and len(my_ships) > len(closest_enemy_ships) + 2:
navigate_ship(closest_enemy_ships[0])
#logging.info("myships: " + str(my_id))
#logging.info("team_ships: " + str(team_ship))
else:
if len(my_planets_not_full) > 0 and len(closest_enemy_ships) > 0:
distance_between_my_ship_and_enemy_ship = ship.calculate_distance_between(closest_enemy_ships[0])
distance_between_my_ship_and_my_planet_not_full = ship.calculate_distance_between(my_planets_not_full[0])
if distance_between_my_ship_and_enemy_ship < 18:
navigate_ship(closest_enemy_ships[0])
logging.info("kill close ship:")
else:
docking(my_planets_not_full[0], 0)
logging.info("fillerUp:")
elif len(closest_empty_planets) > 0 and len(closest_enemy_ships) > 0:
if ship.can_dock(closest_empty_planets[0]):
command_queue.append(ship.dock(closest_empty_planets[0]))
continue
distance_between_my_ship_and_empty_planet = ship.calculate_distance_between(closest_empty_planets[0])
distance_between_my_ship_and_outside_planet = ship.calculate_distance_between(closest_outside_planets[0])
if distance_between_my_ship_and_enemy_ship < distance_between_my_ship_and_empty_planet * .6:
navigate_ship(closest_enemy_ships[0])
else:
docking(closest_empty_planets[0], 0)
elif len(closest_enemy_ships) > 0:
navigate_ship(closest_enemy_ships[0])
turn_num += 1
logging.info("Turn: " + str(turn_num))
game.send_command_queue(command_queue)
# turn over
# game over
##################WHEN DONE THROW IN A BUNCH OF RANDOM STUFF TO THROW OTHER PEOPLE OFF, IE VARIABLES,################
######################################FUUNCTIONS, COMMENTS SAYING HOW IMPORT IT IS #########################################
# ### have bots chase me when there are x amount of ships ###
# ### can do distance to coordinates for diff coordinance ###
### Make sure starting ships do not crash ###
### After starting ships start to make more ships ###