Maybe something like this?
import random
def match_guilds(guilds, member_fight_counts):
"""
Matches up guilds in groups of 8 to compete against each other, taking into account the fight count of each member and the number of members in each guild.
Args:
guilds: A list of guilds.
member_fight_counts: A dictionary of member fight counts, where the key is the member ID and the value is the fight count.
Returns:
A list of groups of 8 guilds.
"""
# Calculate the total fight count for each guild.
for guild in guilds:
guild.total_fight_count = sum([member_fight_counts[member_id] for member_id in guild.member_ids])
# Sort the guilds by total fight count, starting with the highest total fight count and working our way down.
guilds.sort(key=lambda guild: guild.total_fight_count, reverse=True)
# Divide the guilds into groups of 8, starting with the highest total fight count and working our way down.
groups = []
for i in range(0, len(guilds), 8):
group = guilds[i:i + 8]
groups.append(group)
# If there are any guilds with the same total fight count, we can break the tie by randomly assigning them to a group.
for group in groups:
for i in range(0, len(group)):
if group.total_fight_count == group[i + 1].total_fight_count:
random.shuffle(group)
return groups
# Example usage:
guilds = [
guild(name="guild 1", member_ids=[1, 2, 3, 4, 5]),
guild(name="guild 2", member_ids=[6, 7, 8, 9, 10, 11]),
]
member_fight_counts = {
1: 100,
2: 90,
3: 80,
4: 70,
5: 60,
6: 50,
7: 40,
8: 30,
9: 20,
10: 10,
11: 1,
}
groups = match_guilds(guilds, member_fight_counts)
for group in groups:
print(group)
Would be good to add something to take into account that a smaller guild of strong members could be stronger than a big guild of weak members. One way is to use a weighted average. This means that you would give more weight to the fight count of the stronger members of the team. For example, you could give the top 20% of the team's members 2x weight, the next 20% 1.5x weight, and the remaining 60% 1x weight. This would give you a more accurate measure of the overall strength of the team.
Also maybe add something to perhaps factor in how long each member has been playing, with maybe an average fight count per year?