更新分数的代码无法正常工作

时间:2018-12-23 19:31:46

标签: python python-3.x

我的代码工作正常,甚至可以玩游戏;但是,游戏中的比分并没有更新,似乎我的节拍功能有问题,我无法弄清楚。.

请参阅下面的完整代码

const movies=[{title:"Movie A",genre:["Action","Sci-Fi","Thriller"]},{title:"Movie B",genre:["Horror","Sci-Fi"]},{title:"Movie C",genre:["Action","Horror","Thriller"]},{title:"Movie D",genre:["Mystery","Horror","Sci-Fi"]}];

const final = movies
              .map(a => a.genre)
              .flat()
              .sort()
              .reduce((a, label) =>
                ((a[label] = a[label] || {label, count: 0})["count"]++,a), {});

console.log(Object.values(final));

2 个答案:

答案 0 :(得分:2)

请注意,beats(move1, move2)函数始终返回字符串,而不是布尔值。此外,在Game.play_round中,您可以省略is True位。只是if <condition>有用。

答案 1 :(得分:0)

我会在您的states函数中引入一些beats()(平局,人类获胜,Bot(?)获胜):

RESULT_HUMAN_WIN = 0
RESULT_RANDOM_WIN = 1
RESULT_TIE = 2

def beats(move1, move2):
    if move1 == move2:
        return RESULT_TIE

    elif ((move1 == 'rock' and move2 == 'scissors') or
          (move1 == 'scissors' and move2 == 'paper') or
          (move1 == 'paper' and move2 == 'rock')):
        return RESULT_HUMAN_WIN
    else:
        return RESULT_RANDOM_WIN

同时在play_round函数中将比较器切换为使用新的states来确定放置点的位置:

match_result = beats(move1, move2)

if match_result == RESULT_TIE:
    print("it's a tie!")
elif match_result == RESULT_HUMAN_WIN:
        self.player1_score += 1
elif match_result ==  RESULT_RANDOM_WIN:
        self.player2_score += 1