Skip to content

Commit 3795aff

Browse files
authored
Merge pull request #1033 from K-ETFreeman/feature/#1032-working-veto-system
2 parents 6b70550 + 49eb2f8 commit 3795aff

7 files changed

Lines changed: 23 additions & 20 deletions

File tree

server/ladder_service/veto_system.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def extract_pools_veto_config(
116116
map_pool_map_version_ids=[
117117
map.map_pool_map_version_id
118118
for map in matchmaker_queue_map_pool.map_pool.maps.values()
119-
] + [-1],
119+
],
120120
veto_tokens_per_player=veto_tokens_per_player,
121121
max_tokens_per_map=max_tokens_per_map,
122122
minimum_maps_after_veto=minimum_maps_after_veto
@@ -260,21 +260,20 @@ def _is_valid_veto_config_for_queue(
260260
) -> bool:
261261
num_maps = len(queue_config.map_pool.maps)
262262

263+
if (queue_config.minimum_maps_after_veto > num_maps):
264+
return False
265+
263266
if (
264267
queue_config.max_tokens_per_map == 0
265-
and queue_config.minimum_maps_after_veto >= num_maps
268+
and queue_config.minimum_maps_after_veto == num_maps
269+
and queue_config.veto_tokens_per_player > 0
266270
):
267271
return False
268272

269273
if queue_config.max_tokens_per_map != 0:
270274
total_players = queue.team_size * 2
271275
vetoable_maps_per_player = queue_config.veto_tokens_per_player / queue_config.max_tokens_per_map
272276
vetoable_maps = total_players * vetoable_maps_per_player
273-
274-
# tokens/map > number of maps that may be vetoed
275-
# TODO: because vetoable_maps >= 0 this inequality also implies
276-
# queue_config.minimum_maps_after_veto > num_maps
277-
# Why is it strictly greater than here but greater than or equal to above?
278277
if vetoable_maps > num_maps - queue_config.minimum_maps_after_veto:
279278
return False
280279

server/matchmaker/map_pool.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,16 @@ def apply_antirepetition_adjustment(self, initial_weights: dict[int, float], pla
3838
adjusted_weights = notzero_weights.copy()
3939

4040
def get_notrepeated_weight_transfer_targets(current_weight, rep_count):
41-
for base_threshold in base_thresholds:
41+
thresholds = list(base_thresholds)
42+
factor = repeat_factor ** (rep_count - 1)
43+
if factor < 1:
44+
thresholds.extend(t * factor for t in base_thresholds if t * factor < base_thresholds[-1])
45+
46+
for threshold in thresholds:
4247
targets = [
4348
target_id for target_id in notzero_weights
4449
if repetition_counts.get(target_id, 0) == 0 and
45-
notzero_weights[target_id] >= base_threshold * repeat_factor ** (rep_count - 1) * current_weight
50+
notzero_weights[target_id] >= threshold * current_weight
4651
]
4752
if targets:
4853
return targets
@@ -100,7 +105,7 @@ def choose_map(self, played_map_ids: Iterable[int] = (), initial_weights: Option
100105
self._logger.debug("______map_list________________: %s", map_list)
101106
final_weights = [adjusted_weights.get(mp_mv_id, 0) * m.weight for mp_mv_id, m in map_list]
102107
self._logger.debug("______final_weights________________: %s", final_weights)
103-
return random.choices([map for _, map in map_list], weights=final_weights, k=1)[0].get_map()
108+
return random.choices([map for _, map in map_list], weights=final_weights, k=1)[0].get_map() # nosec B311
104109

105110
def __repr__(self) -> str:
106111
return f"MapPool({self.id}, {self.name}, {list(self.maps.values())})"

server/matchmaker/matchmaker_queue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def __init__(
6666
self.team_size = team_size
6767
self.rating_peak = 1000.0
6868
self.params = params or {}
69-
self.map_pools = {info.id: info for info in map_pools}
69+
self.map_pools = {info.map_pool.id: info for info in map_pools}
7070

7171
self._queue: dict[Search, None] = OrderedDict()
7272
self.on_match_found = on_match_found

server/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ def get_map(self) -> Map:
146146
folder_name=folder_name,
147147
ranked=True,
148148
weight=self.weight,
149+
map_pool_map_version_id=self.map_pool_map_version_id,
149150
)
150151

151152

tests/integration_tests/test_matchmaker_vetoes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ async def test_map_pool_changes_causing_silent_update_and_not_stops_search(playe
175175
)
176176
await ladder_service.update_data()
177177
msg = await read_until_command(proto, "vetoes_info", timeout=10)
178-
print(f"Received vetoes_info: {msg}")
178+
179179
assert msg.get("forced") is False
180180
assert msg["vetoes"] == gen_vetoes([])
181181
assert player.state == PlayerState.SEARCHING_LADDER

tests/unit_tests/test_map_pool.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def test_choose_map_raises_on_empty_map_pool(map_pool_factory):
250250
{1: 0, 2: 1.5, 3: 1.5}
251251
),
252252
# Really complex redistribution test
253-
# 1 -> [5,6], [2,3] -> [5,6,8], [7,9] -> 5
253+
# 1 -> [5], [2,3] -> [5,6,8], [7,9] -> 5
254254
(
255255
{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},
256256
[1, 1, 2, 3, 7, 9],
@@ -261,8 +261,8 @@ def test_choose_map_raises_on_empty_map_pool(map_pool_factory):
261261
2: 0,
262262
3: 0,
263263
4: 0.2,
264-
5: pytest.approx(3.655405, rel=1e-6),
265-
6: pytest.approx(1.324324, rel=1e-6),
264+
5: pytest.approx(4.055405, rel=1e-6),
265+
6: pytest.approx(0.924324, rel=1e-6),
266266
7: 0,
267267
8: pytest.approx(0.770270, rel=1e-6),
268268
9: 0
@@ -279,8 +279,8 @@ def test_choose_map_raises_on_empty_map_pool(map_pool_factory):
279279
2: 0,
280280
3: 0,
281281
4: 0.2,
282-
5: pytest.approx(3.655405, rel=1e-6),
283-
6: pytest.approx(1.324324, rel=1e-6),
282+
5: pytest.approx(4.055405, rel=1e-6),
283+
6: pytest.approx(0.924324, rel=1e-6),
284284
7: 0,
285285
8: pytest.approx(0.770270, rel=1e-6),
286286
9: 0

tests/unit_tests/test_veto_system.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ def test_is_valid_veto_config_for_queue(queue_factory):
2727
) is False
2828

2929
# minimum_maps_after_veto equal to map pool size
30-
# TODO: Is calling this invalid really the desired behavior? When
31-
# max_tokens_per_map != 0, they are allowed to be equal
3230
assert _is_valid_veto_config_for_queue(
3331
queue,
3432
MatchmakerQueueMapPool(
@@ -40,7 +38,7 @@ def test_is_valid_veto_config_for_queue(queue_factory):
4038
max_tokens_per_map=0,
4139
minimum_maps_after_veto=1,
4240
)
43-
) is False
41+
) is True
4442

4543
assert _is_valid_veto_config_for_queue(
4644
queue,

0 commit comments

Comments
 (0)