条件是正确的,类仍然没有附加/删除Python

2024-09-30 18:34:48 发布

您现在位置:Python中文网/ 问答频道 /正文

当我遇到这个问题时,我正在编写我自己版本的幸运9(每个玩家得到2张牌,并且被问到他们是否想要另一张,他们的分数相当于(值的总和)%10)。 每个玩家只有在有足够的钱下注的情况下才能继续下注,如果他们没有足够的钱,他们将从游戏的活跃玩家列表self.playing中的class game()移动到self.playable。但是,即使要移动的条件得到满足,也不是所有类都能正确处理。你知道吗

这就是我遇到问题的地方:

self.observer.notifyListeners(self.playing, self.deck.cards, self) '''yeah, i used an observer design pattern'''

然后重定向到此部分:

def notifyListeners(self, x, kards, system):
            #These are all in an observer class and I pass class game as "system" as the parameter
    x.sort(key = lambda x: x.points)
    for y in x:
        print y.name, y.points
        for z in y.cards:
            self.pastcards.append(z)
        y.cards = []

    winners = []
    winners.append(x[len(x)-1])
    for y in x:
        if y.points == winners[0].points and y is not x[len(x)-1]:
            winners.append(y)

    self.money = self.money/len(winners)

    for y in winners:
        y.handlemove(self.money)
        print y.name, " wins."

    for y in x:
        if y.name == "Streaky" and y not in winnders:
            y.wins = 0
        else:
            pass


    for y in x:
        print y.name, ": ", y.money

    print len(self.pastcards)
    print "Cards left: ", len(kards)

    for y in x:
        if y.money < 100:
            y.isEligible = False

    for y in x:
        if y.isEligible == False:
            system.playable.append(y)
            self.removelisteners(y)
            system.playing.remove(y)

            for y in x:
                    print y.name, y.money

我把它们打印出来,这样我就可以看到剩下的是谁了,但有时,有100英镑的球员仍然是名单的一部分。有点把我拖到这里。任何帮助都将不胜感激。你知道吗

谢谢。你知道吗


Tags: nameinselfforlenif玩家system