-
Notifications
You must be signed in to change notification settings - Fork 2
/
Player.py
53 lines (38 loc) · 1.38 KB
/
Player.py
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
CONQUER_BONUS = 2
class Player:
def __init__(self, pid):
self._territories = []
self._armies = 0
self._id = pid
def add_territory(self, territory):
from Territory import Territory
if not isinstance(territory, Territory):
raise TypeError
self._territories.append(territory)
territory.owner = self
def remove_territory(self, territory):
from Territory import Territory
if not isinstance(territory, Territory):
raise TypeError
self._territories.remove(territory)
territory.owner = None
def id(self):
return self._id
@property
def armies(self):
return self._armies
@armies.setter
def armies(self, armies):
if not isinstance(armies, int):
raise TypeError
self._armies = 0 if armies<0 else armies
def has_territory(self, t):
return t in self._territories
def conquer(self, attacker, attacked, placement):
assert attacker in self._territories
assert attacked in attacker.attackables()
attacker.n_armies -= attacked.n_armies + placement
attacked.n_armies = placement
self._armies += CONQUER_BONUS
attacked.owner.remove_territory(attacked)
self.add_territory(attacked)