Sign in to follow this  
Sindusk

The Gaussian Roll - Mathematical Analysis

Recommended Posts

Introduction

 

The Gaussian roll governs a gigantic amount of systems in Wurm. This method is called in almost every facet of gameplay. From mining ore QL, to the power of enchants you cast, to chance to parry, to your ability to continue an unfinished item, this method determines your chance to succeed and by what margin you succeed by. When you mine an ore, the resulting QL is determined by the result of this method. When you cast a spell, the power of the enchant or effect is the result of this method. When you improve an item, the amount you improve by is the result of this method, and fails if the result is less than zero. It's not farfetched to call this the backbone of functionality in Wurm, and yet it doesn't seem to be understood or analyzed anywhere. For that purpose, I'm sharing now an analysis from a mathematician of Wurm's Gaussian Roll.

 

Wikipedia: Gaussian Function

 

The Method

    public static final float rollGaussian(float skill, float difficulty, long parentId, String name) {
        float slide = (skill * skill * skill - difficulty * difficulty * difficulty) / 50000.0f + (skill - difficulty);
        float w = 30.0f - Math.abs(skill - difficulty) / 4.0f;
        int attempts = 0;
        float result = 0.0f;
        do {
            result = (float)random.nextGaussian() * (w + Math.abs(slide) / 6.0f) + slide;
            float rejectCutoff = (float)random.nextGaussian() * (w - Math.abs(slide) / 6.0f) + slide;
            if (slide > 0.0f) {
                if (result > rejectCutoff + Math.max(100.0f - slide, 0.0f)) {
                    result = -1000.0f;
                }
            } else if (result < rejectCutoff - Math.max(100.0f + slide, 0.0f)) {
                result = -1000.0f;
            }
            if (++attempts != 100) continue;
            if (result > 100.0f) {
                return 90.0f + Server.rand.nextFloat() * 5.0f;
            }
            if (result >= -100.0f) continue;
            return -90.0f - Server.rand.nextFloat() * 5.0f;
        } while (result < -100.0f || result > 100.0f);
        return result;
    }

Mathematical Analysis


Say skill==difficulty first, then slide==0, w==30.
Thus both result and rejectCutoff are Gaussian with standard deviation 30 and mean 0.
We reject result in case result<rejectCutoff-100, which has a probability of between 0.9% and 1%, using the following theorem.
    Theorem: Let X and Y be independent normal, with means μ and ν, and variances σ2 and τ2 respectively. 
    Let W=X−Y. Then W is normally distributed, with mean μ−ν, and variance σ2+τ2.
(Note that rejectCutoff-100 is Gaussian with mean -100 and standard deviation 30, so we are looking for the probability that
rejectCutoff-100-result>0, which is a Gaussian with mean -100 and variance 1800, standard deviation 30sqrt(2).  The probability
that a Gaussian variable is 2.357 standard deviations above the mean is between 0.9% and 1%.)

 

In the second portion, if the result is above 100 or below -100, it is truncated to +- 90 with some extra random thrown in.  this only
happens between 0.9% and 1% of the time each (with the standard deviation and means used).  We should note that the chance of getting 
anything between 90 and 100 is only 0.7%, so truncating everything above 100 down to 100 in this case would make good rolls too likely.

 

We consider several more examples.
Say skill==50, difficulty==40, then slide==11.22, w==27.50.
result has mean 11.22 and standard deviation 29.37
rejectCutoff has mean 11.22 and standard deviation 25.63
we reject if the Gaussian variable result-rejectCutoff-88.88>0
rejectCutoff-88.88-result has mean -88.88 and standard deviation 38.98
and so we reject 1.13% of the time.

 

Big Picture Analysis


We attempt to give some big picture analysis of what this method does.  If your skill is well below the difficulty of the task,
then you will have a below-average mean, and a standard deviation which well below 30, which will make it difficult to overcome the
low mean, even on a particularly good roll.  As your skill increases towards the difficulty, your mean shifts towards 0, and the standard 
deviation increases towards 30, allowing for more variation in rolls and approximately 50-50 behaviour in successes and failures.  As your skill 
surpasses the difficulty, the mean of your rolls increases above 0, and the standard deviation begins decreasing, so you an expect better averages, and with less variation.
As your skill increases further, the standard deviation eventually begins increasing up to a maximum of 30.0715 with skill==100 and difficulty==91.2879.  

 

To see a plot of how the standard deviation changes (x is skill, a is difficulty), query WolframAlpha with the following:
plot 30-abs(x-a)/4+abs( (x^3-a^3)/50000+(x-a))/6 where a=50, 0<x<100

 

To see a plot of how the mean changes, query Wolframalpha with the following:
plot (x^3-a^3)/50000+(x-a) where a=50, 0<x<100

 

The rejection cutoff seems completely arbitrary and useless, considering how the method handles results above 100 or below -100.
It is probably meant to prevent, for example, extremely low skill allowing for extremely high results.
Essentially getting two Gaussians with essentially the same mean and standard deviation and making sure they aren't too far apart.
It happens infrequently enough that it probably isn't worth changing, even for performance.

 

As far as the removal of results above 100 and below -100, it seems like a reasonable way to handle that extra 2% of cases without just saying they're all -100 or 100,
since the probability of getting something between 90 and 100 could be quite a bit lower than the probability of getting something above 100, we don't want to throw all the extra weight onto 100.
Unfortunately, this leads to a situation in which a skill of some number less than 100 is better than a skill of level 100 for skill checks.

Edited by Sindusk
  • Like 7

Share this post


Link to post
Share on other sites
5 minutes ago, Sindusk said:

 

Unfortunately, this leads to a situation in which a skill of some number less than 100 is better than a skill of level 100 for skill checks.

?

Share this post


Link to post
Share on other sites

^ dat.

 

'official proof' that sometimes being at 95+ skills sucks for success rate... and maybe, just maybe, something could be done to prevent all that 'fake' randomness making things harder to achieve than they should be.

  • Like 1

Share this post


Link to post
Share on other sites

In my opinion, the quickest fix for the stated issues at near-100 skill would be:

 

When re-rolling a roll that goes over 100, just weight that second roll significantly higher in value than it otherwise would be. Maybe even guarantee a result greater than 0.

 

This way, you'd still get consistently higher results, but without getting a bunch of 100s.

 

 

Of course, a more fundamental solution to the problem would probably be better, but as a quick and dirty stopgap, it could work.

Share this post


Link to post
Share on other sites

Thanks, Sindusk! Now I can hate RNG in detail. :)

 

Seriously, I'd like to see the RNG generally tightened, to produce fewer outliers (and in some cases, removed outright, such as creation/imping failure).

  • Like 1

Share this post


Link to post
Share on other sites

Cool. So now instead of putting the blame on Wogic, I can blame this. Thanks. :)

Edited by Benie

Share this post


Link to post
Share on other sites

Geeze, you mathmetologists! Always my worst subject in school, so very long ago. I find it more than sufficient that others can understand these quantifanatical fantasmorgisms and align them into somewhat of an applicable basis to make the game function in a playable manner without myself needing the least understanding nor interest in deciphering the pure yet somewhat unpredictable results. 2+2 will do for a few, where less equals nevermore (quoth the raven).

 

=Ayes=

Share this post


Link to post
Share on other sites

Understanding this is one step closer to having a tool to lookup skill gain chance. It doesn't matter so much for WU  as for it basically, any success is a skill gain.

Now for WO it's more important because of the 0 to 40 skill gain mechanic. Using Syn's logic above you can make a calculator for finding whatever combination of character skill, tool quality, and difficulty will put the mean at 20. 20 mean is the optimal point or the halfway point between 0 and 40.

 

Another fun thing to take form this is that the rune which buffs skill bonus is a joke.

 

I also don't see the point in rerolling for outside 100 and -100. Quality is capped between 0 and 100, skill gain is 0 to 40. why does it matter if a person with 99 skill, use a 99ql tool does some 1 difficulty task. Further, this example done  100 tries should on average result in 40 to 50 of 100 plus rolls. The failure rate is a ridiculously low number like 1 in a million?  I thought the point of using gaussian was to try and mimic real-life probability? I'm not sure why wurm didn't realize as soon as your start rerolling results it breaks the model.

 

Here is a picture of a google sheet tool I made.

Spoiler

fqaY5hb.png

 

 

 

Share this post


Link to post
Share on other sites

Skill roll calculators (and more) exist already, but those who made them don't really want them to be shared publicly, for reasons I can't entirely fathom.

Share this post


Link to post
Share on other sites

A nicely formatted and nonmath mumbo-jumbo version doesn't exist in-game, and that is something really hope gets added someday (no I'm not making a suggestion, no point in my asking Wurm devs for anything).

I'd be willing to share mine but I'd have to find a good way to do it as letting hundreds of people mess with my google sheet doesn't work well...guess I could make a copy of it, locke it up, and post a like so folks can download it.

 

Share this post


Link to post
Share on other sites

If it's a copy, you can just restrict some areas and let others try to make it better.

Share this post


Link to post
Share on other sites

This is interesting, however I think we should know that this modifier works hand in hand with items as well. It's been widely reported that using gather runes/rares and harvesting things that are 100ql and crafting with them makes crafting difficult. The rolls seem to be floating in the 50s for creation off 100ql items and improving fails more than it succeeds at high qualities with these items as well. This seems like an oversight in the mathematics of the game and really should be altered.

Share this post


Link to post
Share on other sites

quick question about this. From what I can tell the behavior of bounding the rolls to -100 < x < 100 causes distributions that aren't normal. I was hoping to do probability density functions but i"m not sure if they apply when I can't verify the distribution fits a normal curve.

 

If this is the case isn't the best way to do a skill gain style calculator to just call the gaussian roll method seen in WU a bunch of time and count the frequency of roll where 0 < x <= 40?

Edited by joedobo

Share this post


Link to post
Share on other sites

Honestly, the best way to do a skill gain/skill roll calculator is the way it's been done before: By essentially running the same algorithm that Wurm does, a significant number of times, and plotting the results.

Share this post


Link to post
Share on other sites

Do we really need to plot them? Wouldn't it be just as good to count the number of outcomes that are in the sweet spot?

 

for 99 skill and 10 difficulty and ran through the same code WU uses.

 

plot:

sZyQXTim.png

 

numeric:

skill gain tick chance: 0.011323

 

Edited by joedobo

Share this post


Link to post
Share on other sites
4 minutes ago, joedobo said:

Do we really need to plot them? Wouldn't it be just as good to count the number of outcomes that are in the sweet spot?

 

Yes, because you might want to know more than just skill gain chance. You might also want to know the chance of a successful result in general, or results over 90%, or any number of things.

Share this post


Link to post
Share on other sites

My -feeling- is that passing 70 skill level on Forestry I fail pruning significantly more often than at lower skills. I wonder if that is my perception only, a reason of the above math or another falw in the skillcheck code?

Edited by Jaz

Share this post


Link to post
Share on other sites
3 minutes ago, Jaz said:

My -feeling- is that passing 70 skill level on Forestry I fail pruning significantly more often than at lower skills. I wonder if that is my perception only, a reason of the above math or another falw in the skillcheck code?

 

Some actions, including pruning, have difficulty that actually scales up with your skill. This can result in lower success rate at higher skill, especially if your tools don't improve along with your skill.

Share this post


Link to post
Share on other sites
4 minutes ago, Jaz said:

My -feeling- is that passing 70 skill level on Forestry I fail pruning significantly more often than at lower skills. I wonder if that is my perception only, a reason of the above math or another falw in the skillcheck code?

[2018-06-12] [17:56:04] You make a lot of errors and need to take a break.
[2018-06-12] [17:56:10] You make a lot of errors and need to take a break.
[2018-06-12] [17:56:16] You make a lot of errors and need to take a break.
[2018-06-12] [17:56:21] You make a lot of errors and need to take a break.

 

That's a fairly common occurrence for me, it's stupid.

  • Like 2

Share this post


Link to post
Share on other sites

Just verified that, at least in Wurm Unlimited, pruning a tree has a difficulty of (skill - 10).

 

Let's say you're using a 90QL tool at 20 skill and 80 skill. A difficulty 10 action with a 90QL tool and 20 skill is definitely going to have better success rates than a difficulty 70 action with 80 skill and a 90QL tool.

  • Like 2

Share this post


Link to post
Share on other sites
6 minutes ago, Oblivionnreaver said:

[2018-06-12] [17:56:04] You make a lot of errors and need to take a break.
[2018-06-12] [17:56:10] You make a lot of errors and need to take a break.
[2018-06-12] [17:56:16] You make a lot of errors and need to take a break.
[2018-06-12] [17:56:21] You make a lot of errors and need to take a break.

 

That's a fairly common occurrence for me, it's stupid.

 

Same here,  same old 90ql tool as before, so it seems the difficulty scales steeper than the skill?

EDIT: yes so it is sounds like a not fully thought over skillcheck here...

EDIT2: for pruning I can live with it - but how many other areas may exist with the same wogic?

Edited by Jaz

Share this post


Link to post
Share on other sites

 

36 minutes ago, Jaz said:

 

EDIT2: for pruning I can live with it - but how many other areas may exist with the same wogic?

2

This is the perfect example of why I wanted to avoid plotting things. It's just extra info that confuses people. I think we need a tool that isn't something that appears math-heavy or complicated WU code mining.


Oh, and to further complicate with forestry-related stuff is that skill bonus for this area is huge. For most things skill bonus of 10 would be very lucky. With forestry, and if you got a high sickle skill, one could easily cap the bonus at 70.

 

In general, as far I can tell anyway, assuming your sickle skill is about equal to your forestry skill you'd want a sickle that is 5 ql points less then forestry skill. (1 difficulty and sickle skill roll will about come out on average to a power equal to the sickle skill. So if your sickle skill is equal to forestry then the bonus should equal foresty on average and it's hard capped at 70.)

Share this post


Link to post
Share on other sites
4 hours ago, Oblivionnreaver said:

[2018-06-12] [17:56:04] You make a lot of errors and need to take a break.
[2018-06-12] [17:56:10] You make a lot of errors and need to take a break.
[2018-06-12] [17:56:16] You make a lot of errors and need to take a break.
[2018-06-12] [17:56:21] You make a lot of errors and need to take a break.

 

That's a fairly common occurrence for me, it's stupid.

 

94 forestry, 92ql sickle and I spam prune 3x and more often than naught you can get 3 fails, it is silly how this happens, one would think at these skills you should never have to tap the prune key more than once to prune a tree

Share this post


Link to post
Share on other sites

94 forestry and 92 ql sickle nets out to about 95 skill and 84 difficulties (you're likely seeing a 70 skill bonus on average).

That would make something like this: skill gain(0-40): %49.9E0, failure(<0): %29.8E0, 90+: %26E-2

 

Seems like it's working exactly as it was intended. Although, I think I get where folks are complaining. Wurm wanted to try a different skill function to make it easier to skill up but unfortunately, they also made it near impossible to get 100% success at high levels.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this