问:使用积分系统随机创建角色



这更像是一个抽象的"我将如何处理这个问题"的问题,而不是我在编码上挣扎。我想制作一个角色创建屏幕,其中你有 0 分,但可以从一个统计数据中取出并将其放入另一个统计数据中。在这个系统下,你如何随机化统计数据。我有基本统计数据和最大偏差,但我不知道如何随机化统计数据,以便它成为专门的角色。它们不会在一个统计数据中达到 150%,在其他两个统计数据中达到 75%,但我认为温和的专业化,可能使用某种形式的加权随机化器,会很好。随意使用伪代码或只是解释您将如何做到这一点。:D

这是我

在python中的解决方案:

import random
from operator import add, sub
baseStats = {
"baseHealth":10.00,
"baseSpeed":10.00,
"baseAccuracy":10.00,
}
baseDeviation = 3
ops = (add, sub)
charStats = {}
#Make spread. Eg: If the deviation is 3 It'll be [0, 0, 0, 0, 1, 1, 1, 2, 2, 3]
#With the highest deviations being the rarest
spread = []
for i in range(1,baseDeviation+2):
    for j in range(1,baseDeviation+2-i):
        spread.append(i)
print(spread)
#Make a list of stats without the base values.
remainingStats = []
for key, value in baseStats.items():
    charStats[key] = value
    remainingStats.append(key)
#Choose a stat and add or subract a random choice from our weighted spread
op = random.choice(ops)
chosenOne = random.choice(remainingStats)
remainingStats.remove(chosenOne)
chosenNumber = random.choice(spread)
charStats[chosenOne] = op(charStats[chosenOne],chosenNumber)
spread.remove(chosenNumber)
#Work out the difference between the randomised stat and the standard then give
#it to one and leave the other be.
difference = baseStats[chosenOne] - charStats[chosenOne]
charStats[random.choice(remainingStats)] = charStats[random.choice(remainingStats)] + difference
print(charStats)

最新更新