XCOM 2
Nice DropShip (De)Briefing
 This topic has been pinned, so it's probably important
Uglu_Muglu  [developer] 8 Mar, 2016 @ 8:09am
For the statistics guys out there
The fomulas used to estimate luck are rather simple but they already give you a "good" feeling for how much luck you had.
Lets see what all luck formulas have in common. They always have some component that is an expected value (E ) and a component that is the actual observed component (O). In addition they always assume that each of the shots happen independent from each other.

Goal should thus be find a function L(O,E) (the "luck score") such that
1) The luck score does reflect the luckyness in game
2) Assumption of independence for different events entering is mostly fullfilled
3) We have a "scale" on which the Luck score is defined
[ should be symmetric for lucky/unlucky]
[ Linearity (hard to say why but it then feels more natural - I guess)]
Last edited by Uglu_Muglu; 8 Mar, 2016 @ 1:03pm
< >
Showing 1-15 of 25 comments
Uglu_Muglu  [developer] 8 Mar, 2016 @ 8:18am 
My luck score currently is:
ObservedNumHits - E[numHits]
1) good (but does not include actual damage dealt)
2) mediocre (whithout that shot missing the other shot would have never happend
3) Mediocre/Bad (unbounded, especially for large num of shots)

Another possible luck score is
( ObservedNumHits - E[numHits] ) / max( ObservedNumHits , E[numHits] )
1) good (but does not include actual damage dealt)
2) mediocre (whithout that shot missing the other shot would have never happend
3) Good (bounded by +/- 100 %)
Last edited by Uglu_Muglu; 8 Mar, 2016 @ 12:39pm
Uglu_Muglu  [developer] 8 Mar, 2016 @ 8:32am 
Kosmos Luck score currently is:
(ObservedNumHits - E[numHits]) /E[numHits]
1) good (but does not include actual damage dealt)
2) mediocre (whithout that shot missing the other shot would have never happend
3) Mediocre (bounded by +99 and -1, because we only use integer percentage)
Last edited by Uglu_Muglu; 8 Mar, 2016 @ 12:21pm
GeminiGod 8 Mar, 2016 @ 10:35am 
@Uglu_Muglu:

1. The value displayed at top left (first screen): Perhaps change the title to "Accuracy/Expected Accuracy". Probably too many letters to include "no overwatch". People can figure that out given it is same as vanilla. (Though not sure why you wouldn't include overwatch since you are tracking it.)

2. Yes, I am familiar with statistics. Please read the following carefully. Your descriptions of yours and Kosmo's formulas are inaccurate, which is a bit perplexing. Your own formula described doesn't match what your own mod is actually doing.

Kosmo's actual formula:
Luck = (ActualAvgHIt% / ExpectedAvgHIt%) - 1.
Where ActualAvgHit%=HIts/Shots. Where Luck is multiplied by 100 to turn it into a %.

Ex: A soldier's accuracy is 20%. His expected accuracy is 60%. Therefore his accuracy is 1/3 of what it should be, which is calculated as "67% unlucky".
(In your example of a 1% chance shot that hits, luck would be calculated as 99% (assuming a sample size of 1), not 9900.)

Your formula as best I can tell:
(ActualAvgHit% - ExpectedAvgHit%) * 100

Ex: A soldier's accuracy is 20%. His expected accuracy is 60%. Therefore he is 400% unlucky. This is terribly confusing. Are you saying he is 4x less likely to hit than expected? No that is not true. If you drop the *100, what you can say is that there was a difference of 40% between actual and expected HIt%.

In summary, you are trying to compare the difference whereas Kosmo is trying to compare the ratio. Neither is necessarily right or wrong so long as used properly (which yours isn't at the present time). The difference method is simpler and works fine with a small sample size (such as your mission stats). The ratio method is more useful with larger sample sizes, and it is more useful to predict future outcomes. ( Ex: Overall my soldier is 10% unlucky, therefore my next shot with a 50% hit chance is probably more like a 45% hit chance. You can't extrapolate that way by just comparing the difference.)
Last edited by GeminiGod; 8 Mar, 2016 @ 10:40am
Uglu_Muglu  [developer] 8 Mar, 2016 @ 11:44am 
I am statistics geek too :)
@ Kosmos formula:
(ActualAvgHIt% / ExpectedAvgHIt%) - 1 = (ActualAvgHIt%- ExpectedAvgHIt%) / ExpectedAvgHIt% (if you think of it as a fraction and then pull the - 1 up in the numerator
Which i translated into
(ActualNumOfHits/NumShots-ExpectedNumberOfHits/NumShots)
/(ExpectedNumberOfHits/NumShots)
=(ActualNumHits-ExpectedNumHits)/ExpectedNumHits
which is what I tried to say
So if I now have a soldier hits a 1% shot then for me the ExpectedNumHits = 0.01, ActualNumHits=1 & NumShots=1; so for me ActualAvgHit % = 100 % whereas ExpectedAvgHit % =1% which gives for me 99 which was in my head 9900 % (okay in this case as the percentage is always an integer it is actually bounded by 99, if it was float it is definately unbounded just consider 0.1% shot that hits ->score = 990)

Also: What happens if a soldier misses all shots -> score always -1

@ My Formula:
Just skip the *100 factor and it would produce 40 % (I don't have the 100% factor in my formula)
Read it as: He is 40% (absolute) short of performing as expected.
The absolute difference is sometimes also used for votes "Party A has lost 5% during the last week" (dropped from 40% to 35%) Which correctly should have been "Party A lost 12.5% of what they had previously"
In germany we have the expression "Prozentpunkte" ~ percentage points for something like that

Didn't say Kosmo's formula is wrong! (At least didn't intended to say so) Just thought about it and for me it never made sense that it was unbounded even for a single shot. And even th bounds are pretty odd [-1 to 99] (only valid for integer)


I considered it among others for my mod (never had a look at Kosmos before I finished my mod) as well as the third version where we have a denominator of max(ActualAvgHit%, ExpectedAvgHit%) (which is certainly bounded by one even for floats)
and a fourth version which is
(ActualAvgHitProbability - ExpectedAvgHitProbability)/
sqrt[(ExpAvgHitProbability)*(100%-ExpAvgHitProbability)]
Where in the denominator there is the variance (if we assume that the shot is bernoulli distributed.
Problem here also is that it is unbounded

I am still looking for better solutions which might better handle 1) and 2)

Can you come up with some sentence for Kosmo's luck score? (Like I did)
Last edited by Uglu_Muglu; 8 Mar, 2016 @ 12:41pm
Uglu_Muglu  [developer] 8 Mar, 2016 @ 12:30pm 
Came up with another interesting scenario to think about:
Two guys shoot:
Pistol (2-3 damage), Rifle (3-5 damage)
Lets say both have a hit percentage of 50%, and damage roll is equally likely to score anything in the interval. As for two shots at 50% we expect (on average) one hit. So let's further assume that either of then did hit.
Target has 4 Hp.
Would't you say you were more lucky when hitting with the rifle at 4/5 rather than hitting with the pistol at 3?
But statistically speaking hitting with the rifle at 4/5 is more likely = you were less lucky if happening? :steamhappy:

Resolution:
The statistic nerds would introduce another function to avoid such odd things: The gain or more frequent the risk
In our example one could define the gain as a function of the amount of damage dealt that is 0 for damage <=3 (target still alive) and 1 for damage >=4 (target dead)
Now the observed gain for hitting for hitting with the rifle for 4/5 is 1 whereas the expected gain from shooting with the rifle is 2/3 so ObservedGain-ExpectedGain=1/3
For the pistol the actual and expected gain are both zero so the difference is also zero.
All in all gain for hitting with Rifle for 4/5 is higher then hitting with pistol for 3
So one concludes hitting with the rifle for 4/5 has a higher gain = one could then translate this back into being more happy (higher gain) at the end of the day when hitting with the rifle for 4/5
Last edited by Uglu_Muglu; 8 Mar, 2016 @ 11:46pm
GeminiGod 8 Mar, 2016 @ 5:11pm 
Your explanation very helpful to understand your thought process. Regarding Kosmo's formula (Will discuss your formula and other questions in separate post):

I agree with your algebraic deconstruction of Kosmo's formula as you have now described it, though your unusual example with 990% as the answer and statement that it is unbounded is not true, hence my confusion. Every variation of the below formulas (as you correctly wrote them above) yield the same answer bounded from 0-1 or 0-100%.

All of these variations of the same formula yield the same results:
Luck = (ActualAvgHIt% / ExpectedAvgHIt%) - 1
Luck = (ActualAvgHIt%- ExpectedAvgHIt%) / ExpectedAvgHIt%.
Luck = (ActualNumHits-ExpectedNumHits) / ExpectedNumHits

The problem is that by deconstructing the first formula, you are not actually simplifying. You are adding an extra calculation step. We are given the ExpectedAvgHit%. No math is needed here! You add a math step by trying to simplify that down to a hits/shot formula and are essentially inventing data (unless you are trying to calculate a number of shots needed to hit, but I digress). You can't go simpler than the raw data you are starting with. Admittedly it is confusing that the data points are already an average chance to hit that we are simply averaging a second time.
Last edited by GeminiGod; 8 Mar, 2016 @ 9:09pm
GeminiGod 8 Mar, 2016 @ 5:57pm 
Regarding your formula, as mentioned before, I agree with your conclusion that Kosmo's calculation might be better for a Lifetime Stats mod with a larger sample size than with your mission stats mod. (Again, his calculation is also critical for his mod because he is predicting future shots.) The small sample size with mission stats definitely makes comparing the difference between the averages simpler and more intuitively logical.

If it is a simple subtracting formula after you calculate the ActualHIt%, the answers should be bounded where x is -100<=x<=100. These crazy numbers I see right now in your mod for 394% luck are not being calculated or displayed properly.

"What happens if a soldier misses all shots?"
- I agree 100% or 0% with Kosmo's formula not terribly useful with small sample sizes other than to simply tell you in binary fashion that you were more or less lucky than expected. It is probably better if ExpectedHIt%=60 and ActualHit%=0 to say that Luck = 0 - 60 = -60%.

I also considered more complicated calculations that try to consider fancier stats calcs, but this isn't really a traditional statistics question we are trying to answer, and I found my brain was chasing its own tail! Usually stats tries to measure something and then compare it against random chance. Here we are essentially comparing random chance with random chance for fun because we are a superstitious people and superstition is fun! :) More accurately, what we are actually measuring with these luck calculations is variance caused by sample size effect!

"Can you come up with some sentence for Kosmo's luck score?"
- I did already on my first comment in this discussion. A soldier with 20% accuracy and 60% expected accuracy is 1/3 as accurate as expected, or 2/3 (67%) as inaccurate as expected.
- Kosmo's luck calculations are slightly more appropriately described as a ratio (which I mentioned to him, but % makes more sense for people and I would display it that way too if I were him.)
- I love your comparison sentence: " "Party A has lost 5% during the last week" (dropped from 40% to 35%) Which correctly should have been "Party A lost 12.5% of what they had previously". Interesting that German has other words for this! (No wonder you are such good engineers!)
Last edited by GeminiGod; 8 Mar, 2016 @ 9:12pm
GeminiGod 8 Mar, 2016 @ 6:16pm 
Rifle/Pistol Experiment:
- Now this is really interesting and opens up a whole new can of worms! A formula that includes the luck of damage range roll would be very cool but much more complicated. Probably also much trickier for you to program (so not sure if you want to go there!). Your formula would have to reference weapon damage as well as weapon mods and abilities. And there is the issue of critical hits...

You could also take it a step further and try to approximate a total luck score for soldiers that includes offensive hits, crits, & damage, as well as defensive hits, crits, & damage. Its not worth making my brain hurt trying to figure that one out unless the programming challenges could be overcome and there was a genuine interest in using it.
GeminiGod 8 Mar, 2016 @ 9:51pm 
I didn't notice your resolution comment for the rifle/pistol experiment:

I think I follow what you are saying there with gain. Interesting idea. It might start getting a bit confusing and subjective if a kill shot is valued differently than a non-kill shot for damage luck.

My recommendation would be to track the min and max possible damage for every hit for the entire mission based on weapon, mods, etc. (misses should be ignored since you are already tracking that chance separately). Ideally melee and grenades would also be included in this. Then calculate the expected mean with perfectly average luck. This mean becomes the ExpectedDamage. DamageLuck% = ((Actual Damage / ExpectedDamage) - 1) * 100.

Rifle/Pistol experiment example:
Pistol damage range of 2-3 equals a mean of 2.5 expected damage.
Rifle damage of 3-5 equals a mean of 4 expected damage.
Lets say soldier has 1 hit with each weapon. Pistol hits for 2 damage. Rifle hits for 5 damage.
ExpectedDamage = 2.5 + 4 = 6.5
ActualDamage = 2 + 5 = 7
DamageLuck% =(( 7 / 6.5) - 1) * 100 = 7.69% lucky.

Then if you wanted you could combine this easily with your existing offense and defense hit% luck calculations via basic addition and subtraction for an overall luck%.
Last edited by GeminiGod; 8 Mar, 2016 @ 10:01pm
Uglu_Muglu  [developer] 8 Mar, 2016 @ 11:23pm 
@ The bounding problem:

Upper bound
Lets say soldiers actual accuracy is 100% and expected accuracy is 1%
Kosmos' formula (100%/1%-1)=(100-1)=99
(So staying with integers for expected accuraray results in bound of 99 [ no percent here so 9900%])

Lets say soldiers actual accuracy is 100% and expected accuracy is 10 ^ -i %
Kosmos' formula (100%/10^ - i %-1)=(10 ^ (i+2)-1)~10^ (i+2)
arbitrarly large because can make i arbitrary large.
(So allowing expected accuraray to be >0% and <1% results in unbounded score)

Lower bound
Lets say soldiers actual accuracy is 0% and expected accuracy is Whatever%>0
Kosmo's: (0%/whatever%-1)= - 1
-> bounded from below
Last edited by Uglu_Muglu; 8 Mar, 2016 @ 11:27pm
Uglu_Muglu  [developer] 8 Mar, 2016 @ 11:33pm 
@ 394%
it was actually a problem with how XCom treats different attack types, I simply treated everything happening between aliens and XCom equally:
But throw/launch grenade gives 0% = shot.GetHitChance but shot.WasHit == true which my program then processed as: Amazing you were 100% Lucky you son of a ****
Hope you never had 394% since version 0.903 though

@ the rifle pistol thing:
I guess, I screwed it up because something else got into my mind while wrtiting about it:
The idea was:
Both have a 50% chance to hit so on average one of the two shots are going to happen. Lets say we are in the average case of either one of them hits:
(and then the story continues)
Edited version is online

@ you suggestion including damage,
I like the idea once I figured it out how to read the damage roll things from XCom it's gonna be included for sure!


@ more at how I see the rifle pistol thing
Lets say the basic approach is calculating something like a luck score by comparing based on an outside viewpoint the observed/actual result with the expected result.
But as we are all humans at the end of the day we might not (only) be interested in how lucky we were but maybe also what he have gained from something (e.g. how happy we are at the end of a mission)
So for calculating the happiness (~gain) we have to take into consideration also how we personally see things (kind of biased maybe)

If we now come back to the rifle pistol thing but now with an arbitrary hit probability p
P( damage)
P_R(X)=1/3*p (Rifle)
P(X)=1/2*p (Pistol)

Let's now work with a happiness function (which is a gain function in a more general case):
happyness H as a function of shot outcome Rifle (3-5) is H_R(0)= MF (Miss (Frustration) factor < 0), H_R(3) = HNKF (Hit no kill frustration factor )
H_R(4)=H_R(5)=KF (Kill factor)

Lets say MF= - 5 ( i really don't like missing)
Lets say HNKF= 2 (i do like getting damage in
Lets say KF= 10 ( I do love killing guys very much)

For the pistol we could then also define H_P(0)= MF; H_P(2)=H_P(3)=HNKF
Expected Happiness for rifle
E[ H_R ] = 2/3*p* KF + 1/3 * p * HNKF + (1-p)* MF
Expected Happiness for pistol
E[ H_P ] = p* HNKF + (1-p)* MF

Things start to get even more involved if you also think about the case that you can kill the guy also by hitting with both of them for 2 | 3 respectively ...

The point I am trying to make, and which I also would love to include in the post mission briefing thing is: Displaying something like
You should actually be (freaking happy, Happy , not so very happy, emotionless, unhappy, very unhappy) about the way the mission's outcome
How awesome would that be!


Last edited by Uglu_Muglu; 9 Mar, 2016 @ 12:41am
GeminiGod 9 Mar, 2016 @ 10:44am 
"Lets say soldiers actual accuracy is 100% and expected accuracy is 1%
Kosmos' formula (100%/1%-1)=(100-1)=99"

While you are correct, the implied conversion from % to decimal is hopefully very intuitive to any educated reader. Most math programs automatically convert the % to decimal for you. This isn't something worth debating further. That said, From a programming standpoint I would agree that this issue makes version 2 of that formula probably most optimal as the simplest formula with fewest steps: Luck = (ActualAvgHIt%- ExpectedAvgHIt%) / ExpectedAvgHIt%.

Moving on!

"but maybe also what he have gained from something (e.g. how happy we are at the end of a mission)"

It is your mod so of course at the end of the day you can do whatever you want and my opinion matters very little. That said, the more I think about this happiness idea the less I like it. It is too subjective. Your idea of happiness will be different than mine and mine will be different than the next guy commenting on this mod and asking you questions about how you are calculating this.

Furthermore, this idea of happiness is already built into the objective luck calcuations. I knew what I was doing when I chose to take a pistol shot or a rifle shot and roughly how likely it was to result in a kill shot. Some soldiers tend to have more assists and less kill shots by design of the choices I make. That doesn't mean the soldier with the assists did a worse job or I am less happy with that soldier. The whole point of these objective luck calculations is give me a sense of how happy or unhappy I should be with my soldier's performance. More information would just be TMI IMO. I think it is safe to asume that if a soldier misses a high % shot or we get a below average damage on that shot, all Xcom players will be similarly unhappy with that soldier. If it is a super important shot that my soldier messes up, I don't need a mod to tell me what he did. My memory and the objective statistics from your mod tell me all I need to know.

Lastly, other mods such as Red Fog would dramatically affect your Happiness Quotient. With Red Fog I care less about killing the enemy and more about damaging the enemy because it reduces their stats. Again, if my soldier misses a bunch of shots, and had low damage on the shots he did hit, I am not going to be happy. End of story.

In conclusion I strongly recommend you keep the stats objective, but keep up the fun awards and titles you are currently doing based off of the stats. There are all sorts of fun awards you could do: Biggest loser, Best closer (for most kills), Damage king, Lucky SOB, etc.
Last edited by GeminiGod; 9 Mar, 2016 @ 10:46am
GeminiGod 9 Mar, 2016 @ 9:50pm 
Either the calculation or title for "Most Attacks" seems to be a bit off. It said my soldier with most attacks did 2x, but he did at least 4 or 5 attacks. Is this supposed to say "Most Hits"?
GeminiGod 9 Mar, 2016 @ 10:53pm 
Hmm, the next mission looked good for "Most Attacks." I think maybe it isn't including pistol shots, which is why it looked wrong for my sharpshooter. Could be wrong but that is my best guess.
GeminiGod 13 Mar, 2016 @ 10:49pm 
I finally figured out my confusion about your luck calculation. The 100-hit% thing wasn't sinking into my thick head because the next step wasn't explained and because the initial post in this discussion stated something different. It looks like you are calculating 100 or 0 minus ExpectedHit% for each individual shot and then adding each calculation for each shot together?? Hence the sometimes large % numbers >100%.

Maybe I am completely overanalyzing this and it really doesn't matter, but nevertheless, technically speaking it would be more accuate to simply calculate hits/shots, convert to % form, and then subtract from the total average expected hit%. (ex: if 1 out of 3 shots hit and the expected hit% for each shot was 40%, 50%, & 60%, then Luck = (1/3*100)-((40%+50%+60%)/3) = 33%-50% = -17% luck.
Last edited by GeminiGod; 13 Mar, 2016 @ 10:50pm
< >
Showing 1-15 of 25 comments
Per page: 1530 50