-
Notifications
You must be signed in to change notification settings - Fork 0
/
territory.py
54 lines (40 loc) · 1.46 KB
/
territory.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
class Territory:
def __init__(self, name, board_pos, size_on_board, border_color):
self.name = name
self.board_pos = board_pos
self.size_on_board = size_on_board
self.border_color = border_color
self.neighbors = []
self.ruler = None
self.troops = 0
self.fill_color = ''
def __str__(self):
return self.name
def add_neighbor(self, neighbor):
self.neighbors.append(neighbor)
def is_neutral(self):
return not self.ruler
def is_border_territory(self):
for neighbor in self.neighbors:
if neighbor.ruler != self.ruler:
return True
return False
def enemy_neighbors(self):
enemy_neighbors = []
for neighbor in self.neighbors:
if neighbor.ruler != self.ruler:
enemy_neighbors.append(neighbor)
return enemy_neighbors
def friendly_fortifiers(self):
friendly_fortifiers = []
for neighbor in self.neighbors:
if neighbor.troops > 1 and neighbor.ruler == self.ruler:
friendly_fortifiers.append(neighbor)
return friendly_fortifiers
def can_be_attack_source(self, player):
for neighbor in self.neighbors:
if neighbor.ruler != player and self.troops > 1:
return True
return False
def can_be_fortify_target(self):
return self.friendly_fortifiers() and self.enemy_neighbors()