-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMyBotv1.py
More file actions
59 lines (53 loc) · 2.83 KB
/
MyBotv1.py
File metadata and controls
59 lines (53 loc) · 2.83 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
import hlt
import logging
# GAME START
# Here we define the bot's name as Settler and initialize the game, including communication with the Halite engine.
game = hlt.Game("Settler V1")
# Then we print our start message to the logs
logging.info("Starting my Settler bot!")
while True:
# TURN START
# Update the map for the new turn and get the latest version
game_map = game.update_map()
# Here we define the set of commands to be sent to the Halite engine at the end of the turn
command_queue = []
# For every ship that I control
for ship in game_map.get_me().all_ships():
# If the ship is docked
if ship.docking_status != ship.DockingStatus.UNDOCKED:
# Skip this ship
continue
# For each planet in the game (only non-destroyed planets are included)
for planet in game_map.all_planets():
# If the planet is owned
if planet.is_owned():
# Skip this planet
continue
# If we can dock, let's (try to) dock. If two ships try to dock at once, neither will be able to.
if ship.can_dock(planet):
# We add the command by appending it to the command_queue
command_queue.append(ship.dock(planet))
else:
# If we can't dock, we move towards the closest empty point near this planet (by using closest_point_to)
# with constant speed. Don't worry about pathfinding for now, as the command will do it for you.
# We run this navigate command each turn until we arrive to get the latest move.
# Here we move at half our maximum speed to better control the ships
# In order to execute faster we also choose to ignore ship collision calculations during navigation.
# This will mean that you have a higher probability of crashing into ships, but it also means you will
# make move decisions much quicker. As your skill progresses and your moves turn more optimal you may
# wish to turn that option off.
navigate_command = ship.navigate(
ship.closest_point_to(planet),
game_map,
speed=int(hlt.constants.MAX_SPEED/2),
ignore_ships=True)
# If the move is possible, add it to the command_queue (if there are too many obstacles on the way
# or we are trapped (or we reached our destination!), navigate_command will return null;
# don't fret though, we can run the command again the next turn)
if navigate_command:
command_queue.append(navigate_command)
break
# Send our set of commands to the Halite engine for this turn
game.send_command_queue(command_queue)
# TURN END
# GAME END