47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
|
|
from warchron.model.war import War
|
||
|
|
from warchron.model.war_event import InfluenceSpent
|
||
|
|
|
||
|
|
|
||
|
|
class ResolutionContext:
|
||
|
|
def __init__(self, context_type: str, context_id: str, participant_ids: list[str]):
|
||
|
|
self.context_type = context_type
|
||
|
|
self.context_id = context_id
|
||
|
|
self.participant_ids = participant_ids
|
||
|
|
|
||
|
|
self.current_bids: dict[str, int] = {}
|
||
|
|
self.round_index: int = 0
|
||
|
|
self.is_resolved: bool = False
|
||
|
|
|
||
|
|
|
||
|
|
class TieResolver:
|
||
|
|
|
||
|
|
@staticmethod
|
||
|
|
def resolve(
|
||
|
|
war: War,
|
||
|
|
context: ResolutionContext,
|
||
|
|
bids: dict[str, int],
|
||
|
|
) -> str | None:
|
||
|
|
# verify available token for each player
|
||
|
|
for pid, amount in bids.items():
|
||
|
|
participant = war.participants[pid]
|
||
|
|
if participant.influence_tokens() < amount:
|
||
|
|
raise ValueError("Not enough influence tokens")
|
||
|
|
# apply spending
|
||
|
|
for pid, amount in bids.items():
|
||
|
|
if amount > 0:
|
||
|
|
war.participants[pid].events.append(
|
||
|
|
InfluenceSpent(
|
||
|
|
participant_id=pid,
|
||
|
|
amount=amount,
|
||
|
|
context=context.context_type,
|
||
|
|
)
|
||
|
|
)
|
||
|
|
# determine winner
|
||
|
|
max_bid = max(bids.values())
|
||
|
|
winners = [pid for pid, b in bids.items() if b == max_bid]
|
||
|
|
if len(winners) == 1:
|
||
|
|
context.is_resolved = True
|
||
|
|
return winners[0]
|
||
|
|
# persisting tie → None
|
||
|
|
return None
|