-
Notifications
You must be signed in to change notification settings - Fork 0
/
playerActions.py
124 lines (103 loc) · 4.27 KB
/
playerActions.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
from player import Player
from copy import copy, deepcopy
# Returns all the possible actions that the player could make
# Actions are stored in a dictionary, with the function for
# a given action as the keyword, and necessary info as the value
def possibleActions(p):
#Note - needs to be fixed to reflect the new definition of PlayerHand
#also possible to be imperative and not functional
m = {}
#walk
m['walk'] = []
for c in p.l.neighbors:
m['walk'].append(c)
#directFlight, charterFlight, buildRS
m['charterFlight'] = []
m['directFlight'] = []
m['buildRS'] = []
for c in p.hand:
m['charterFlight'].append(c)
if c.city == p.l:
m['directFlight'] = [c]
if p.l.rs == 0:
m['buildRS'] = [c]
#researchFlight
m['researchFlight'] = []
if p.l.rs != 0:
for cty in p.board.researchStations:
if cty != p.l:
m['researchFlight'].append(c)
#treat
for color, n in p.l.cubes.items():
if n>=1:
m['treat'].append(color)
#giveCard, takeCard
m['giveCard'] = []
m['takeCard'] = []
for p2 in p.board.players:
if p2 != p:
for c in p.hand:
m['giveCard'].append((p2, c))
for c in p2.hand:
m['takeCard'].append((p2,c))
#cureDisease - unfinished
return m
#Gives a set of all possible cities that a player can move to
#with a single action, in the form of tuples of the city and the cost in cards.
#If a city can be reached in multiple ways, all will be returned.
#However, if one option is strictly better, only it will be returned.
def singleMovement(p):
newCities = {}
actions = possibleActions(p)
for w in actions['walk']:
newCities[w] = [[]]
for rf in actions['researchFlight']:
newCities[rf] = [[]]
for cf in actions['charterFlight']:
if cf.city not in newCities:
newCities[cf.city] = [[cf]]
for df in actions['directFlight']:
for cty in p.board.cities:
if cty not in newCities:
newCities[cty] = [[df]]
elif newCities[cty] != [[]]:
newCities[cty].append([df])
return newCities
#Returns a dictionary of all possible cities that a player can reach in exactly n moves, and their costs.
#If a city can be reached in multiple ways, all will be returned.
#However, if one option is strictly better, only it will be returned.
def manyMovements(p, n):
if n==1: #base case
return singleMovement(p)
else: #recursive step
newCities = {}
prev = manyMovements(p,n-1)
for prev_cty, prev_costs in prev.items(): #consider each city
for pc in prev_costs: #consider each cost to reach each city
temp_player = Player(p.name, prev_cty, deepcopy(p.hand), p.board)
temp_player.hand.remove(pc)
newStep = singleMovement(temp_player)
for cty, cost in newStep.items():
for c in cost: #look at each possible cost
newCost = pc + c
if cty in newCities: #reaching an old city
status = 'good'
#recheck for better options
for q in newCities[cty]:
if set(q) <= set(newCost):
status = 'worse'
elif set(q) >= set(newCost):
newCities[cty].remove(q)
if status == 'good':
newCities[cty].append(newCost)
else: #reaching a new city
newCities[cty] = [newCost]
return newCities
#returns a dict of ways to reach a city, with the key being the number of steps
#The method stops when the city can be reached with no card expenditure
def reachCity(p, c):
done = false
whie not done:
#Returns a dictionary of all cities that can be treated
#along with the number of each cube color removed, and the cost in cards
#def manyTreatments(p, n):