Example #1
0
def unit_best_goal(my_unit):
    #print('unit {} at {},{} is calling best goal'.format(my_unit.id, my_unit.pos.x, my_unit.pos.y), file = sys.stderr)
    global first_base
    first_base = my_unit
    list_raw = []
    for x in range(agent.mapWidth):
        for y in range(agent.mapHeight):
            #print('a = {},{}, energium = {}'.format(x, y, agent.map.get_tile_by_pos(Position(x,y)).energium), file = sys.stderr)
            if (not agent.map.get_tile(x, y).is_base()
                    and not (x == my_unit.pos.x and y == my_unit.pos.y)
                    and agent.map.get_tile(x, y).energium > 0):
                list_raw.append(Position(x, y))
    priority_list = sorted(list_raw, key=functools.cmp_to_key(compare))
    for x in priority_list:
        if (goal_is_available(x, unit)):
            return x
Example #2
0
def unit_best_nearby_goal(my_unit):
    #print('unit {} at {},{} is calling best nearby goal'.format(my_unit.id, my_unit.pos.x, my_unit.pos.y), file = sys.stderr)
    global first_base
    first_base = my_unit
    list_raw = []
    radius = GAME_CONSTANTS["PARAMETERS"]["SEARCH_RADIUS"]
    leftX = my_unit.pos.x - radius if (my_unit.pos.x - radius >= 0) else 0
    rightX = my_unit.pos.x + radius + 1 if (
        my_unit.pos.x + radius < agent.mapWidth) else agent.mapWidth - 1
    leftY = my_unit.pos.y - radius if (my_unit.pos.y - radius >= 0) else 0
    rightY = my_unit.pos.y + radius + 1 if (
        my_unit.pos.y + radius < agent.mapWidth) else agent.mapWidth - 1
    for x in range(leftX, rightX):
        for y in range(leftX, rightY):
            #print('a = {},{}, energium = {}'.format(x, y, agent.map.get_tile_by_pos(Position(x,y)).energium), file = sys.stderr)
            if (not agent.map.get_tile(x, y).is_base()
                    and not (x == my_unit.pos.x and y == my_unit.pos.y)
                    and agent.map.get_tile(x, y).energium > 0):
                list_raw.append(Position(x, y))
    priority_list = sorted(list_raw, key=functools.cmp_to_key(compare))
    for x in priority_list:
        if (goal_is_available(x, unit)):
            return x
    return None
Example #3
0
def nearestPosEmpTileDir(unit, player, opponent, agent):
    north, south, west, east = None, None, None, None
    northTile, southTile, westTile, eastTile = None, None, None, None
    canGoNorth, canGoSouth, canGoWest, canGoEast = False, False, False, False
    if unit.pos.x + 1 < agent.mapWidth:
        east = Position(unit.pos.x + 1, unit.pos.y)
        eastTile = agent.map.get_tile_by_pos(east)
        canGoEast = True

    if unit.pos.y + 1 < agent.mapHeight:
        north = Position(unit.pos.x, unit.pos.y + 1)
        northTile = agent.map.get_tile_by_pos(north)
        canGoNorth = True

    if unit.pos.x - 1 >= 0:
        west = Position(unit.pos.x - 1, unit.pos.y)
        westTile = agent.map.get_tile_by_pos(west)
        canGoWest = True

    if unit.pos.y - 1 >= 0:
        south = Position(unit.pos.x, unit.pos.y - 1)
        southTile = agent.map.get_tile_by_pos(south)
        canGoSouth = True

    for oppUnit in opponent.units:
        if north and north.equals(oppUnit.pos):
            canGoNorth = False
            if oppUnit.get_breakdown_level() <= unit.get_breakdown_level():
                return DIRECTIONS.NORTH
        if south and south.equals(oppUnit.pos):
            canGoSouth = False
            if oppUnit.get_breakdown_level() <= unit.get_breakdown_level():
                return DIRECTIONS.SOUTH

        if west and west.equals(oppUnit.pos):
            canGoWest = False
            if oppUnit.get_breakdown_level() <= unit.get_breakdown_level():
                return DIRECTIONS.WEST

        if east and east.equals(oppUnit.pos):
            canGoEast = False
            if oppUnit.get_breakdown_level() <= unit.get_breakdown_level():
                return DIRECTIONS.EAST

    for oppUnit in player.units:
        if north and north.equals(oppUnit.pos):
            canGoNorth = False

        if south and south.equals(oppUnit.pos):
            canGoSouth = False

        if west and west.equals(oppUnit.pos):
            canGoWest = False

        if east and east.equals(oppUnit.pos):
            canGoEast = False

    if canGoNorth and northTile.energium >= 0:
        return DIRECTIONS.NORTH

    if canGoEast and eastTile.energium >= 0:
        return DIRECTIONS.NORTH

    if canGoWest and westTile.energium >= 0:
        return DIRECTIONS.NORTH

    if canGoSouth and southTile.energium >= 0:
        return DIRECTIONS.NORTH
Example #4
0
    totalCost = len(opponent.units) * 50 + opponent.energium

    if (len(opponent.units) * 50 +
            opponent.energium) > (len(player.units) * 50 + player.energium):
        commands.append(player.bases[random_base].spawn_unit())

    ### AI Code goes here ###
    free_real_estate = []
    tiles = []

    for y in range(agent.mapHeight):
        for x in range(agent.mapWidth):
            if mymap.get_tile(x, y).energium >= 0:
                flag = True
                for unit in player.units:
                    if unit.pos.equals(Position(x, y)):
                        flag = False

                for unit in opponent.units:
                    if unit.pos.equals(Position(x, y)):
                        flag = False

                if flag:
                    free_real_estate.append(mymap.get_tile(x, y).energium)
                    tiles.append((x, y))

    for unit in player.units:
        max_energium = max(free_real_estate)
        if mymap.get_tile_by_pos(unit.pos).energium >= max_energium:
            continue
        current_energium = mymap.get_tile_by_pos(unit.pos).energium
    my_units = player.units

    # all your bases
    my_bases = player.bases

    #my custom pq
    global first_base
    first_base = my_bases[0]
    list_raw = []

    if (first_time):
        for x in range(agent.mapWidth):
            for y in range(agent.mapHeight):
                #print('a = {},{}, energium = {}'.format(x, y, agent.map.get_tile_by_pos(Position(x,y)).energium), file = sys.stderr)
                if (not agent.map.get_tile(x, y).is_base()):
                    list_raw.append(Position(x, y))
        priority_list = sorted(list_raw, key=functools.cmp_to_key(compare))
        #for x in priority_list:
        #print(x.x, x.y, agent.map.get_tile_by_pos(x).energium, file=sys.stderr)
        first_time = False

    commands = []

    # use print("msg", file=sys.stderr) to print messages to the terminal or your error log.
    # normal prints are reserved for the match engine. Uncomment the lines below to log something
    # print('Turn {} | ID: {} - {} bases - {} units - energium {}'.format(agent.turn, player.team, len(my_bases), len(my_units), player.energium), file=sys.stderr)

    ### AI Code goes here ###

    # Let your creativity go wild. Feel free to change this however you want and
    # submit it as many times as you want to the servers
            for add in positionsToAdd:
                if add[0] >= 0 and add[0] < agent.mapWidth and add[
                        1] >= 0 and add[1] < agent.mapHeight:
                    if (add[0], add[1]) not in q and (
                            add[0],
                            add[1]) not in visited and (add[0],
                                                        add[1]) not in sent_to:
                        visited.append((add[0], add[1]))
                        q.append((add[0], add[1]))
            #print(q,positionsToAdd,file=sys.stderr)
            if q:
                current = q[0]
                visited.append(current)

        sent_to.append((current[0], current[1]))
        current = Position(current[0], current[1])
        point = current
        print("unit is on", unit.pos.x, unit.pos.y, file=sys.stderr)
        print(current.x,
              current.y,
              "was removed",
              "energium = ",
              agent.map.get_tile_by_pos(current).energium,
              file=sys.stderr)
        search_in.remove([
            mymap.get_tile(current.x, current.y).energium, current.y,
            current.x,
            mymap.get_tile(current.x, current.y)
        ])
        print(search_in[0:5], file=sys.stderr)
        direction_to_take = None