-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.py
160 lines (127 loc) · 4.29 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
class Player:
def __init__(self, playerId):
self.playerId = playerId
self.lumber = 1
self.wheat = 1
self.sheep = 1
self.ore = 0
self.brick = 1
self.army = 0
self.largest_army = False
self.longest_road = False
self.settlements = []
self.roads = []
self.dev_cards = []
self.ready = False
# checks #########################
def can_buy_settlement(self):
if self.lumber >= 1 and self.brick >= 1 and self.sheep >= 1 and self.wheat >= 1 and len(self.settlements) < 5:
return True
elif len(self.settlements) < 2:
return True
else:
return False
def can_upgrade_settlement(self):
if self.wheat >= 2 and self.ore >= 3 and self.count_cities() < 4:
return True
else:
return False
def can_buy_road(self):
if (self.brick >= 1 and self.lumber >= 1 and len(self.roads) < 15) or len(self.roads) < 2:
return True
else:
return False
def can_buy_dev_card(self, lodc):
if self.sheep >= 1 and self.wheat >= 1 and self.ore >= 1 and lodc:
return True
else:
return False
def road_at_pos(self, pos):
for road in self.roads:
if road.is_inside_local(1, pos) or road.is_inside_local(2, pos):
return True
return False
def settlement_at_pos(self, pos):
for settlement in self.settlements:
if settlement.is_inside_local(pos):
return True
return False
# purchase #########################
def buy_settlement(self):
if len(self.settlements) >= 2:
self.lumber -= 1
self.brick -= 1
self.sheep -= 1
self.wheat -= 1
def upgrade_settlement(self):
self.wheat -= 2
self.ore -= 3
def buy_road(self):
if len(self.roads) >= 2:
self.brick -= 1
self.lumber -= 1
def buy_dev_card(self):
self.sheep -= 1
self.wheat -= 1
self.ore -= 1
# misc ####################
def count_resources(self):
sum_of_resources = self.brick + self.lumber + self.sheep + self.wheat + self.ore
return sum_of_resources
def get_list_of_resources(self):
resource_list = []
resource_list = resource_list + (['lumber'] * self.lumber) + (['wheat'] * self.wheat) + (['ore'] * self.ore)
resource_list = resource_list + (['brick'] * self.brick) + (['sheep'] * self.sheep)
return resource_list
def count_cities(self):
i = 0
for settlement in self.settlements:
if settlement.level == 2:
i += 1
return i
# dev cards ###############
def count_dev_card(self, card_type):
i = 0
for card in self.dev_cards:
if card == card_type:
i += 1
return i
def pop_dev_card(self, card_type):
i = 0
while i < len(self.dev_cards):
if self.dev_cards[i] == card_type:
self.dev_cards.pop(i)
return
i += 1
# Trade #################
def can_4_for_1(self):
t1 = self.wheat >= 4 or self.lumber >= 4 or self.ore >= 4 or self.brick >= 4 or self.sheep >= 4
return t1
def can_3_for_1(self):
can = self.wheat >= 3 or self.lumber >= 3 or self.ore >= 3 or self.brick >= 3 or self.sheep >= 3
return can
def add_amount_of(self, resource, num):
if resource == 'lumber':
self.lumber += num
elif resource == 'sheep':
self.sheep += num
elif resource == 'wheat':
self.wheat += num
elif resource == 'ore':
self.ore += num
elif resource == 'brick':
self.brick += num
def has_resources(self):
can = self.wheat or self.lumber or self.ore or self.brick or self.sheep
return can
# victory_points
def count_vps(self):
vps = 0
for settlement in self.settlements:
vps += settlement.level
vps += self.dev_cards.count('victory_point')
if self.longest_road:
vps += 2
if self.largest_army:
vps += 2
return vps