forked from justinchen673/Catan-AI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
winType.py
170 lines (137 loc) · 5.22 KB
/
winType.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
class Win:
'''
This class defines a type of win the game. This is the list of be parsed when running
the AI in order to find the win that is most probable for the player. The
characteristics of the class are similar to that of the player class
'''
def __init__(self):
#I haven't included monoplies and year of plenty since they are very variable
#and their use changes based on the iterations of the game
self.devCardDict = {
"knight": 0,
"victoryPoint": 0,
"roadBuilding": 0
}
#amount of resources required to get that victory
self.resourceDict = {
"wheat": 0,
"sheep": 0,
"brick": 0,
"ore": 0,
"wood": 0
}
#number of Settlements and Cities required in that win
self.numSettlements = 0
self.numCities = 0
#bool based on whether or not a win required largest Arny
self.largestArmy = False
#bool based on whether or not win requires longest road as well as minimum roads
#needed to win
self.longestRoad = False
self.minRoadsNeeded = 0
#total victory points in this win
self.totalVicPts = 0
self.totalCost = 0
#a number to help keep track of this exact win
self.number = 0
'''
when you print the string you will get the number
'''
def __str__(self):
return str(self.number)
'''
defines the type of win/ what the player uses to win the game.
uses an input of similar dummy dictionaries and bools from the main AI function
'''
def setWinType(self, vicPts, army , road ,setts, cits):
#if army has 2 vic points, then the win requires largest army
if army == 2:
self.devCardDict["knight"] = 3
self.largestArmy = True
#if win has 2 vic points, then the win requires longest road
if road == 2:
self.longestRoad = True
#copies over the number of dev card victory points
self.devCardDict["victoryPoint"] = vicPts
#number of Settlements and cities in the win, cities divided by two, since they
#are worth double
self.numSettlements = setts
self.numCities = int(cits/2)
#set total victory points in this win
self.totalVicPts = vicPts + army + road +setts + cits
'''
sets the information for roads
including minimum roads needed and how many road building cards were uesd
'''
def setRoads(self, minR, rBuilding):
self.minRoadsNeeded = minR
self.devCardDict["roadBuilding"] = rBuilding
'''
sets the arbitary counter , just to help access and debugging in the future
'''
def setNumber(self, counter):
self.number = counter
'''
calculate the total resouces requied to accomplish that particular winning strategy
returns the dictionary of the resources
'''
def calcResourceCost(self):
#sum of all dev cards required in the win
devSum = self.devCardDict["knight"] + self.devCardDict["victoryPoint"] + self.devCardDict["roadBuilding"]
#adds neccesarry resources for all the dev cards
for i in range(0, devSum):
self.resourceDict["sheep"] = self.resourceDict["sheep"] + 1
self.resourceDict["ore"] = self.resourceDict["ore"] + 1
self.resourceDict["wheat"] = self.resourceDict["wheat"] + 1
#add the neccesarry resource for all the settlements plus the cities minus 2
#this is because all cities were settlements once
#also we start with 2 settlements that are free
for i in range(0, self.numSettlements + self.numCities - 2):
self.resourceDict["sheep"] = self.resourceDict["sheep"] + 1
self.resourceDict["wood"] = self.resourceDict["wood"] + 1
self.resourceDict["brick"] = self.resourceDict["brick"] + 1
self.resourceDict["wheat"] = self.resourceDict["wheat"] + 1
#add neccesarry resources for all the Cities
for i in range(0, self.numCities):
self.resourceDict["ore"] = self.resourceDict["ore"] + 3
self.resourceDict["wheat"] = self.resourceDict["wheat"] + 2
#add neccessary resources for all roads built
#minus road building since we accounted for that earlier
#minus the 2 roads we started with
for i in range(0, self.minRoadsNeeded - (2*self.devCardDict["roadBuilding"]) -2):
self.resourceDict["wood"] = self.resourceDict["wood"] + 1
self.resourceDict["brick"] = self.resourceDict["brick"] + 1
return self.resourceDict
'''
calculates the total cost by summing the resource cards required for the victory
'''
def calcTotalCost(self):
for key,val in self.resourceDict.items():
self.totalCost = self.totalCost + val
'''
for i in range(0, self.devCardDict["knight"]):
self.totalCost = self.totalCost -1
'''
return self.totalCost
'''
calculates the victory points in this particular solution
'''
def vicPoints(self):
self.totalVicPts = self.devCardDict["victoryPoint"] + self.numSettlements
self.totalVicPts = self.totalVicPts + (2* self.numCities)
if self.longestRoad == True:
self.totalVicPts = self.totalVicPts + 2
if self.largestArmy == True:
self.totalVicPts = self.totalVicPts + 2
'''
makes sure that victory points are greater than 10
'''
def sanityCheck(self):
if (self.totalVicPts >=10):
return True
return False
'''
sets the less than symbol for comparisons and sorting
'''
def __lt__(self, other):
return self.totalCost < other.totalCost