Module server.matchmaker.algorithm.bucket_teams

Functions

def rotate(list_: list[~T], amount: int) ‑> list[~T]
Expand source code
def rotate(list_: list[T], amount: int) -> list[T]:
    return list_[amount:] + list_[:amount]

Classes

class BucketTeamMatchmaker
Expand source code
@with_logger
class BucketTeamMatchmaker(Matchmaker):
    """
    Uses heuristics to group searches of any size
    into CombinedSearches of team_size
    and then runs StableMarriageMatchmaker
    to produce a list of matches from these.
    """

    def find(
        self, searches: Iterable[Search], team_size: int, rating_peak: float
    ) -> tuple[list[Match], list[Search]]:
        teams, searches_without_team = self._find_teams(searches, team_size)

        matchmaker1v1 = StableMarriageMatchmaker()
        matches, unmatched_searches = matchmaker1v1.find(teams, 1, rating_peak)

        unmatched_searches.extend(searches_without_team)
        return matches, unmatched_searches

    @staticmethod
    def _find_teams(
        searches: Iterable[Search], team_size: int
    ) -> tuple[list[Search], list[Search]]:
        full_teams = []
        unmatched = searches
        need_team = []
        for search in unmatched:
            if len(search.players) == team_size:
                full_teams.append(search)
            else:
                need_team.append(search)

        if all(len(s.players) == 1 for s in need_team):
            teams, unmatched = _make_teams_from_single(need_team, team_size)
        else:
            teams, unmatched = _make_teams(need_team, team_size)
        full_teams.extend(teams)

        return full_teams, unmatched

Uses heuristics to group searches of any size into CombinedSearches of team_size and then runs StableMarriageMatchmaker to produce a list of matches from these.

Ancestors

Methods

def find(self,
searches: Iterable[Search],
team_size: int,
rating_peak: float) ‑> tuple[list[tuple['Search', 'Search']], list[Search]]
Expand source code
def find(
    self, searches: Iterable[Search], team_size: int, rating_peak: float
) -> tuple[list[Match], list[Search]]:
    teams, searches_without_team = self._find_teams(searches, team_size)

    matchmaker1v1 = StableMarriageMatchmaker()
    matches, unmatched_searches = matchmaker1v1.find(teams, 1, rating_peak)

    unmatched_searches.extend(searches_without_team)
    return matches, unmatched_searches