1
\$\begingroup\$

My workerclass has physical attributes such as physical_fitness and sexual_fitness which are intended to be functions of their age (the attribute is, unsurprisingly, called age). When the class is initialized, the initial values of XYZ_fitness are computed by a randomized normal distribution.

In each game tick, worker's grow a year older. I want to appreciate/depreciate the values of their physical attributes such that, for example, they increase until they are at their maximum value around age 35, and decline with age after that. What is an efficient way of defining this function?

Would this involve something like running their age through a quadratic function with its maxima at the age value 35? I'm sure there's some elegant math/statistics here that's escaping me.

\$\endgroup\$
1
\$\begingroup\$

I would suggest that you do NOT try to create a mathematical formula for this, since you will sooner or later find that the curve needs special shapes - it will be very tricky to achieve these with an f(age).

Instead write the value pairs in a table and linearly interpolate between two age values and grab the corresponding other value. If you have for example only 10 rows, for ages 0...90 years, with 10 year intervals (ie. age in column 1 and for example strength in column 2), the curve will have a bit of sharpness, but otoh it is easy to insert more points AND you can use for example Newton interpolation (C code sample) to smooth between the points; this will create the nice roundness you'd get when drawing between the points with a pen, by hand.

It is easy to create and adhoc-view a suitable table in Excel or OpenOffice, then copy/paste it. Or simply write it into a .txt file.

Above all, you'll open for further development and maintenance this way. Doing it with some polynomial formulas seems to me like harakiri.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.