我的代码工作正常,甚至可以玩游戏;但是,游戏中的比分并没有更新,似乎我的节拍功能有问题,我无法弄清楚。.
请参阅下面的完整代码
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));
答案 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