Example #1
0
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)
Example #3
0
                    '--TIME_MAX',
                    help='Time to take while finding moves',
                    type=float)

args = vars(parser.parse_args())

# decide if logging should happen
if args["logging"]:
    if not os.path.isdir("logs"):
        os.mkdir("logs")
    LOG_FILENAME = str(int(time.time())) + "-" + '.log'
    logging.basicConfig(filename="logs/" + LOG_FILENAME, level=logging.DEBUG)
else:
    logging.disable(logging.CRITICAL)

myID, gameMap = hlt.get_init()
haliteBot = HaliteBotCode(gameMap, myID, args)

# do the init steps
haliteBot.do_init()

bot_name = "byronwall-ga1" if args["name"] is None else args["name"]
hlt.send_init(bot_name)

# decide if profiling should happen
SHOULD_PROFILE = args["profile"]
if SHOULD_PROFILE:
    if not os.path.isdir("profiles"):
        os.mkdir("profiles")

frame = 0
Example #4
0
import hlt
from hlt import NORTH, EAST, SOUTH, WEST, STILL, Move, Square
import random
import logging
logging.basicConfig(filename='example.log',level=logging.INFO)
logging.info('Start log ---------------------')
myID, game_map = hlt.get_init()
hlt.send_init("Attack best prodratio")

def populate_lists(game_map):
    logging.info('****populate_lists****')
    my_squares = []
    empty_squares =[]
    enemies =[]
    enemy_size = []
    enemy_squares = []
    for square in game_map:
        if(square.owner == 0):
            #logging.info('adding empty')
            empty_squares.append(square)
        elif(square.owner == myID):
            #logging.info('adding owned')
            my_squares.append(square)
        else:
            if square.owner not in enemies:
                #logging.info('adding enemy')
                enemies.append(square.owner)
                enemy_squares.append([])
            #logging.info('adding enemy square')
            enemy_squares[enemies.index(square.owner)].append(square)
    #logging.info("MySquares " + str(len(my_squares)))
Example #5
0
import hlt
from hlt import NORTH, EAST, SOUTH, WEST, STILL, Move, Square
import random

myId, game_map = hlt.get_init()
hlt.send_init("ProductionBot")


def findNearestEnemyDirection(square):
    nearestEnemyDirection = NORTH
    maxDistance = min(game_map.height, game_map.width) / 2

    for neighborDirection, neighbor in enumerate(game_map.neighbors(square)):
        current = neighbor
        distance = 0
        while (current.owner == myId and distance < maxDistance):
            distance = distance + 1
            current = game_map.get_target(current, neighborDirection)

        if distance < maxDistance:
            maxDistance = distance
            nearestEnemyDirection = neighborDirection

    return nearestEnemyDirection


def notMe(square):
    return square[1].owner != myId


def assign_move(square):
Example #6
0
    if len(close_range_enemy_neighbors) > 0 and is_mature_for_close_range_battle(strength):
        return Move(square, direction_from_to_square(game_map, square, close_range_enemy_neighbors[0]))

    close_range_neutral_neighbors = [neighbor for neighbor in game_map.neighbors(square, n=5) if is_neutral(neighbor)]
    if len(close_range_neutral_neighbors) > 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))

    # 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'])
Example #7
0
import hlt
from hlt import NORTH, EAST, SOUTH, WEST, STILL, Move, Square
import simulate
import time
import copy

cardinals = [NORTH, EAST, SOUTH, WEST]
start_time = time.time()
my_id, gamemap = hlt.get_init()


def eval_square(gamemap, square, num_neighbors=3):
    return square.production / max(1, square.strength) + sum(
        [(neighbor.production) / max(1, neighbor.strength)
         for neighbor in gamemap.neighbors(square, n=num_neighbors)])


def dijkstra(gamemap, target, start=None, available=None):
    if available is None:
        available = set([square for square in gamemap])
    else:
        available = set(available)

    queue = [square for square in available]
    came_from = {square: None for square in available}
    cost_so_far = {square: float("inf") for square in available}
    cost_so_far[target] = 0

    while queue:
        current_square = min(queue, key=lambda x: cost_so_far[x])
        queue.remove(current_square)
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)
Example #9
0
#from pandas.hashtable import na_sentinel

import hlt
from hlt import NORTH, EAST, SOUTH, WEST, STILL, Move, Square
import random
import logging
from collections import namedtuple

myID, game_map, targetCoord = hlt.get_init()
hlt.send_init("SneakyBevster")
logging.basicConfig(filename=str(myID) + '.log', level=logging.DEBUG)


def find_nearest_enemy_direction(square):
    direction = NORTH
    max_distance = min(game_map.width, game_map.height) / 2
    for d in (NORTH, EAST, SOUTH, WEST):
        distance = 0
        current = square
        while (current.owner == myID or current.owner==0) and distance < max_distance:
            distance += 1
            current = game_map.get_target(current, d)
        if distance < max_distance:
            direction = d
            max_distance = distance
    return direction


def heuristic(square):
    if square.owner == 0 and square.strength > 0:
        return square.production / square.strength
Example #10
0
import random
import logging
import csv
from collections import namedtuple


# prodWeight= random.randint(1,10)
# squareWeight= random.randint(1,10)
# stayStill = random.randint(3,7)
# gameStyle = random.randint(0,1)

stayStill = 5
gameStyle = 1
beingAttacked = False

myID, game_map, targetCoord,totalStrength,totalProd,areaStrength,ts,tp,gameStyle = hlt.get_init(1,2)
hlt.send_init("PrecisionBevster3")

logging.basicConfig(filename=str("tagets") + '.log', level=logging.DEBUG)

def get_adjas(direction):

    if direction==0:
        adjas = [1,3]
    elif direction==1:
        adjas = [0,2]
    elif direction==2:
        adjas = [1,3]
    elif direction==3:
        adjas = [0,2]
    else:
Example #11
0
 def __init__(self, name='Bot'):
     self.my_id, self.game = hlt.get_init()
     hlt.send_init(name)
Example #12
0
    close_range_neutral_neighbors = [
        neighbor for neighbor in game_map.neighbors(square, n=7)
        if is_neutral(neighbor)
    ]
    if len(close_range_neutral_neighbors
           ) > 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'])