我已经创建了一个数字猜谜游戏,用户可以选择一系列数字进行猜测,当用户输入数字时,如果程序太高或太低,程序将会响应,直到用户猜对了。该程序目前需要尝试的次数和时间。也存在不同的困难(难度越高,猜测的数字越多)。我试图创建一个评分系统,但我需要一些数学方面的帮助。现在我有这个代码生成一个分数:
def scorer(tries, total_time, difficulty):
# Tells the user how much time and how many attempts were made
print "\nCorrect! It took you " + str(round(total_time, 2)) + \
" seconds and " + str(tries) + " tries to guess.\n"
# Calculates score, making lower times and fewer
# tries yield a higher score
# Difmod takes into account the difficulty
# Multiply by 1000 to make number more readable
score = 1 / (1 + (tries * round(total_time, 2))) * 1000 * dif_mod(difficulty)[1]
# Prints the score, rounded to 1 decimal place
print "Score: " + str(round(score, 2))
tries
和total_time
不言自明,dif_mod
是我为了让得分更加公平而做出的价值。更高的困难。 dif_mod
的值越高,难度就越高。如下所示:
def dif_mod(difficulty):
if difficulty == 1:
return [10, 1]
elif difficulty == 2:
return [50, 1.5]
elif difficulty == 3:
return [100, 2]
elif difficulty == 4:
return [1000, 10]
elif difficulty == 5:
return [10000, 20]
elif difficulty == 0:
return [1, 1]
列表中的第一个值是要猜测的最高可能数,列表中的第二个项是dif_mod
。这些都是占位符值,我想弄清楚我应该为它们使用什么。
我的主要目标是根据较少的尝试次数和较少的时间来提高分数,但如果他们的难度较高,也会奖励得分较高的用户。