fix tie-break loser re-bid
This commit is contained in:
parent
c9407f9407
commit
60992c22df
2 changed files with 38 additions and 12 deletions
|
|
@ -18,7 +18,7 @@ from warchron.model.war import War
|
||||||
from warchron.model.campaign import Campaign
|
from warchron.model.campaign import Campaign
|
||||||
from warchron.model.campaign_participant import CampaignParticipant
|
from warchron.model.campaign_participant import CampaignParticipant
|
||||||
from warchron.model.sector import Sector
|
from warchron.model.sector import Sector
|
||||||
from warchron.model.tie_manager import TieContext
|
from warchron.model.tie_manager import TieContext, TieResolver
|
||||||
from warchron.model.score_service import ScoreService
|
from warchron.model.score_service import ScoreService
|
||||||
from warchron.view.campaign_dialog import CampaignDialog
|
from warchron.view.campaign_dialog import CampaignDialog
|
||||||
from warchron.view.campaign_participant_dialog import CampaignParticipantDialog
|
from warchron.view.campaign_participant_dialog import CampaignParticipantDialog
|
||||||
|
|
@ -144,14 +144,14 @@ class CampaignController:
|
||||||
) -> Dict[str, Dict[str, bool]]:
|
) -> Dict[str, Dict[str, bool]]:
|
||||||
bids_map = {}
|
bids_map = {}
|
||||||
for ctx in contexts:
|
for ctx in contexts:
|
||||||
|
active = TieResolver.get_active_participants(
|
||||||
|
war, ctx.context_type, ctx.context_id, ctx.participants
|
||||||
|
)
|
||||||
players = [
|
players = [
|
||||||
ParticipantOption(
|
ParticipantOption(id=pid, name=self.app.model.get_participant_name(pid))
|
||||||
id=pid,
|
for pid in active
|
||||||
name=self.app.model.get_participant_name(pid),
|
|
||||||
)
|
|
||||||
for pid in ctx.participants
|
|
||||||
]
|
]
|
||||||
counters = [war.get_influence_tokens(pid) for pid in ctx.participants]
|
counters = [war.get_influence_tokens(pid) for pid in active]
|
||||||
dialog = TieDialog(
|
dialog = TieDialog(
|
||||||
parent=self.app.view,
|
parent=self.app.view,
|
||||||
players=players,
|
players=players,
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,9 @@ class TieResolver:
|
||||||
raise RuntimeError("Missing player(s) in this battle context.")
|
raise RuntimeError("Missing player(s) in this battle context.")
|
||||||
p1 = campaign.participants[battle.player_1_id].war_participant_id
|
p1 = campaign.participants[battle.player_1_id].war_participant_id
|
||||||
p2 = campaign.participants[battle.player_2_id].war_participant_id
|
p2 = campaign.participants[battle.player_2_id].war_participant_id
|
||||||
if not TieResolver.can_tie_be_resolved(war, [p1, p2]):
|
if not TieResolver.can_tie_be_resolved(
|
||||||
|
war, ContextType.BATTLE, battle.sector_id, [p1, p2]
|
||||||
|
):
|
||||||
war.events.append(
|
war.events.append(
|
||||||
TieResolved(None, ContextType.BATTLE, battle.sector_id)
|
TieResolved(None, ContextType.BATTLE, battle.sector_id)
|
||||||
)
|
)
|
||||||
|
|
@ -64,7 +66,9 @@ class TieResolver:
|
||||||
tie_id = f"{campaign_id}:score:{score_value}"
|
tie_id = f"{campaign_id}:score:{score_value}"
|
||||||
if TieResolver.is_tie_resolved(war, ContextType.CAMPAIGN, tie_id):
|
if TieResolver.is_tie_resolved(war, ContextType.CAMPAIGN, tie_id):
|
||||||
continue
|
continue
|
||||||
if not TieResolver.can_tie_be_resolved(war, participants):
|
if not TieResolver.can_tie_be_resolved(
|
||||||
|
war, ContextType.CAMPAIGN, tie_id, participants
|
||||||
|
):
|
||||||
war.events.append(TieResolved(None, ContextType.CAMPAIGN, tie_id))
|
war.events.append(TieResolved(None, ContextType.CAMPAIGN, tie_id))
|
||||||
continue
|
continue
|
||||||
ties.append(
|
ties.append(
|
||||||
|
|
@ -127,6 +131,16 @@ class TieResolver:
|
||||||
groups[-1].append(pid)
|
groups[-1].append(pid)
|
||||||
return groups
|
return groups
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_active_participants(
|
||||||
|
war: War,
|
||||||
|
context_type: ContextType,
|
||||||
|
context_id: str,
|
||||||
|
participants: List[str],
|
||||||
|
) -> List[str]:
|
||||||
|
groups = TieResolver.rank_by_tokens(war, context_type, context_id, participants)
|
||||||
|
return groups[0]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def resolve_tie_state(
|
def resolve_tie_state(
|
||||||
war: War,
|
war: War,
|
||||||
|
|
@ -135,7 +149,14 @@ class TieResolver:
|
||||||
participants: List[str],
|
participants: List[str],
|
||||||
bids: dict[str, bool] | None = None,
|
bids: dict[str, bool] | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
# confirmed draw if bids are 0
|
active = TieResolver.get_active_participants(
|
||||||
|
war, context_type, context_id, participants
|
||||||
|
)
|
||||||
|
# confirmed draw if non had bid
|
||||||
|
if not active:
|
||||||
|
war.events.append(TieResolved(None, context_type, context_id))
|
||||||
|
return
|
||||||
|
# confirmed draw if current bids are 0
|
||||||
if bids is not None and not any(bids.values()):
|
if bids is not None and not any(bids.values()):
|
||||||
war.events.append(TieResolved(None, context_type, context_id))
|
war.events.append(TieResolved(None, context_type, context_id))
|
||||||
return
|
return
|
||||||
|
|
@ -147,8 +168,13 @@ class TieResolver:
|
||||||
# if tie persists, do nothing, workflow will call again
|
# if tie persists, do nothing, workflow will call again
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def can_tie_be_resolved(war: War, participants: List[str]) -> bool:
|
def can_tie_be_resolved(
|
||||||
return any(war.get_influence_tokens(pid) > 0 for pid in participants)
|
war: War, context_type: ContextType, context_id: str, participants: List[str]
|
||||||
|
) -> bool:
|
||||||
|
active = TieResolver.get_active_participants(
|
||||||
|
war, context_type, context_id, participants
|
||||||
|
)
|
||||||
|
return any(war.get_influence_tokens(pid) > 0 for pid in active)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def was_tie_broken_by_tokens(
|
def was_tie_broken_by_tokens(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue