gpt4 book ai didi

algorithm - 基于花费时间和用户级别的排名算法

转载 作者:可可西里 更新时间:2023-11-01 11:22:20 24 4
gpt4 key购买 nike

想想一个游戏,玩家试图解决问题,每个问题实际上都意味着“级别”。

玩家在玩游戏时会看到实时排名。

RedisIO 具有排序集功能,我会使用它。

但是我不知道怎么给玩家打分:

PlayerA at 7 level, total game time 80  seconds
PlayerB at 7 level, total game time 65 seconds
PlayerC at 5 level, total game time 40 seconds
PlayerD at 1 level, total game time 200 seconds

我想要的排名就是这样

1) PlayerB - because level 7 and 65  seconds
2) PlayerA - because level 7 and 80 seconds
3) PlayerC - because level 5 and 40 seconds
4) PlayerD - because level 1 and 200 seconds

我试过了

(timeSpent/level)

计算,但当某人的水平较低且花费的时间比其他玩家少时,计算效果不佳。

最佳答案

简答:你可以有以下功能:

score = (level * HUGE_NUMBER) - timeSpent

对于 HUGE_NUMBER,您可以选择一个略大于完成一个级别所允许的最大时间的值。

虽然这对大多数情况来说可能就足够了,但我宁愿使用排序来解决这个问题,以避免排名算法中任何潜在的看不见的错误。

假设玩家的 level 是排名的主导因素,我会按 level 降序排列所有玩家。这可能会给您类似的结果(请注意,这还不是最终排名):

1) PlayerA - because level 7 and 80  seconds
2) PlayerB - because level 7 and 65 seconds
3) PlayerC - because level 5 and 40 seconds
4) PlayerD - because level 1 and 200 seconds

然后,我将在每个 level 中创建玩家子列表,并按 time 升序对它们进行排序。在上面的例子中,第二次排序会给你最终的正确排名。

1) PlayerB - because level 7 and 65  seconds
2) PlayerA - because level 7 and 80 seconds
3) PlayerC - because level 5 and 40 seconds
4) PlayerD - because level 1 and 200 seconds

关于algorithm - 基于花费时间和用户级别的排名算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19954883/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com