-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyBot.py
87 lines (63 loc) · 2.08 KB
/
MyBot.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
"""
Main function for halite. Essentially creates a memory files, attempt to dump anything/everything to it,
and play the game
"""
import time
import sys
import copy
import pickle
import os
import numpy
from hlt import entity as ntt
try:
import hlt
import logging
name = sys.argv[1]
applyRandomizedWeight = False
if len(sys.argv) >= 3:
applyRandomizedWeight = sys.argv[2] == "True"
game = hlt.Game(name)
import nnutils
import nn.GuylaineV3 as Guylaine
import game as g
import numpy as np
from nn import starterBot
game_map = game.map
guylaine = Guylaine.Guylaine(name)
guylaine.load(applyRandomizedWeight)
guylaine.save(applyRandomizedWeight)
command_queue = []
while True:
command_queue.clear()
# advance the simulation 1 step
game_map = game.update_map()
if len(sys.argv) == 1: # nullbot
game.send_command_queue(command_queue)
continue
# Get State
for ship in game_map.get_me().all_ships():
command = None
target = guylaine.predict(ship, game_map)
logging.debug("target: %s", target)
speed = hlt.constants.MAX_SPEED
distance_remaining = ship.calculate_distance_between(target)
if distance_remaining < speed:
speed = distance_remaining / 2
if ship.can_dock(target):
logging.debug("target is planet, docking")
command = ship.dock(target)
else:
command = ship.navigate(
ship.closest_point_to(target),
game_map,
speed=int(speed),
ignore_ships=False)
if (command != None):
logging.debug("Command: %s", command)
command_queue.append(command)
game.send_command_queue(command_queue)
except Exception as e:
try:
logging.exception(str(e))
except Exception as f:
logging.exception(str(f))