-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/#1032 working veto system #1033
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,7 +100,7 @@ | |
queue.team_size = info["team_size"] | ||
queue.rating_peak = await self.fetch_rating_peak(info["rating_type"]) | ||
queue.map_pools.clear() | ||
for map_pool_id, min_rating, max_rating in info["map_pools"]: | ||
for map_pool_id, min_rating, max_rating, veto_tokens_per_player, max_tokens_per_map, minimum_maps_after_veto in info["map_pools"]: | ||
map_pool_name, map_list = map_pool_maps[map_pool_id] | ||
if not map_list: | ||
self._logger.warning( | ||
|
@@ -112,7 +112,10 @@ | |
queue.add_map_pool( | ||
MapPool(map_pool_id, map_pool_name, map_list), | ||
min_rating, | ||
max_rating | ||
max_rating, | ||
veto_tokens_per_player, | ||
Check warning on line 116 in server/ladder_service/ladder_service.py GitHub Actions / flake8
|
||
max_tokens_per_map, | ||
Check warning on line 117 in server/ladder_service/ladder_service.py GitHub Actions / flake8
|
||
minimum_maps_after_veto | ||
) | ||
# Remove queues that don't exist anymore | ||
for queue_name in list(self.queues.keys()): | ||
|
@@ -125,6 +128,7 @@ | |
select( | ||
map_pool.c.id, | ||
map_pool.c.name, | ||
map_pool_map_version.c.id.label("map_pool_map_version_id"), | ||
map_pool_map_version.c.weight, | ||
map_pool_map_version.c.map_params, | ||
map_version.c.id.label("map_id"), | ||
|
@@ -150,6 +154,7 @@ | |
map_list.append( | ||
Map( | ||
id=row.map_id, | ||
map_pool_map_version_id=row.map_pool_map_version_id, | ||
folder_name=folder_name, | ||
ranked=row.ranked, | ||
weight=row.weight, | ||
|
@@ -191,6 +196,9 @@ | |
matchmaker_queue_map_pool.c.map_pool_id, | ||
matchmaker_queue_map_pool.c.min_rating, | ||
matchmaker_queue_map_pool.c.max_rating, | ||
matchmaker_queue_map_pool.c.veto_tokens_per_player, | ||
matchmaker_queue_map_pool.c.max_tokens_per_map, | ||
matchmaker_queue_map_pool.c.minimum_maps_after_veto, | ||
game_featuredMods.c.gamemod, | ||
leaderboard.c.technical_name.label("rating_type") | ||
) | ||
|
@@ -219,7 +227,10 @@ | |
info["map_pools"].append(( | ||
row.map_pool_id, | ||
row.min_rating, | ||
row.max_rating | ||
row.max_rating, | ||
row.veto_tokens_per_player, | ||
row.max_tokens_per_map, | ||
row.minimum_maps_after_veto | ||
)) | ||
except Exception: | ||
self._logger.warning( | ||
|
@@ -523,7 +534,25 @@ | |
pool = queue.get_map_pool_for_rating(rating) | ||
if not pool: | ||
raise RuntimeError(f"No map pool available for rating {rating}!") | ||
game_map = pool.choose_map(played_map_ids) | ||
|
||
Check warning on line 537 in server/ladder_service/ladder_service.py GitHub Actions / flake8
|
||
pool, _, _, veto_tokens_per_player, max_tokens_per_map, minimum_maps_after_veto = queue.map_pools[pool.id] | ||
|
||
vetoesMap = defaultdict(int) | ||
tokensTotalPerPlayer = defaultdict(int) | ||
|
||
for (id, map) in pool.maps.items(): | ||
Check warning on line 543 in server/ladder_service/ladder_service.py Codacy Production / Codacy Static Code Analysisserver/ladder_service/ladder_service.py#L543
|
||
for player in all_players: | ||
vetoesMap[map.map_pool_map_version_id] += player.vetoes.get(map.map_pool_map_version_id, 0) | ||
tokensTotalPerPlayer[player.id] += player.vetoes.get(map.map_pool_map_version_id, 0) | ||
|
||
for player in all_players: | ||
if (tokensTotalPerPlayer[player.id] > veto_tokens_per_player): | ||
raise RuntimeError(f"Player {player.id} has too many vetoes!") | ||
|
||
if (max_tokens_per_map == 0): | ||
max_tokens_per_map = self.calculate_dynamic_tokens_per_map(minimum_maps_after_veto, vetoesMap.values()) | ||
|
||
game_map = pool.choose_map(played_map_ids, vetoesMap, max_tokens_per_map) | ||
|
||
game = self.game_service.create_game( | ||
game_class=LadderGame, | ||
|
@@ -673,6 +702,26 @@ | |
if player not in connected_players | ||
]) | ||
|
||
def calculate_dynamic_tokens_per_map(self, M: float, tokens: list[int]) -> float: | ||
sorted_tokens = sorted(tokens) | ||
if (sorted_tokens.count(0) >= M): | ||
return 1 | ||
|
||
result = 1; last = 0; index = 0 | ||
Check failure on line 710 in server/ladder_service/ladder_service.py GitHub Actions / flake8
|
||
while (index < len(sorted_tokens)): | ||
Check warning on line 711 in server/ladder_service/ladder_service.py GitHub Actions / flake8
|
||
(index, last) = next(((i, el) for i, el in enumerate(sorted_tokens) if el > last), (len(sorted_tokens) - 1, sorted_tokens[-1])) | ||
index += 1 | ||
divider = index - M | ||
if (divider <= 0): | ||
Check warning on line 715 in server/ladder_service/ladder_service.py GitHub Actions / flake8
|
||
continue | ||
|
||
result = sum(sorted_tokens[:index]) / divider | ||
upperLimit = sorted_tokens[index] if index < len(sorted_tokens) else float('inf') | ||
if (result <= upperLimit): | ||
return result | ||
|
||
raise Exception("Failed to calculate dynamic tokens per map: impossible vetoes setup") | ||
Comment on lines
+705
to
+723
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly here we are throwing an exception based on user input so a user could craft a veto selection that could cause the majority of games to fail to start. It would be better to have some default value rather than throwing an exception. |
||
|
||
async def get_game_history( | ||
self, | ||
players: list[Player], | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not do validation of the number of tokens per player when starting the game. This validation and error raising should happen when the server receives the set_vetoes message. This is because as it is now a player could send the server more than the max amount of vetoes and then cause a game to never be able to launch.