-
Notifications
You must be signed in to change notification settings - Fork 1
/
helper_functions.py
230 lines (203 loc) · 9.55 KB
/
helper_functions.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
from PlayerCountry import PlayerCountry
from random import random, sample, randint
def treasryChange(country, nChange):
country.treasury = country.treasury + nChange
def cResourceChange(country, nChange):
country.cResources = coutry.cResources + nChange
def changeGDP(country, nChange):
country.GDP = country.GDP + nChange
def changeNukeResearch(country, nChange):
country.nukeResearch = country.nukeResearch + nChange
def changeAAResearch(country, nChange):
country.aaResearch = country.aaResearch + nChange
def changeMProduction(country, nChange):
country.mProduction = country.mProduction + nChange
def changeFProduction(country, nChange):
country.fProduction = country.fProduction + nChange
def changeARResearch(country, nChange):
country.ARResearch = country.ARResearch + nChange
def changeEducation(country, nChange):
country.education = country.education + nChange
def changeFaValues(country, nChange):
country.faValues = country.faValues + nChange
def fTrage(country1, country2, resource1, amount1, resource2, amount2): #f = food, t = treasury, n = nukes
if(resource1 == f and resouce2 == n):
country1.cResources = country1.cResources - amount1
country1.nukes = country1.nukes + amount2
country2.nukes = country2.nukes - amount2
country2.cResources = country2.cResources + amount1
elif(resources1 == f and resource2 == t):
country1.cResources = country1.cResources - amount1
country1.treasury = country1.treasury + amount2
country2.treasury = country2.treasury - amount2
country2.cResources = country2.cResources + amount1
elif(resources1 == n and resource2 == t):
country1.nukes = country1.nukes - amount1
country1.treasury = country1.treasury + amount2
country2.treasury = country2.treasury - amount2
country2.nukes = country2.nukes + amount1
########3 OPPOSITE FUNCTIONS ##########
elif(resource1 == n and resouce2 == f):
country2.cResources = country2.cResources - amount2
country2.nukes = country2.nukes + amount1
country1.nukes = country1.nukes - amount1
country1.cResources = country1.cResources + amount2
elif(resources1 == t and resource2 == f):
country2.cResources = country2.cResources - amount1
country2.treasury = country2.treasury + amount2
country1.treasury = country1.treasury - amount2
country1.cResources = country1.cResources + amount1
elif(resources1 == t and resource2 == n):
country2.nukes = country2.nukes - amount1
country2.treasury = country2.treasury + amount2
country1.treasury = country1.treasury - amount2
country1.nukes = country1.nukes + amount1
def launchNuke(c1, c2, target): # c1 is your own country, c2 is the opposing country, target is the specific city
print("LaunchNuke Called")
if (c1.faValues.get(c2.name) == 0):
print("Valid Target")
if (c1.nukes > 0):
print("Has Nukes Available")
c1.nukes = c1.nukes - 1
if (c2.cityDictionary.get(target)[1] != 0):
c2.cityDictionary.get(target)[1] = c2.cityDictionary.get(target)[1] - 1
if (c1.nukeResearch > c2.aaResearch):
diff = c1.nukeResearch - c2.aaResearch
initPop = c2.cityDictionary.get(target)[0]
if(diff > 14):
c2.cityDictionary.get(target)[0] = 0;
c2.population -= initPop
elif(diff == 14):
c2.cityDictionary.get(target)[0] = initPop*.01;
c2.population -= initPop*.99
elif(diff == 13):
c2.cityDictionary.get(target)[0] = initPop*.02;
c2.population -= initPop*.98
elif(diff == 12):
c2.cityDictionary.get(target)[0] = initPop*.03;
c2.population -= initPop*.97
elif(diff == 11):
c2.cityDictionary.get(target)[0] = initPop*.04;
c2.population -= initPop*.96
elif(diff == 10):
c2.cityDictionary.get(target)[0] = initPop*.05;
c2.population -= initPop*.95
elif(diff == 9):
c2.cityDictionary.get(target)[0] = initPop*.15;
c2.population -= initPop*.85
elif(diff == 8):
c2.cityDictionary.get(target)[0] = initPop*.25;
c2.population -= initPop*.75
elif(diff == 7):
c2.cityDictionary.get(target)[0] = initPop*.35;
c2.population -= initPop*.65
elif(diff == 6):
c2.cityDictionary.get(target)[0] = initPop*.45;
c2.population -= initPop*.55
elif(diff == 5):
c2.cityDictionary.get(target)[0] = initPop*.6;
c2.population -= initPop*.4
elif(diff == 4):
c2.cityDictionary.get(target)[0] = initPop*.7;
c2.population -= initPop*.3
elif(diff == 3):
c2.cityDictionary.get(target)[0] = initPop*.8;
c2.population -= initPop*.2
elif(diff == 2):
c2.cityDictionary.get(target)[0] = initPop*.9;
c2.population -= initPop*.1
elif(diff == 1):
c2.cityDictionary.get(target)[0] = initPop*.95;
c2.population -= initPop*.05
else:
return False
def researchPurchase(country, researchType):
if(researchType == "Anti-Air"):
stock = 0
for (k, v) in country.cityDictionary.items():
stock += v[1]
cost = country.aaResearch * 25000 * (1.025**stock)
if(country.treasury > cost):
country.treasury = country.treasury - cost
country.aaResearch += 1
elif(researchType == "Nuclear"):
cost = country.nukeResearch * 25000 * (1.025**country.nukes)
if(country.treasury > cost):
country.treasury = country.treasury - cost
country.nukeResearch += 1
elif(researchType == "Food Production"):
cost = country.fProduction * 12500
if(country.treasury > cost):
country.treasury -= cost
country.fProduction += 1
def getAAResearchCost(country):
stock = 0
for (k, v) in country.cityDictionary.items():
stock += v[1]
return (country.aaResearch * 25000 * (1.025**stock))
def getNukeResearchCost(country):
return country.nukeResearch * 25000 * (1.025**country.nukes)
def getFProductionCost(country):
return country.fProduction * 12500
def getNukeCost():
return 3000000
def getAACost():
return 1500000
def makeNuke(c1):
if (c1.treasury >= 3000000):
c1.treasury -= 3000000
c1.nukes += 1
def makeAntiAir(c1, city):
if (c1.treasury >= 1500000):
c1.treasury -= 1500000
c1.cityDictionary[city] = c1.cityDictionary.get(city)[1] + 1
def winLossCondition(players, nukes, turn):
if (nukes >= 100):
return None, False
elif (turn == 100):
highest = 0
for player in players:
if ((player.population)/(player.startingPop) > highest):
highest = player
return player, True
else:
for player in players:
if ((player.population)/(player.startingPop) < .5):
return player, False
def agentCountryTurn(country, players):
cities = []
for (k, v) in country.cityDictionary.items():
cities.append(k)
aaPurchase = (random() < ((1-(getAACost()/country.treasury))*.35))
while(aaPurchase):
makeAntiAir(country, cities[randint(0, len(cities)-1)])
nukePurchase = (random() < ((1-(getAACost()/country.treasury))*.35))
nukePurchase = (random() < ((1-(getNukeCost()/country.treasury))*.25))
while(nukePurchase):
makeNuke(country)
nukePurchase = (random() < ((1-(getNukeCost()/country.treasury))*.25))
investments = sample(range(3), randint(0,3))
if(0 in investments):
nukeInvestment = (random() < ((1-(getNukeResearchCost(country)/country.treasury))*.33))
while(nukeInvestment):
researchPurchase(country, "Nuclear")
nukeInvestment = random() < ((1-(getNukeResearchCost(country)/country.treasury))*.33)
if(1 in investments):
aaInvestment = (random() < ((1-(getAAResearchCost(country)/country.treasury))*.33))
while(aaInvestment):
researchPurchase(country, "Anti-Air")
aaInvestment = (random() < ((1-(getAAResearchCost(country)/country.treasury))*.33))
if(2 in investments):
fInvestment = (random() < ((1-(getFProductionCost(country)/country.treasury))*.33))
while(fInvestment):
researchPurchase(country, "Food Production")
fInvestment = (random() < ((1-(getFProductionCost(country)/country.treasury))*.33))
if(country.nukes > 0 and random() < .5):
targetCountry = players[randint(0,len(players)-1)]
while(targetCountry == country):
targetCountry = players[randint(0,len(players))]
targetCities = []
for (k, v) in targetCountry.cityDictionary.items():
targetCities.append(k)
targetCity = targetCountry.cityDictionary.get(targetCities[randint(0, len(targetCities))])
launchNuke(country, targetCountry, targetCity)