def get_next_hero(pick, against=[], ban=[]):
    best_connection = -100
    next_pick = 0

    for next_hero_id in winrate.index:
        # if this hero is not in the opening
        if next_hero_id not in pick and next_hero_id not in ban \
                and next_hero_id not in against:
                
            total_connection = 0
            for picked_hero in pick:
                hero1, hero2 = sorted([next_hero_id, picked_hero])
                total_connection += winrate.loc[hero1][hero2]
                
            for enemy in against:
                total_connection -= lose_rate.loc[next_hero_id][enemy]

            if total_connection > best_connection:
                best_hero = next_hero_id
                best_connection = total_connection

    return best_hero.item()

pick = Heroes()
pick.add(Hero.from_name(''))

ban = Heroes()
ban.add(Hero.from_name('Shadow Fiend'))
ban.add(Hero.from_name('Invoker'))

against = Heroes()
against.add(Hero.from_name('Slardar'))
against.add(Hero.from_name('Witch Doctor'))

while len(pick) < 5:
    next_hero = get_next_hero(list(pick.get_ids()),
                              ban=list(ban.get_ids()),
                              against=list(against.get_ids()))
    pick.add(Hero(next_hero))
    
print(pick.get_names())

"""
Explanation: Building a pick
Idea: user gives 2 heroes as input, after that algorithms searches for the best next hero till there are 5 of them. The best hero would be choosen by maximazing the weight of edges in heroes graph. Heroes graph -- vertices are rows in winrate matrix and edges are winrates of heroes pairs.
End of explanation
"""


h1 = Hero(4)
h2 = Hero(108)
print(h1.name, h2.name)

"""
Explanation: A lot of attempts to build a pick from a random hero gave me the next thought: maximum weighted winrate should be limited by some value. Because otherwise, same combinations of heroes will appear over and over again. For example, all the values in winrate matrix more than .6 should be equal to .6 or weights should be somehow.
First idea really improves performance!
End of explanation
"""


