0

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

4

1 回答 1

0

这是我在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)
于 2016-04-26T19:51:06.457 回答