예제 #1
0
def get_exit_paths(instance):
    start, finish = instance.level.botSpawnAreas[instance.game.enemyTeam.name]
    enemy_base = Vector2(start.x, start.y)
    instance.graph.add_node("enemy_base", position = (start.x, start.y), weight = 0.0)
    instance.graph.node["enemy_base"]["exit_path"] = 0.0
    instance.graph.node["enemy_base"]["camp_target"] = 0.0
    instance.graph.node["enemy_base"]["camp_location"] = 0.0
        
    for i, j in itertools.product(range(int(start.x), int(finish.x)), range(int(start.y), int(finish.y))):
        instance.graph.add_edge("enemy_base", instance.terrain[j][i], weight = 1.0)                       

    our_flag_node = regressions2.get_node_index(instance, instance.game.team.flag.position)
    enemy_score_node = regressions2.get_node_index(instance, instance.game.enemyTeam.flagScoreLocation)
    enemy_flag_node = regressions2.get_node_index(instance, instance.game.enemyTeam.flag.position)
    our_score_node = regressions2.get_node_index(instance, instance.game.team.flagScoreLocation)
    
    b_to_flag = nx.shortest_path(instance.graph, source="enemy_base", target = our_flag_node)
    b_to_def = nx.shortest_path(instance.graph, source="enemy_base", target = enemy_flag_node)
    b_to_def2 = nx.shortest_path(instance.graph, source="enemy_base", target = our_score_node)

    #Calculate how the enemy is exiting from their base.
    exit_paths = [(b_to_flag, 10), (b_to_def, 6), (b_to_def2, 2)]
    for x in range(50):
        position = instance.level.findRandomFreePositionInBox(instance.level.area)
        base_seperation = position - enemy_base
        base_seperation = base_seperation*15/base_seperation.length()
        close_pos = enemy_base + base_seperation
        x, y = regressions2.sanitize_position(instance, close_pos)
        close_pos = Vector2(x, y)
        node_index = regressions2.get_node_index(instance, close_pos)
        path = nx.shortest_path(instance.graph, source="enemy_base", target = node_index)
        exit_paths.append((path, 4))     
    return exit_paths
예제 #2
0
def extrapolate(instance):
    points = []
    bot_extraps = {}
    for enemy_bot in instance.enemies.keys():
        if enemy_bot.health > 0.0:
            #Get enemy heading.
            extrapolation = enemy_bot.position - instance.enemies[enemy_bot]
            #If we have no new data on enemy location, assume they are heading in direction of flag.
            #TODO account for pin bots, hunt bots, and defend bots.
            #TODO account for probable pathing... pheremone?
            if extrapolation.length() == 0.0:
                extrapolation = instance.game.team.flag.position - enemy_bot.position
            if extrapolation.length() == 0.0:
                extrapolation = instance.game.enemyTeam.flagScoreLocation - enemy_bot.position          
            extrapolation.normalize()
            #Calculate point enemy should have ran to. TODO make realistic with level speed.
            #TODO use visualizer to simultaneously show with visualization via circle drawings.
            enemy_speed = get_enemy_bot_speed(instance, enemy_bot)*.8 #.8 because not straight running lines.

            #Resolve points going off map by having the bot calculated as at map edge.
            if extrapolation.x > enemy_bot.position.x:
                x_bound = 87
            else:
                x_bound = 2
            if extrapolation.y > enemy_bot.position.y:
                y_bound = 49
            else:
                y_bound = 2

            if enemy_bot.seenlast != None:
                extrapolated_change = extrapolation * enemy_speed * (enemy_bot.seenlast + 1.5)
            else:
                extrapolated_change = extrapolation * enemy_speed * 1.5
                
            if extrapolated_change.x > abs(enemy_bot.position.x - x_bound):
                extrapolated_change.x = x_bound
            if extrapolated_change.y > abs(enemy_bot.position.y - y_bound):
                extrapolated_change.y = y_bound
            
            final_position = enemy_bot.position + extrapolated_change
            x, y = regressions2.sanitize_position(instance, final_position)
            
            final_position = Vector2(x, y)

            node_index = regressions2.get_node_index(instance, final_position)

            vector = regressions2.get_node_vector(instance, node_index)

            points.append(vector)
            bot_extraps[enemy_bot] = vector
            
    if instance.DRAW_POINTS == "extrap":
        instance.points = points
        
    return bot_extraps
예제 #3
0
def get_exit_paths(instance):
    start, finish = instance.level.botSpawnAreas[instance.game.enemyTeam.name]
    enemy_base = Vector2(start.x, start.y)
    instance.graph.add_node("enemy_base",
                            position=(start.x, start.y),
                            weight=0.0)
    instance.graph.node["enemy_base"]["exit_path"] = 0.0
    instance.graph.node["enemy_base"]["camp_target"] = 0.0
    instance.graph.node["enemy_base"]["camp_location"] = 0.0

    for i, j in itertools.product(range(int(start.x), int(finish.x)),
                                  range(int(start.y), int(finish.y))):
        instance.graph.add_edge("enemy_base",
                                instance.terrain[j][i],
                                weight=1.0)

    our_flag_node = regressions2.get_node_index(
        instance, instance.game.team.flag.position)
    enemy_score_node = regressions2.get_node_index(
        instance, instance.game.enemyTeam.flagScoreLocation)
    enemy_flag_node = regressions2.get_node_index(
        instance, instance.game.enemyTeam.flag.position)
    our_score_node = regressions2.get_node_index(
        instance, instance.game.team.flagScoreLocation)

    b_to_flag = nx.shortest_path(instance.graph,
                                 source="enemy_base",
                                 target=our_flag_node)
    b_to_def = nx.shortest_path(instance.graph,
                                source="enemy_base",
                                target=enemy_flag_node)
    b_to_def2 = nx.shortest_path(instance.graph,
                                 source="enemy_base",
                                 target=our_score_node)

    #Calculate how the enemy is exiting from their base.
    exit_paths = [(b_to_flag, 10), (b_to_def, 6), (b_to_def2, 2)]
    for x in range(50):
        position = instance.level.findRandomFreePositionInBox(
            instance.level.area)
        base_seperation = position - enemy_base
        base_seperation = base_seperation * 15 / base_seperation.length()
        close_pos = enemy_base + base_seperation
        x, y = regressions2.sanitize_position(instance, close_pos)
        close_pos = Vector2(x, y)
        node_index = regressions2.get_node_index(instance, close_pos)
        path = nx.shortest_path(instance.graph,
                                source="enemy_base",
                                target=node_index)
        exit_paths.append((path, 4))
    return exit_paths