0

This is more an abstract "How would I approach this" question than me struggling with coding. I want to make a character creation screen where you have 0 points but can take away from one stat and put it into another. How, under this system would you randomise stats. I have base stats and the max deviation but I don't know how to got about randomising the stats so it makes specialized characters. They're not all going to be 150% in one and 75% in the other two stats but I think gentle specialization, probably with some form of weighted randomizer, would be nice. Feel free to respond with pseudo code or just an explanation of how you would do it. :D

1 Answers1

0

Here's my solution in 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)