Skip to content

Commit

Permalink
Send rating boundaries for all players in a search party
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackYps committed Jun 8, 2024
1 parent c3ca6c1 commit 4470c33
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 26 deletions.
5 changes: 3 additions & 2 deletions server/matchmaker/matchmaker_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
}
Expand Down
18 changes: 8 additions & 10 deletions server/matchmaker/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 5 additions & 7 deletions tests/integration_tests/test_matchmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests/test_teammatchmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]

Check failure on line 89 in tests/integration_tests/test_teammatchmaker.py

View workflow job for this annotation

GitHub Actions / unit-test

test_info_message[qstream] assert [[[300, 700]]] == [[300, 700]] At index 0 diff: [[300, 700]] != [300, 700] Full diff: [ [ + [ - 300, + 300, ? ++++ - 700, + 700, ? ++++ + ], ], ]

Check failure on line 89 in tests/integration_tests/test_teammatchmaker.py

View workflow job for this annotation

GitHub Actions / unit-test

test_info_message[json] assert [[[300, 700]]] == [[300, 700]] At index 0 diff: [[300, 700]] != [300, 700] Full diff: [ [ + [ - 300, + 300, ? ++++ - 700, + 700, ? ++++ + ], ], ]
Expand Down
3 changes: 1 addition & 2 deletions tests/unit_tests/test_lobbyconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)],
}
]
})
Expand Down
6 changes: 2 additions & 4 deletions tests/unit_tests/test_matchmaker_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Check failure on line 188 in tests/unit_tests/test_matchmaker_queue.py

View workflow job for this annotation

GitHub Actions / unit-test

test_search_boundaries AttributeError: 'Search' object has no attribute 'boundaries'. Did you mean: 'boundary_80'?
assert p1.ratings[RatingType.LADDER_1V1][0] < s1.boundaries[1]


def test_search_expansion_controlled_by_failed_matching_attempts(matchmaker_players):
Expand Down

0 comments on commit 4470c33

Please sign in to comment.