-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
63 lines (53 loc) · 1.8 KB
/
Copy pathmodels.py
File metadata and controls
63 lines (53 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# models.py
"""
Data models for GeoPolitical Domination.
Uses dataclasses for type safety and clarity.
"""
from dataclasses import dataclass, field
from typing import Optional, Set, Tuple
import random
import logging
from constants import PALETTE, STARTING_MONEY
logger = logging.getLogger(__name__)
@dataclass
class Player:
"""Represents a player (human or bot) in the game."""
name: str
is_bot: bool = False
color: Tuple[int, int, int] = (120, 120, 120)
money: int = STARTING_MONEY
vulnerable: bool = False
was_attacked: bool = False
owned: Set[int] = field(default_factory=set)
troop_buy_limit: int = 20
last_gather_turn: int = 0
is_host: bool = False
is_spectator: bool = False
eliminated: bool = False
had_territory: bool = False # tracks if player ever owned territory
def __post_init__(self):
if self.color == (120, 120, 120) and not self.is_bot:
self.color = random.choice(PALETTE)
def troop_count(self, countries):
"""Count total troops across all owned territories."""
return sum(
int(c.get("troops", 0))
for c in countries.values()
if c.get("owner") == self.name
)
def country_count(self):
"""Count owned territories."""
return len(self.owned)
def to_snapshot_dict(self):
"""Convert to a snapshot-compatible dict for bot AI and rendering."""
return {
"name": self.name,
"money": self.money,
"is_bot": self.is_bot,
"color": self.color,
"vulnerable": bool(self.vulnerable),
"was_attacked": bool(self.was_attacked),
"is_host": bool(self.is_host),
"is_spectator": bool(self.is_spectator),
"eliminated": bool(self.eliminated),
}