diff --git a/server/matchmaker/matchmaker_queue.py b/server/matchmaker/matchmaker_queue.py index 778407981..60cb81507 100644 --- a/server/matchmaker/matchmaker_queue.py +++ b/server/matchmaker/matchmaker_queue.py @@ -278,6 +278,8 @@ def to_dict(self): """ Return a fuzzy representation of the searches currently in the queue """ + boundaries = [] + boundaries.extend(search.boundary_80 for search in self._queue.keys()) return { "queue_name": self.name, "queue_pop_time": datetime.fromtimestamp( @@ -288,8 +290,7 @@ def to_dict(self): ndigits=2 ), "num_players": self.num_players, - "boundary_80s": [search.boundary_80 for search in self._queue.keys()], - "boundary_75s": [search.boundary_75 for search in self._queue.keys()], + "boundaries": boundaries, # TODO: Remove, the client should query the API for this "team_size": self.team_size, } diff --git a/server/matchmaker/search.py b/server/matchmaker/search.py index 962b1b98b..8912d51c1 100644 --- a/server/matchmaker/search.py +++ b/server/matchmaker/search.py @@ -112,25 +112,23 @@ def displayed_ratings(self) -> list[float]: """ return [rating.displayed() for rating in self.raw_ratings] - def _nearby_rating_range(self, delta: int) -> tuple[int, int]: + def _nearby_rating_range(self, delta: int) -> list[tuple[int, int]]: """ Returns 'boundary' mu values for player matching. Adjust delta for different game qualities. """ - mu, _ = self.ratings[0] # Takes the rating of the first player, only works for 1v1 - rounded_mu = int(math.ceil(mu / 10) * 10) # Round to 10 - return rounded_mu - delta, rounded_mu + delta + ranges = [] + for rating in self.ratings: + mu, _ = rating + rounded_mu = int(math.ceil(mu / 10) * 10) # Round to 10 + ranges.append((rounded_mu - delta, rounded_mu + delta)) + return ranges @property - def boundary_80(self) -> tuple[int, int]: + def boundary_80(self) -> list[tuple[int, int]]: """ Achieves roughly 80% quality. """ return self._nearby_rating_range(200) - @property - def boundary_75(self) -> tuple[int, int]: - """ Achieves roughly 75% quality. FIXME - why is it MORE restrictive??? """ - return self._nearby_rating_range(100) - @property def failed_matching_attempts(self) -> int: return self._failed_matching_attempts diff --git a/tests/integration_tests/test_matchmaker.py b/tests/integration_tests/test_matchmaker.py index be58d7ae4..2db6276ac 100644 --- a/tests/integration_tests/test_matchmaker.py +++ b/tests/integration_tests/test_matchmaker.py @@ -450,8 +450,7 @@ async def test_matchmaker_info_message(lobby_server, mocker): assert queue["queue_pop_time_delta"] == math.ceil( config.QUEUE_POP_TIME_MAX / 2 ) - assert queue["boundary_80s"] == [] - assert queue["boundary_75s"] == [] + assert queue["boundaries"] == [] @fast_forward(10) @@ -484,8 +483,7 @@ async def test_command_matchmaker_info(lobby_server, mocker): assert queue["queue_pop_time_delta"] == math.ceil( config.QUEUE_POP_TIME_MAX / 2 ) - assert queue["boundary_80s"] == [] - assert queue["boundary_75s"] == [] + assert queue["boundaries"] == [] @fast_forward(10) @@ -512,10 +510,10 @@ async def read_update_msg(): queue_message = next( q for q in msg["queues"] if q["queue_name"] == "ladder1v1" ) - if not queue_message["boundary_80s"]: + if not queue_message["boundaries"]: continue - assert len(queue_message["boundary_80s"]) == 1 + assert len(queue_message["boundaries"]) == 1 return @@ -530,7 +528,7 @@ async def read_update_msg(): msg = await read_until_command(proto, "matchmaker_info") queue_message = next(q for q in msg["queues"] if q["queue_name"] == "ladder1v1") - assert len(queue_message["boundary_80s"]) == 0 + assert len(queue_message["boundaries"]) == 0 @fast_forward(10) diff --git a/tests/integration_tests/test_teammatchmaker.py b/tests/integration_tests/test_teammatchmaker.py index e07d795ef..d14ca4fd8 100644 --- a/tests/integration_tests/test_teammatchmaker.py +++ b/tests/integration_tests/test_teammatchmaker.py @@ -83,7 +83,7 @@ async def test_info_message(lobby_server): assert msg["queues"] for queue in msg["queues"]: - boundaries = queue["boundary_80s"] + boundaries = queue["boundaries"] if queue["queue_name"] == "tmm2v2": assert boundaries == [[300, 700]] diff --git a/tests/unit_tests/test_lobbyconnection.py b/tests/unit_tests/test_lobbyconnection.py index 248102f7c..b18be9835 100644 --- a/tests/unit_tests/test_lobbyconnection.py +++ b/tests/unit_tests/test_lobbyconnection.py @@ -1039,8 +1039,7 @@ async def test_command_matchmaker_info( "queue_pop_time_delta": 1.0, "team_size": 1, "num_players": 6, - "boundary_80s": [(1800, 2200), (300, 700), (800, 1200)], - "boundary_75s": [(1900, 2100), (400, 600), (900, 1100)] + "boundaries": [(1800, 2200), (300, 700), (800, 1200)], } ] }) diff --git a/tests/unit_tests/test_matchmaker_queue.py b/tests/unit_tests/test_matchmaker_queue.py index 134c31ce5..04c57f3f8 100644 --- a/tests/unit_tests/test_matchmaker_queue.py +++ b/tests/unit_tests/test_matchmaker_queue.py @@ -185,10 +185,8 @@ def test_search_no_match_wrong_type(matchmaker_players): def test_search_boundaries(matchmaker_players): p1 = matchmaker_players[0] s1 = Search([p1]) - assert p1.ratings[RatingType.LADDER_1V1][0] > s1.boundary_80[0] - assert p1.ratings[RatingType.LADDER_1V1][0] < s1.boundary_80[1] - assert p1.ratings[RatingType.LADDER_1V1][0] > s1.boundary_75[0] - assert p1.ratings[RatingType.LADDER_1V1][0] < s1.boundary_75[1] + assert p1.ratings[RatingType.LADDER_1V1][0] > s1.boundaries[0] + assert p1.ratings[RatingType.LADDER_1V1][0] < s1.boundaries[1] def test_search_expansion_controlled_by_failed_matching_attempts(matchmaker_players):