2017-05-25 7 views
-4

現在、Zelda Breath of the Wild種のみを実行しているAkinatorのようなゲームを作っています。何らかの理由で、私がcoocooに関するすべての情報を入力すると、出力はGerudoになります。助けてください。ここでは、コードです:あなたはそれを反復している間、リストから項目をポップリストからのものを正しく削除する

class Thing(): # The general class for a object 
    def __init__(self, area, race, ally, living, extra): 
    self.area = area 
    self.race = race 
    self.ally = ally 
    self.living = living 
    self.extra = extra 
class Guess(): # The class for the guess 
    def __init__(self): 
    self.area = None 
    self.race = None 
    self.ally = bool 
    self.living = bool 
    self.extra = str 
talus = Thing("everywhere", "talus", False, True, " rocky") 
coocoo = Thing("everywhere", "coocoo", True, True, " a fierce, chicken-like friend") 
zora = Thing("in the zora area", "zora", True, True, " swimming") 
rito = Thing("in the rito area", "rito", True, True, " flying") 
goron = Thing("in the goron area", "goron", True, True, " rolling") 
gerudo = Thing("in the gerudo area", "gerudo", True, True, " a women") 
hylean = Thing("everywhere", "hylean", True, True, " good and bad") 
guardian = Thing("everywhere", "guardian", False, False, " mechanical") 
moblin = Thing("everywhere", "moblin", False, True, " related to the bokoblin") 
staloblin = Thing("everywhere", "staloblin", False, False, " a large undead enemy") 
bokoblin = Thing("everywhere", "bokoblin", False, True, " a basic enemy") 
stalkoblin = Thing("everywhere", "stalkoblin", False, False, " a basic undead enemy") 
lynel = Thing("everywhere", "lynel", False, True, " a horse-like beast") 
octorok = Thing("everywhere", "octorok", False, True, " a rock-shooting monster") 
lizafos = Thing("everywhere", "lizafos", False, True, " a scaley, speeding, baddie") 
stalzafos = Thing("everywhere", "stalzafos", False, False, " a fast, skeletal enemy") 
spirit = Thing("everywhere", "spirit", True, False, " a helpful ghost") 
def akinator(): 
    everything = [talus, zora, rito, goron, gerudo, hylean, guardian, moblin, stalkoblin, staloblin, bokoblin, lynel, octorok, lizafos, stalzafos, spirit, coocoo] 
    possible_areas = ["everywhere", "in the zora area", "in the rito area", "in the goron area", "in the gerudo area", "in the hylean greenlands"] 
    guess = Guess() 
    alive = input("Is it alive? y/n ") 
    if alive == "n": 
    guess.living = False 
    elif alive == "y": 
    guess.living = True 
    for i in everything: 
     if i.living != guess.living: 
      everything.pop(everything.index(i)) 
    ally = input("Is it one of your allies? y/n ") 
    if ally == "n": 
    guess.ally = False 
    elif ally == "y": 
    guess.ally = True 
    for i in everything: 
     if i.ally != guess.ally: 
      everything.pop(everything.index(i)) 
    for i in possible_areas: 
     area = input("Do they live " + i + "? y/n ") 
     if area == "y": 
      guess.area = i 
      break 
    for i in everything: 
     if i.area != guess.area: 
      everything.pop(everything.index(i)) 
    for i in everything: 
     extra = input("Is it" + i.extra + "? y/n ") 
     if extra == "n": 
     everything.pop(everything.index(i)) 
     if extra == "y": 
     print("Is it a "+ i.race +"?") 
     quit() 
    print("Is it a "+everything[0].race+"?") 

akinator() 
+0

? –

+0

あなたの入力と出力を表示することができます – Ouss

+0

この[how-to-ask](http://stackoverflow.com/help/how-to-ask)を読んでガイドラインに従ってください。あなたの問題を記述し、再現してください。 – thewaywewere

答えて

1

は悪い考えである - それはあなたのリストのイテレータをアップファウル、あなたは、次の項目のテストをスキップします。代わりに

for i in everything: 
    if i.living != guess.living: 
     everything.pop(everything.index(i)) # <- BAD 

してみてくださいあなたは出力になりたいん何

everything = [i for i in everything if i.living == guess.living] 
+0

それはうまくいった。ありがとう –

関連する問題