-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactions.py
268 lines (211 loc) · 7.73 KB
/
actions.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
import util
class Action:
def __init__( self ):
pass
def choose(self,state):
gameState = state.deepCopy()
return gameState
def resolve(self,state):
gameState = state.deepCopy()
return gameState
class Challenge(Action):
def __init__(self, playerChallenge):
self.type = 'challenge'
self.playerChallenge = playerChallenge
def choose(self,state):
gameState = state.deepCopy()
gameState.actionStack.append(self)
gameState.playerChallenge = self.playerChallenge
actionIsBlock = gameState.playerBlock is not None
lastPlayer = gameState.playerBlock if actionIsBlock else gameState.playerTurn
if not actionIsBlock:
influences = util.actionToInfluence[gameState.currentAction] #Influence is a list
#want to see if playerTurn has that Influence
result = any([True for x in influences if x in gameState.players[gameState.playerTurn].influences] )
self.punishedPlayer = self.playerChallenge if result else gameState.playerTurn
self.challengeSuccess = not result
else:
influences = util.blockToInfluence[gameState.currentAction] #Influence is a list
#want to see if playerTurn has that Influence
result = any([True for x in influences if x in gameState.players[gameState.playerBlock].influences] )
self.punishedPlayer = self.playerChallenge if result else gameState.playerBlock
self.challengeSuccess = not result
return gameState
def resolve(self, state):
gameState = state.deepCopy()
gameState.challengeSuccess = self.challengeSuccess
if self.challengeSuccess:
gameState.actionStack.pop()
gameState.punishedPlayers.append(self.punishedPlayer)
return gameState
def __str__(self):
return 'Challenge by %r' %(self.playerChallenge)
class Tax(Action):
def __init__(self):
self.type = 'tax'
def choose(self, state):
gameState = state.deepCopy()
gameState.currentAction = 'tax'
gameState.actionStack.append(self)
gameState.players[gameState.playerTurn].possibleInfluences['duke'] += 1
return gameState
def resolve(self, state):
gameState = state.deepCopy()
#Current player's coin amount += 3
gameState.players[gameState.playerTurn].coins += 3
return gameState
def __str__(self):
return 'Tax'
class Assassinate(Action):
def __init__(self, target):
self.target = target
self.type = 'assassinate'
def choose(self, state):
gameState = state.deepCopy()
gameState.currentAction = 'assassinate'
gameState.actionStack.append(self)
gameState.players[gameState.playerTurn].possibleInfluences['assassin'] += 1
gameState.players[gameState.playerTurn].coins -= 3
gameState.playerTarget = self.target
return gameState
def resolve(self, state):
gameState = state.deepCopy()
gameState.punishedPlayers.append(self.target)
return gameState
def __str__(self):
return 'Assassination of: %r' %(self.target)
class Exchange(Action):
def __init__(self):
self.type = 'exchange'
def choose(self, state):
gameState = state.deepCopy()
gameState.currentAction = 'exchange'
gameState.actionStack.append(self)
gameState.players[gameState.playerTurn].possibleInfluences['ambassador'] += 1
return gameState
def resolve(self, state):
gameState = state.deepCopy()
gameState.playerExchange = gameState.playerTurn
addCards = gameState.deck[0:2]
gameState.deck = gameState.deck[2:]
gameState.players[gameState.playerTurn].influences += addCards
gameState.punishedPlayers += [gameState.playerTurn, gameState.playerTurn]
return gameState
def __str__(self):
return 'Exchange'
class Steal(Action):
def __init__(self, target):
self.target = target
self.type = 'steal'
def choose(self, state):
gameState = state.deepCopy()
gameState.currentAction = 'steal'
gameState.actionStack.append(self)
gameState.players[gameState.playerTurn].possibleInfluences['captain'] += 1
gameState.playerTarget = self.target
return gameState
def resolve(self, state):
gameState = state.deepCopy()
stolenCoins = min(gameState.players[self.target].coins, 2)
gameState.players[self.target].coins -= stolenCoins
gameState.players[gameState.playerTurn].coins += stolenCoins
return gameState
def __str__(self):
return 'Steal from: %r' %(self.target)
class Income(Action):
def __init__(self):
self.type = 'income'
def choose(self, state):
gameState = state.deepCopy()
gameState.currentAction = 'income'
gameState.actionStack.append(self)
return gameState
def resolve(self, state):
gameState = state.deepCopy()
#Current player's coin amount += 1
gameState.players[gameState.playerTurn].coins += 1
return gameState
def __str__(self):
return 'Income'
class ForeignAid(Action):
def __init__(self):
self.type = 'foreign aid'
def choose(self, state):
gameState = state.deepCopy()
gameState.currentAction = 'foreign aid'
gameState.actionStack.append(self)
return gameState
def resolve(self, state):
gameState = state.deepCopy()
#Current player's coin amount += 2
gameState.players[gameState.playerTurn].coins += 2
return gameState
def __str__(self):
return 'Foreign Aid'
class Coup(Action):
def __init__(self, target):
self.target = target
self.type = 'coup'
def choose(self, state):
gameState = state.deepCopy()
gameState.currentAction = 'coup'
gameState.actionStack.append(self)
return gameState
def resolve(self, state):
gameState = state.deepCopy()
gameState.players[gameState.playerTurn].coins -= 7
gameState.punishedPlayers.append(self.target)
return gameState
def __str__(self):
return 'Coup on: %r' % (self.target)
class Block(Action):
def __init__(self, playerBlock):
self.playerBlock = playerBlock
self.type = 'block'
def choose(self, state):
gameState = state.deepCopy()
gameState.playerBlock = self.playerBlock
gameState.actionStack.append(self)
if gameState.currentAction == 'foreign aid':
gameState.players[gameState.playerTurn].possibleInfluences['duke'] += 1
elif gameState.currentAction == 'assassinate':
gameState.players[gameState.playerTurn].possibleInfluences['contessa'] += 1
elif gameState.currentAction == 'steal':
gameState.players[gameState.playerTurn].possibleInfluences['captain'] += 0.5
gameState.players[gameState.playerTurn].possibleInfluences['ambassador'] += 0.5
return gameState
def resolve(self, state):
gameState = state.deepCopy()
gameState.playerBlock = None # why?
if len(gameState.actionStack) > 0:
gameState.actionStack.pop()
return gameState
def __str__(self):
return 'Block by: %r' % (self.playerBlock)
class Discard(Action):
def __init__(self, player, influenceIndex):
self.influenceIndex = influenceIndex
self.player = player
self.type = 'discard'
def choose(self, state):
gameState = state.deepCopy()
gameState.actionStack.insert(0, self)
return gameState
def resolve(self, state):
gameState = state.deepCopy()
gameState.punishedPlayers.remove(self.player)
influences = gameState.players[self.player].influences
if len(influences) == 0:
print 'OOPS influences empty'
return gameState
if len(influences) <= self.influenceIndex:
print 'OOPS influences out of range'
self.influenceIndex = len(influences) - 1
if self.player == gameState.playerExchange:
gameState.deck.append(influences[self.influenceIndex])
else:
gameState.inactiveInfluences[influences[self.influenceIndex]] += 1
del gameState.players[self.player].influences[self.influenceIndex]
return gameState
def __str__(self):
return 'Discard by: %r [%d]' %(self.player, self.influenceIndex)