Skip to content

Commit

Permalink
Change map pool selection (#952)
Browse files Browse the repository at this point in the history
* Select opposing players based on displayed rating

instead of mean

* Select map pool based on average rating of the players

* Make map pool selection configurable

* Refactor if-chain to static mapping in config.py

---------

Co-authored-by: Askaholic <[email protected]>
  • Loading branch information
BlackYps and Askaholic authored Mar 18, 2023
1 parent 6dcfd41 commit fec446b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
11 changes: 10 additions & 1 deletion server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import asyncio
import logging
import os
import statistics
from typing import Callable

import trueskill
Expand All @@ -26,6 +27,11 @@
# see: http://forums.faforever.com/viewtopic.php?f=45&t=11698#p119599
# Optimum values for ladder here, using them for global as well.
trueskill.setup(mu=1500, sigma=500, beta=240, tau=10, draw_probability=0.10)
MAP_POOL_RATING_SELECTION_FUNCTIONS = {
"mean": statistics.mean,
"min": min,
"max": max,
}


@with_logger
Expand Down Expand Up @@ -131,7 +137,10 @@ def __init__(self):
self.LADDER_SEARCH_EXPANSION_STEP = 0.05
self.LADDER_TOP_PLAYER_SEARCH_EXPANSION_MAX = 0.3
self.LADDER_TOP_PLAYER_SEARCH_EXPANSION_STEP = 0.15
# The maximum amount of time in seconds) to wait between pops.
# The method for choosing map pool rating
# Can be "mean", "min", or "max"
self.MAP_POOL_RATING_SELECTION = "mean"
# The maximum amount of time in seconds to wait between pops
self.QUEUE_POP_TIME_MAX = 90
# The number of possible matches we would like to have when the queue
# pops. The queue pop time will be adjusted based on the current rate of
Expand Down
22 changes: 13 additions & 9 deletions server/ladder_service/ladder_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from sqlalchemy import and_, func, select, text, true

from server import metrics
from server.config import config
from server.config import MAP_POOL_RATING_SELECTION_FUNCTIONS, config
from server.core import Service
from server.db import FAFDatabase
from server.db.models import (
Expand Down Expand Up @@ -499,10 +499,17 @@ async def _start_game(
queue.id,
limit=config.LADDER_ANTI_REPETITION_LIMIT
)
rating = min(
player.ratings[queue.rating_type].displayed()
for player in all_players

def get_displayed_rating(player: Player) -> float:
return player.ratings[queue.rating_type].displayed()

ratings = (get_displayed_rating(player) for player in all_players)
func = MAP_POOL_RATING_SELECTION_FUNCTIONS.get(
config.MAP_POOL_RATING_SELECTION,
statistics.mean
)
rating = func(ratings)

pool = queue.get_map_pool_for_rating(rating)
if not pool:
raise RuntimeError(f"No map pool available for rating {rating}!")
Expand All @@ -521,11 +528,8 @@ async def _start_game(
game.map_file_path = map_path
game.set_name_unchecked(game_name(team1, team2))

def get_player_mean(player: Player) -> float:
return player.ratings[queue.rating_type].mean

team1 = sorted(team1, key=get_player_mean)
team2 = sorted(team2, key=get_player_mean)
team1 = sorted(team1, key=get_displayed_rating)
team2 = sorted(team2, key=get_displayed_rating)

# Shuffle the teams such that direct opponents remain the same
zipped_teams = list(zip(team1, team2))
Expand Down

0 comments on commit fec446b

Please sign in to comment.