示例#1
0
def fillWins(pokeWins):
    for number1 in range(1, pokeListSize//2):
        fighter1=pokeList[number1]
        for number2 in range(pokeListSize//2, pokeListSize):
            fighter2 = pokeList[number2]
            if fighter1!=fighter2:
                winner=pf.battle(fighter1,fighter2,True,False)
                if winner==0:
                    pokeWins[number1][number2]=True
                elif winner==1:
                    pokeWins[number2][number1]=True
示例#2
0
def countScores(pokeScore):
    for number1 in range(1, pokeListSize//2):
        fighter1=pokeList[number1]
        for number2 in range(pokeListSize//2, pokeListSize):
            fighter2 = pokeList[number2]
            for i in range(5):
                if fighter1!=fighter2:
                    winner=pf.battle(fighter1,fighter2,True,False)
                    if winner==0:
                        pokeScore[fighter1.name] += 2
                    elif winner==1:
                        pokeScore[fighter2.name] += 2
                    #else:
                        #pokeScore[fighter1.name] += 1
                        #pokeScore[fighter2.name] += 1
    pokeScore = sorted(pokeScore.items(), key=operator.itemgetter(1))
    for i in range(1,12):
        print(pokeScore[pokeListSize-i])
示例#3
0
def countScores2(topLimit):
    pokeScore = {}
    for poke in range(pokeListSize):
        pokeScore[poke]=0
    for number1 in range(1, pokeListSize//2):
        fighter1=pokeList[number1]
        for number2 in range(pokeListSize//2, pokeListSize):
            fighter2 = pokeList[number2]
            for i in range(3):
                if fighter1!=fighter2:
                    winner=pf.battle(fighter1,fighter2,True,False)
                    if winner==0:
                        pokeScore[number1] += 1
                    elif winner==1:
                        pokeScore[number2] += 1
    pokeScore = sorted(pokeScore.items(), key=operator.itemgetter(1))
    topList = []
    for i in range(1,topLimit+1):
        topList.append(pokeScore[pokeListSize-i])
    return topList
示例#4
0
# Then, read all pokemon from a file and put them on a list (the types are not correctly updated)
pokeList = pf.readPokemonListFromFile("listOfPokemon2.txt")
#print "length of the list "+str(len(pokeList))+" "+str(pokeList)

#TASK A, put all pokemon in the list in a dictionary where the key is the name of the pokemon
pokedex = {}
# Put all pokemon in a dictionary by name
for monster in pokeList:
    pokedex[monster.name] = monster

#TASK B, put go over listOfNamesAndTypes, for every pokemon there, update its types, look for it in the pokedex dictionary and append the types to list pokedex[name].variety
for name, listOfTypes in listOfNamesAndTypes:
    #print "updating types for  "+name
    for t in listOfTypes:
        pokedex[name].variety.append(t)

#Did the monsters in list pokeList also get their names updated? Why?
print(pokedex["Bulbasaur"])
print(pokeList[0])

#now we can make monsters fight by doing:
#pf.battle(pokedex["Bulbasaur"],pokedex['Charmander'])
#or also
#pf.battle(pokeList[8],pokeList[137])

#random battle
fighter1 = random.randint(0, len(pokeList) - 1)
fighter2 = random.randint(0, len(pokeList) - 1)
winner = pf.battle(pokeList[fighter1], pokeList[fighter2], True)
示例#5
0
for monster in pokeList:
    pokedex[monster.name] = monster

#print(pokedex)

# Task B, using the two dictionaries that you now have, pokedex and dictionaryOfNamesAndTypes,
# modifiy the entries in pokedex to include types
pokeTypes = {}
for key, value in pokedex.items():
    currentList = dictionaryOfNamesAndTypes[key]
    for type in currentList:
        value.variety.append(type)

#print("\n\n\n\n"+str(pokedex))

#now we can make monsters fight by doing:
#pf.battle(pokedex["Bulbasaur"],pokedex['Charmander'])
#or also
#pf.battle(pokeList[8],pokeList[137])

#random battle
fighter1 = pokeList[random.randint(0, len(pokeList) - 1)]
fighter2 = pokeList[random.randint(0, len(pokeList) - 1)]

winner = pf.battle(fighter1, fighter2, False, False)
if winner == 0: print(" The pokemon that won the battle was: " + fighter1.name)
elif winner == 1:
    print(" The pokemon that won the battle was: " + fighter2.name)
else:
    print("The battle ended in a draw! ")