wip close round/campaign/war + refacto json None
This commit is contained in:
parent
4c8086caf4
commit
6cbb7c6534
26 changed files with 474 additions and 108 deletions
46
src/warchron/model/tie_manager.py
Normal file
46
src/warchron/model/tie_manager.py
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue