def main():
    global max_production
    own_id, game_map = hlt.get_init()
    hlt.send_init("MyMLBot")
    solver = Solver(own_id, game_map)
    while True:
        game_map.get_frame()
        if max_production is None:
            max_production = solver.get_max_production()
        moves = solver.process_frame()
        hlt.send_frame(moves)
def main():
    global max_production
    own_id, game_map = hlt.get_init()
    hlt.send_init("MyMLBot")
    solver = Solver(own_id, game_map)
    while True:
        game_map.get_frame()
        if max_production is None:
            max_production = solver.get_max_production()
        moves = solver.process_frame()
        hlt.send_frame(moves)
Exemple #3
0
SHOULD_PROFILE = args["profile"]
if SHOULD_PROFILE:
    if not os.path.isdir("profiles"):
        os.mkdir("profiles")

frame = 0

TIME_MAX = 0.8 if args["TIME_MAX"] is None else args["TIME_MAX"]
start_time = time.time()

while True:

    gameMap.get_frame()

    logging.debug("FRAME START %d", frame)

    start_time = time.time()

    should_profile = (myID == 1) and (frame % 50 == 0) and SHOULD_PROFILE
    if should_profile:
        cProfile.run("haliteBot.update(gameMap)",
                     "profiles/profile-" + str(frame) + ".pyprof")
    else:
        haliteBot.update(gameMap)

    moves = haliteBot.moves_this_frame

    hlt.send_frame(moves)

    frame += 1
        return Move(square, direction_from_to_square(game_map, square, best_neighbor))

    # Go Radially from origin location if enough
    if is_mature_to_start_moving_radially_out(strength):
        return Move(square, direction_from_to_square(game_map, origin_square, square))

    return Move(square, STILL)


my_id, game_map = get_init()
send_init("Worse bot")

origin_square = None
while True:
    game_map.get_frame()
    my_squares = [square for square in game_map if is_my(square)]
    if origin_square is None:
        origin_square = my_squares[0]

    moves = [make_move(square) for square in my_squares]
    send_frame(moves)

# def test():
#     FakeMap = namedtuple('FakeMap', ['width', 'height'])
#     FakeSquare = namedtuple('FakeSquare', ['x', 'y'])
#     fake_map = FakeMap(width=10, height=10)
#
#     res = direction_from_to_square(fake_map, FakeSquare(x=1, y=1), FakeSquare(x=5, y=3))
#     pass
#
# test()
Exemple #5
0
def run_game(gamemap,
             attack_path=None,
             simulate_game=False,
             num_moves=float("inf"),
             stop_after_attack_path=False):
    num_move = 0
    moves = []
    if simulate:
        gamemap = copy.deepcopy(gamemap)

    while num_move < num_moves:
        num_move += 1
        if not simulate_game:
            gamemap.get_frame()

        already_moved = set()
        already_targeted = False
        moves = []
        available = [square for square in gamemap if square.owner == my_id]
        attack_square = None

        for square in available:
            if square in already_moved:
                continue
            if attack_path is not None and len(attack_path) > 0:
                attack_squares = [
                    gamemap.contents[target.y][target.x]
                    for target in attack_path
                ]
                attack_square = min(
                    attack_squares[::-1],
                    key=lambda target: abs(
                        gamemap.get_distance(target, square) - 1))
                if attack_square == attack_squares[-1]:
                    # end of the road...
                    attack_path = None
                    if stop_after_attack_path:
                        return num_move

            new_moves = get_move(gamemap,
                                 square,
                                 exclude=already_moved,
                                 target=attack_square)
            for move in new_moves:
                if move.square not in already_moved:
                    moves.append(move)
                    if move.direction != STILL:
                        already_moved.add(move.square)

        # if not simulate:
        future_strengths = {}
        moves.sort(key=lambda move: move.square.strength, reverse=True)
        for idx, move in enumerate(moves):
            if move.direction == STILL:
                future_strengths[move.square] = future_strengths.get(
                    move.square, 0) + move.square.strength
            else:
                future_square = gamemap.get_target(move.square, move.direction)
                if future_square.owner == my_id:
                    new_strength = future_strengths.get(
                        future_square, 0) + move.square.strength
                    if new_strength > 255:
                        moves[idx] = Move(move.square, STILL)
                    else:
                        future_strengths[future_square] = new_strength

        if simulate_game:
            gamemap = simulate.update_gamemap(gamemap, moves)
        else:
            hlt.send_frame(moves)
    return simulate.score_gamemap(gamemap, my_id)
import hlt
from hlt import NORTH, EAST, SOUTH, WEST, STILL, Move, Square
import random


myID, game_map = hlt.get_init()
hlt.send_init("Ran9domPythonBot")

while True:
    game_map.get_frame()
    moves = [
        Move(square, random.choice((NORTH, EAST, SOUTH, WEST, STILL)))
        for square in game_map
        if square.owner == myID]
    hlt.send_frame(moves)
Exemple #7
0
 def run(self):
     while True:
         self.game.get_frame()
         rows, cols = np.where(self.game.owners == self.my_id)
         moves = self.assign_moves(rows, cols)
         hlt.send_frame(moves)
           ) > 0 and is_mature_for_close_range_conquer(strength):
        best_neighbor = choose_best_neutral(close_range_neutral_neighbors,
                                            square)
        return Move(square,
                    direction_from_to_square(game_map, square, best_neighbor))

    return Move(square, STILL)


my_id, game_map = get_init()
send_init("Better bot")

origin_square = None
while True:
    game_map.get_frame()
    my_squares = [square for square in game_map if is_my(square)]
    if origin_square is None:
        origin_square = my_squares[0]

    moves = [make_move(square) for square in my_squares]
    send_frame(moves)

# def test():
#     FakeMap = namedtuple('FakeMap', ['width', 'height'])
#     FakeSquare = namedtuple('FakeSquare', ['x', 'y'])
#     fake_map = FakeMap(width=10, height=10)
#
#     res = direction_from_to_square(fake_map, FakeSquare(x=1, y=1), FakeSquare(x=5, y=3))
#     pass
#
# test()
Exemple #9
0
def send_moves(moves):
    hlt.send_frame(moves)