-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPassiveAgent.py
37 lines (30 loc) · 1.17 KB
/
PassiveAgent.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
import ctypes
from Agent import *
import threading
class PassiveAgent(Agent):
# This agent places all of its bonus armies to the territory with the fewest armies, and doesn’t make any attacks.
def takeTurn(self):
country = self.chooseCountryToAddTroops()
if country is None:
ctypes.windll.user32.MessageBoxW(0, "NO MORE ATTACKS", "ALERT", 1)
return
use_timer=False
if use_timer:
old_num=country.numOfTroops
t = threading.Timer(1, self.setTroopsBonus,args=(country,old_num,self.calcBonusTroops()))
t.start()
country.numOfTroops = str(country.numOfTroops) + "B"
else:
amount = self.calcBonusTroops()
country.numOfTroops = country.numOfTroops + amount
# choose the country with minimum troops
def chooseCountryToAddTroops(self):
country = None
mintroops = 10e6
for c in self.countries:
if c.numOfTroops < mintroops:
country = c
mintroops = c.numOfTroops
return country
def setTroopsBonus(self,country,old_num,amount):
country.numOfTroops=old_num+amount