I have a function which should work, and it actually does... just not all the time. Sometimes it just freezes. Can anyone identify a problem in the ai_northAmericaCheck(): function?
Here is the code:
import random
ai_countries = []
firstTurnsCountries = []
northAmericaList = [0,1,2,3,4,5,6,7,8,9]
availableCountries = range(20)
country0value = 1 # <--- Variables used to store army counts for countries
country1value = 1
country2value = 1
country3value = 1
country4value = 1
country5value = 1
country6value = 1
country7value = 1
country8value = 1
country9value = 1
country10value = 1
country11value = 1
country12value = 1
country13value = 1
country14value = 1
country15value = 1
country16value = 1
country17value = 1
country18value = 1
country19value = 1
# Below: List that provides easy access to above variables
countryVariableList = [country0value, country1value, country2value,
country3value, country4value, country5value,
country6value, country7value, country8value,
country9value, country10value, country11value,
country12value, country13value, country14value,
country15value, country16value, country17value,
country18value, country19value]
attachedCountry0List = [1, 3] # Variables limit attacking and
attachedCountry1List = [0, 2, 3, 4] # fortifying to attached countries only
attachedCountry2List = [1, 4, 5, 13]
attachedCountry3List = [0, 1, 4, 6]
attachedCountry4List = [1, 2, 3, 5, 6, 7]
attachedCountry5List = [2, 4, 7]
attachedCountry6List = [3, 4, 7, 8]
attachedCountry7List = [4, 5, 6, 8]
attachedCountry8List = [6, 7, 9]
attachedCountry9List = [8, 10, 11]
attachedCountry10List = [9, 11, 12]
attachedCountry11List = [9, 10, 12]
attachedCountry12List = [10, 11]
attachedCountry13List = [2, 14, 15]
attachedCountry14List = [13, 15, 16, 19]
attachedCountry15List = [13, 14, 16, 17]
attachedCountry16List = [14, 15, 17, 18, 19]
attachedCountry17List = [15, 16, 18]
attachedCountry18List = [16, 17, 19]
attachedCountry19List = [14, 16, 18]
# Below: List that provides easy access to above lists
attachedCountryTotalList = [attachedCountry0List, attachedCountry1List,
attachedCountry2List, attachedCountry3List,
attachedCountry4List, attachedCountry5List,
attachedCountry6List, attachedCountry7List,
attachedCountry8List, attachedCountry9List,
attachedCountry10List, attachedCountry11List,
attachedCountry12List, attachedCountry13List,
attachedCountry14List, attachedCountry15List,
attachedCountry16List, attachedCountry17List,
attachedCountry18List, attachedCountry19List]
def countryDivider(countryNum):
while True:
if not availableCountries: # check if list is spent/empty
break
q = random.choice(availableCountries) # pick one available country
firstTurnsCountries.append(q) # add it to first list
availableCountries.remove(q) # remove it from the available list
q = random.choice(availableCountries) # repeat for second list
ai_countries.append(q)
availableCountries.remove(q)
firstTurnsCountries.sort()
ai_countries.sort()
def ai_northAmericaCheck():
counter = 0
global ai_countryToAddMen
northAmericaCheckDone = 2
while True:
if counter > len(northAmericaList):
ai_countryToAddMen = "none"
return ai_countryToAddMen
break
if northAmericaList[counter] in ai_countries:
counter2 = 0
while True:
if counter2 >= len(attachedCountryTotalList[counter]):
northAmericaCheckDone = 2
break
if attachedCountryTotalList[counter][counter2] in firstTurnsCountries:
ai_countryToAddMen = northAmericaList[counter]
northAmericaCheckDone = 1
break
if attachedCountryTotalList[counter][counter2] in ai_countries:
counter2 = counter2 + 1
if northAmericaCheckDone == 1:
return ai_countryToAddMen
break
if northAmericaList[counter] in firstTurnsCountries:
counter = counter + 1
countryDivider(9)
ai_northAmericaCheck()
print ai_countryToAddMen
reinforcements = 3
countryVariableList[ai_countryToAddMen] = countryVariableList[ai_countryToAddMen] + reinforcements
print countryVariableList[ai_countryToAddMen]
The game I'm working on is quite lengthy so I included only the parts that the function needs in order to run. Another problem though, is that instead of freezing only some of the time, like it does in this code example, it freezes 95% of the time in my game. So I figured I'd start with the function itself.
Thanks for everybody's time and help!