-
Notifications
You must be signed in to change notification settings - Fork 0
/
currentbot.py
71 lines (59 loc) · 2.68 KB
/
currentbot.py
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
#!/usr/bin/env python3
# Import the Halite SDK, which will let you interact with the game.
import hlt
from hlt import constants
import random
import logging
import utils
# This game object contains the initial game state.
game = hlt.Game()
ship_status = {}
maxx, maxy = utils.getMax(game)
lb, rb = utils.setBorders(game, maxx)
#logging.info('lb = {}, rb = {}'.format(lb, rb))
# Respond with your name.
game.ready("TheMadMan")
while True:
# Get the latest game state.
game.update_frame()
# You extract player metadata and the updated map metadata here for convenience.
me = game.me
game_map = game.game_map
# A command queue holds all the commands you will run this turn.
command_queue = []
for ship in me.get_ships():
# For each of your ships, move randomly if the ship is on a low halite location or the ship is full.
# Else, collect halite.
if ship.id not in ship_status:
ship_status[ship.id] = "exploring"
if ship_status[ship.id] == "returning":
if ship.position == me.shipyard.position:
ship_status[ship.id] = "exploring"
else:
dropoffs = me.get_dropoffs()
if (dropoffs):
tndrop = []
for dropoff in dropoffs:
tndrop.append(game_map.calculate_distance(ship.position, dropoff.position))
tndrop.sort(reverse = True)
move = game_map.naive_navigate(ship, tndrop[0])
else:
move = game_map.naive_navigate(ship, me.shipyard.position)
command_queue.append(ship.move(move))
continue
elif ship.is_full:
ship_status[ship.id] = "returning"
logging.info("Ship {} has {} halite.".format(ship.id, ship.halite_amount))
if game_map[ship.position].halite_amount < constants.MAX_HALITE / 100 or ship.is_full:
maxPos = utils.getMaxHalitePosition(game, lb, rb, maxy)
command_queue.append(
ship.move(game_map.naive_navigate(ship, maxPos)))
#ship.move(random.choice(['s','e','w','n'])))
else:
command_queue.append(ship.stay_still())
# If you're on the first turn and have enough halite, spawn a ship.
# Don't spawn a ship if you currently have a ship at port, though.
if ((game.turn_number >= 1 and me.halite_amount >= constants.SHIP_COST + constants.DROPOFF_COST and not game_map[me.shipyard].is_occupied) or (not me.get_ships())):
command_queue.append(game.me.shipyard.spawn())
# Send your moves back to the game environment, ending this turn.
game.end_turn(command_queue)