resolve pairing WIP
This commit is contained in:
parent
0c6014e946
commit
241d7f10f5
11 changed files with 302 additions and 11 deletions
|
|
@ -24,6 +24,71 @@ class TieContext:
|
|||
|
||||
class TieResolver:
|
||||
|
||||
@staticmethod
|
||||
def find_choice_ties(
|
||||
war: War,
|
||||
round_id: str,
|
||||
) -> List[TieContext]:
|
||||
round = war.get_round(round_id)
|
||||
campaign = war.get_campaign_by_round(round_id)
|
||||
if campaign is None:
|
||||
raise RuntimeError("Round without campaign")
|
||||
ties: List[TieContext] = []
|
||||
scores = ScoreService.compute_scores(
|
||||
war,
|
||||
ContextType.CAMPAIGN,
|
||||
campaign.id,
|
||||
)
|
||||
score_groups = ScoreService.group_participants_by_score(
|
||||
scores, lambda score: score.victory_points
|
||||
)
|
||||
sector_to_battle = {b.sector_id: b for b in round.battles.values()}
|
||||
for group in score_groups:
|
||||
if len(group) <= 1:
|
||||
continue
|
||||
demand: Dict[str, List[str]] = {}
|
||||
for pid in group:
|
||||
choice = round.choices.get(pid)
|
||||
if not choice:
|
||||
continue
|
||||
for sec_id in (
|
||||
choice.priority_sector_id,
|
||||
choice.secondary_sector_id,
|
||||
):
|
||||
if sec_id:
|
||||
demand.setdefault(sec_id, []).append(pid)
|
||||
for sector_id, demanders in demand.items():
|
||||
battle = sector_to_battle.get(sector_id)
|
||||
if battle is None:
|
||||
continue
|
||||
places = len(battle.get_available_places())
|
||||
if len(demanders) <= places:
|
||||
continue
|
||||
context = TieContext(
|
||||
ContextType.CHOICE,
|
||||
round_id,
|
||||
demanders,
|
||||
score_value=None,
|
||||
score_kind=ScoreKind.VP,
|
||||
)
|
||||
if TieResolver.is_tie_resolved(war, context):
|
||||
continue
|
||||
if not TieResolver.can_tie_be_resolved(
|
||||
war,
|
||||
context,
|
||||
demanders,
|
||||
):
|
||||
war.events.append(
|
||||
TieResolved(
|
||||
None,
|
||||
ContextType.CHOICE,
|
||||
round_id,
|
||||
)
|
||||
)
|
||||
continue
|
||||
ties.append(context)
|
||||
return ties
|
||||
|
||||
@staticmethod
|
||||
def find_battle_ties(war: War, round_id: str) -> List[TieContext]:
|
||||
round = war.get_round(round_id)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue