Wednesday, December 5, 2018

Pseudobot - Math and Graphs; How Fair is the Random Stat Generator?

So, last week, and the week before I worked on a tool to randomly generate character attributes in a way that the results would all have the same point values. At first, the algorithm assumed a character would have no decreased attributes and secondary characteristics, which was not satisfying to me, so I adjusted it so that the character could have minimum values based on some numbers I extrapolated from various GURPS sources as the bare minimum ok amount for a character. I think this was a good improvement. However, after making a naive implementation of the algorithm that gave each attribute or secondary characteristic an equal chance of occurring, on a whim, I decided to generate several thousand characters to see what the expected outcomes would be like. The result was that certain things apparently had certain unfair advantages in selecting them that made it so that certain attributes had noticeably lower or higher averages, thus began a complicated process of trying to make the algorithm as balanced as possible.

Basic Algorithm

To give some context, here is the simple naive algorithm, somewhat analogized to make it easier to understand and less technical:
  1. Take a character with attributes and secondary characteristics lowered to the bare "viable" minimum, give them back points for doing this.
  2. In a loop, spend points until we run out doing the following
    1. Taking the ratios of current traits into account, put all the traits that are valid for purchase into a hat.
    2. Choose one from the bag at random.
    3. Give +1 (or +0.25 for basic speed) to that trait, and subtract the point cost from our budget
  3. Return the character

Weighing Results

A few things gave some results different advantages and disadvantages that made them easier to select.
  • Some characteristics have a lower "allowed" minimum than others.
  • Probability of incrementing any
    particular characteristic.
    • For example, Strength can be as low as 10-3; that's 3 decrements; but Basic Speed can go as low as (HT+DX/4)-2.00; that's 8 decrements.
  • Some characteristics are bounded by one or more dependent characteristics.
    • HP should be between 0.7x and 1.3x of ST
    • Will and Per have a lower bound of 70% of IQ
    • Basic Move can be ⌊Basic Speed⌋±3
  • Some characteristics have very different costs. 
    • This causes a problem because traits that have a lower cost, when the remaining point budget gets low enough, get "extra rolls" that the more expensive traits don't get. For example, If there are 10 points left to spend, there is a chance to acquire more increments of Basic Speed, but zero chance to acquire more increments of DX.
    • This also means the range of possible values for cheaper attributes can be potentially higher than for more expensive values.

Reducing Components

After doing some testing, it seemed that having attributes and secondary characteristics reduced as much as possible helped to keep secondary characteristics from hitting the allowed ceiling. By this, I mean that, one can think of a level of HT, for example as also including a free level of FP and Basic Speed. If I added these traits when buying a level of HT, that's like giving FP and Basic Speed a bunch of extra chances of being rolled, which meant that changing the weighted odds of getting higher HT could cause a "butterfly effect" that could cause FP and Basic Speed to increase by a lot, which took away opportunities to buy other things, causing a lot of other attributes and secondary characteristics to lose out, relatively speaking.
The one slightly complicated secondary attribute in the bunch because of all of this was Basic Move, which normally gets a free increment every time Basic Speed x 4 % 4 = 0. I had to hack the algorithm slightly because I couldn't subtract 1/4 of the cost of Basic Move from each level of Basic Speed; I just made it so that every time Basic Speed did hit an even number, it would give back 5 points and decrement Basic Move by 1.

Isn't Weighing Results Cheating?

I got this question while thinking out loud about the problem. If you give favor to one result, is it still really fair or random? Well, obviously, yes, it's still random. The fact of the matter is that some traits have certain properties that give them more opportunities for rolls. By giving the attributes and secondary characteristics a higher probability of being rolled when the opportunity lines up, it makes up for the times when they have absolutely zero opportunity for incrementing.

The "Bare Minimum Viable Character"

The bare minimum viable 0 point character has the following stats:
  • All 4 Attributes are at 7; this gives 180 points worth of disadvantages.
  • Secondary Characteristics
    • HP, FP, Will, and Per are allowed to be 70% of their primary attribute; this means an effective 5 when the controlling attribute is at 7; two decrements each gives 30 points worth of disadvantages.
    • Basic Speed has a minimum adjustment of -2.00; this is 8 decrements for 40 points.
    • Basic Move is already at the floor; HT, DX, and Basic Speed are so low, Basic Move is already 1, so we make no changes for 0 points.
Summing all of this up, a zero point character has 250 points floating to reallocate. In any case, Let's take a look at the results in more detail.

The Results

I generated 20,000 random characters with 0 points, assuming that a balanced generator would have all the attributes balanced around 10, and all the secondary characteristics balanced around 5. 

Attributes

Boxplot of 20,000 zero point
characters
The attributes all have similar patterns, so I've only included the histogram for IQ. I never did really well at statistics, but after looking through Wikipedia, I think the histograms conform to a stochastic model referred to as a "counting process." A counting process is where a random number is generated from counting the number of "successes" produced by generating a different random number. To use the IQ histogram as an example, we have 3.7k examples where we counted 0 successes (7 IQ). 4.7k examples with 1 success (8 IQ) 4.8k where we have 2 successes (9 IQ); and 3.6k where we have 3 successes (10 IQ.) An interesting property of this is that even though the median is close to 10 (9.9435 to be exact) the mode is 9. I think the distribution is similar to a Poisson distribution, but slightly different. Looking at the conditions to be considered a poisson distribution, these conditions are met:
  • The values are discrete counts
  • Events occur independently
  • The event can't occur simultaneously
  • Histogram of IQ Values
  • The probability of a success is determined by a binomial distribution
The one typical property of a poisson distribution that is violated is that the rate is not necessarily constant. If, for example, Will and Per are too low, the occurrence of IQ increments drops to 0. If Basic Speed is low enough, the odds of DX or HT incrementing is 0, and this increases the odds of IQ incrementing. Also, I am not sure if this is absolutely required, but I think the counting process needs to occur over a continuous interval; the interval is a discrete set of loops where something increases or it doesn't. Correct me if I'm wrong here though.

Perception

Perception Histogram
Perception and Will have the interesting designation that they have no cap in proportion to any other attribute or characteristic, and their histograms are similar. Highly unlikely, but because they have no maximum capping, this means that a random character could potentially spend all the points on either or both without any other limits. This gives them a longer tail than any other characteristic in the generator. As a secondary attribute that starts relatively low, it also has a higher variance and standard distribution, which you can see by the way it takes much longer to reach the "peak" of the distribution than it did for IQ above.

Hit Points

HP Histogram
Hit points have a relative upper and lower bound compared to ST. HP must be in the range of ST ±30%. Fatigue has a similar but different shape because it is bound by HT, but decomposed HT! very cheap and also depends on Basic Speed, which depends on Basic Move. These interact subtly with the entire graph, but give an overall similar shape. If we don't look at the graph very carefully, it might seem like this is almost a normal or binomial distribution, but it does have a very heavy tail at the end again.

Basic Speed

Basic Speed Histogram
This is the last "interesting" graph in my opinion because of the high relative variance and the extremely low initial value, and the dependence on all of HT, DX, and Basic Move. It is deceptively similar to a bell curve at this point, but there is no mistaking that the right half of the graph is "heavier" than the left side of the graph.




Other Thoughts and Conclusion

I got permission from the guy who wrote Libre Solo Role Playing to write an app that is similar to the GM emulator in the book. I think I'll use this as a stepping stone to produce the framework for an MVC website that I can eventually add the Pseudobot functionality to. I think I'll also be keeping this project mostly open source because Brian seemed a little more forgiving in what I can and can't do with the app than Steve Jackson Games. Basically, as long as I don't wholesale copy text from the book, and don't say that my implementation is literally equal to his book, I'm free to do whatever, so hooray.

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...