Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions server/ladder_service/veto_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,21 +260,20 @@ def _is_valid_veto_config_for_queue(
) -> bool:
num_maps = len(queue_config.map_pool.maps)

if (queue_config.minimum_maps_after_veto > num_maps):
return False

if (
queue_config.max_tokens_per_map == 0
and queue_config.minimum_maps_after_veto >= num_maps
and queue_config.minimum_maps_after_veto == num_maps
and queue_config.veto_tokens_per_player > 0
):
return False

if queue_config.max_tokens_per_map != 0:
total_players = queue.team_size * 2
vetoable_maps_per_player = queue_config.veto_tokens_per_player / queue_config.max_tokens_per_map
vetoable_maps = total_players * vetoable_maps_per_player

# tokens/map > number of maps that may be vetoed
# TODO: because vetoable_maps >= 0 this inequality also implies
# queue_config.minimum_maps_after_veto > num_maps
# Why is it strictly greater than here but greater than or equal to above?
if vetoable_maps > num_maps - queue_config.minimum_maps_after_veto:
return False

Expand Down
11 changes: 8 additions & 3 deletions server/matchmaker/map_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ def apply_antirepetition_adjustment(self, initial_weights: dict[int, float], pla
adjusted_weights = notzero_weights.copy()

def get_notrepeated_weight_transfer_targets(current_weight, rep_count):
for base_threshold in base_thresholds:
thresholds = list(base_thresholds)
factor = repeat_factor ** (rep_count - 1)
if factor < 1:
thresholds.extend(t * factor for t in base_thresholds if t * factor < base_thresholds[-1])

for threshold in thresholds:
targets = [
target_id for target_id in notzero_weights
if repetition_counts.get(target_id, 0) == 0 and
notzero_weights[target_id] >= base_threshold * repeat_factor ** (rep_count - 1) * current_weight
notzero_weights[target_id] >= threshold * current_weight
]
if targets:
return targets
Expand Down Expand Up @@ -100,7 +105,7 @@ def choose_map(self, played_map_ids: Iterable[int] = (), initial_weights: Option
self._logger.debug("______map_list________________: %s", map_list)
final_weights = [adjusted_weights.get(mp_mv_id, 0) * m.weight for mp_mv_id, m in map_list]
self._logger.debug("______final_weights________________: %s", final_weights)
return random.choices([map for _, map in map_list], weights=final_weights, k=1)[0].get_map()
return random.choices([map for _, map in map_list], weights=final_weights, k=1)[0].get_map() # nosec B311

def __repr__(self) -> str:
return f"MapPool({self.id}, {self.name}, {list(self.maps.values())})"
Expand Down
10 changes: 5 additions & 5 deletions tests/unit_tests/test_map_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def test_choose_map_raises_on_empty_map_pool(map_pool_factory):
{1: 0, 2: 1.5, 3: 1.5}
),
# Really complex redistribution test
# 1 -> [5,6], [2,3] -> [5,6,8], [7,9] -> 5
# 1 -> [5], [2,3] -> [5,6,8], [7,9] -> 5
(
{1: 0.9, 2: 0.6, 3: 0.4, 4: 0.2, 5: 0.75, 6: 0.6, 7: 1, 8: 0.5, 9: 1},
[1, 1, 2, 3, 7, 9],
Expand All @@ -261,8 +261,8 @@ def test_choose_map_raises_on_empty_map_pool(map_pool_factory):
2: 0,
3: 0,
4: 0.2,
5: pytest.approx(3.655405, rel=1e-6),
6: pytest.approx(1.324324, rel=1e-6),
5: pytest.approx(4.055405, rel=1e-6),
6: pytest.approx(0.924324, rel=1e-6),
7: 0,
8: pytest.approx(0.770270, rel=1e-6),
9: 0
Expand All @@ -279,8 +279,8 @@ def test_choose_map_raises_on_empty_map_pool(map_pool_factory):
2: 0,
3: 0,
4: 0.2,
5: pytest.approx(3.655405, rel=1e-6),
6: pytest.approx(1.324324, rel=1e-6),
5: pytest.approx(4.055405, rel=1e-6),
6: pytest.approx(0.924324, rel=1e-6),
7: 0,
8: pytest.approx(0.770270, rel=1e-6),
9: 0
Expand Down
Loading