Better Odds

Discussion of all aspects of multiplayer development: unit balancing, map development, server development, and so forth.

Moderator: Forum Moderators

Choicerer
Posts: 238
Joined: April 29th, 2017, 11:37 pm

Better Odds

Post by Choicerer »

This mod removes the "OMG lucker" aspect from the game. It does this by modifying hit chances based on previous hits/misses during a fight.
The mechanism is quite simple -
For each hit a unit scores, the chance to hit is reduced by 20/15/10% times the defending unit's terrain defence multiplier (flat for 50%, more for low defence, less for high) for units with 2/3/4 strikes respectively and by 10% for units with more than 4 strikes.
For each miss, the chance is increased by the same amounts.
The chance never exceeds 80% and is never lower than 20%.
Magical and marksman attacks are not affected by the mod.
The mod was comissioned by Buddh. I coded it and slightly modified the algorithm.
Last edited by Choicerer on March 22nd, 2018, 12:55 pm, edited 2 times in total.
User avatar
Ravana
Forum Moderator
Posts: 2953
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Better Odds

Post by Ravana »

Did you solve the problems with viewtopic.php?f=19&t=24869 ?
Choicerer
Posts: 238
Joined: April 29th, 2017, 11:37 pm

Re: Better Odds

Post by Choicerer »

These problems don't affect my mod, because there are no stackable modifiers, they only persist during a single fight and then are reset.
The caps DO work. I've tested it extensively.
Oh, and I should also add this is NOT an era, but a modification. So you can use it with any Era/Faction whatnot.
Choicerer
Posts: 238
Joined: April 29th, 2017, 11:37 pm

Re: Better Odds

Post by Choicerer »

The mod's got no downloads *cough* so I've added an improvement. Thanks Vasya for the idea! Now the value by which the chances get modified is multiplied by a percentage based on the defending unit's terrain defence, so that for 50% defence the value is not affected, for higher defences it is lower and for lower it's higher. This is to decrease the chances of units occupying high def tiles to be hit at all, to offset the fact that the mod favours half hits over all-misses and all-hits even in situation where this makes less sense.
Choicerer
Posts: 238
Joined: April 29th, 2017, 11:37 pm

Re: Better Odds

Post by Choicerer »

1.0 -
People who use 0.75, please update.
-The mod worked initially, but after I'd implemented vasya's idea about taking the terrain defence into account while calculating the amount by which to increase/decrease the hit chance, I broke it, because I forgot to add a .0 to /100 (divide by 100) which divided by 100 but implicitly converted the variable to an integer and rounded down to 0, completely removing the functionality of the mod. (WML specifics, adding a .0 makes it be implicitly converted to a float after division).
-Removed this bug:
Choicerer wrote: Beware! The mod currently has a bug which will prevent it from working in local games for "Anonymous local players". You can still get it to work by changing the players from "Local Player" to your nickname.
Also now I've included a macros_debug.cfg file in the mod. It's a debug version and if you don't believe the mod works, you can see for yourself.
Here's how.
Spoiler:
Choicerer
Posts: 238
Joined: April 29th, 2017, 11:37 pm

Re: Better Odds

Post by Choicerer »

Version 1.1 adds an additional checkbox option:
-Luck stacking
Adds an additional balancing feature of storing the remaining luck/bad luck after a fight for each side and adding the modifier to the first attack of the next of their units to fight (on offensive or defensive).
vasya
Multiplayer Moderator
Posts: 74
Joined: August 29th, 2012, 1:53 pm

Re: Better Odds

Post by vasya »

That's an interesting topic! I thought of such add-ons before, even considered writing one myself.
The one thing I definitely lacked is time to implement proper chance/damage calculation. There are all these "unit parry / cth" stats, even weapon "parry/cth" chances if I remember correctly. Also "cth" modifiers like marskman and magical, with further complifications of working only on offense, defense etc.
I wonder if you did your job by using "simulate_battle" API, or you tried to take some/all of the parameters above in mind.

By the way, do you share your add-on as a git repository? Would be quite interesting to check out this way, if you have it.
Choicerer
Posts: 238
Joined: April 29th, 2017, 11:37 pm

Re: Better Odds

Post by Choicerer »

Hey, Vasya! No, I haven't used simulate battle, as it actually doesn't affect hit chances themselves, but is just a simulation. Yes, there are weapon specific accuracy/parry attributes. This is what I tried doing initially, but I found the accuracy attribute couldn't be reset to 0% i.e if I added +10% to a weapon's accuracy and then tried to subtract 10% again, it would end up showing as 1%. I didn't want that, since I'm a bit of a perfectionist, so I've used the "Hit chance" special that's used with attacks such as magical and marksman and defines the hit chance in terms of a preset value. (funny, initially I'd forgotten to add "append" to my special and so I ended up erasing all the other specials that a unit might have). It's also easier to zero out the bonus this way, because you can just use remove_specials.

I do have a git account, but no, I haven't shared anything there. But accessing those files is quite simple and you must know it ;). Unless there's some advantage to viewing them in git I don't know about? (I don't really know much about it).

Oh, by the way, I've already implemented your request for my Randomizer, but I haven't uploaded it yet, because I'm working on a feature that adjusts the mirror options for some known scenarios (including yours).
vasya
Multiplayer Moderator
Posts: 74
Joined: August 29th, 2012, 1:53 pm

Re: Better Odds

Post by vasya »

Okay! I'll check out the downloaded sources right from addons server then. Advantages of using git include:
* total change history. For example, the ability to see what changed between 3 days ago and now (for example to find a bug reason).
* the ability to see diff-s. Like, what exactly did you change in the last commit
* the ability to do Pull Requests (also known as Merge requests). ;-)

I'll check out source code on how you calculate chance to hit then.
Choicerer
Posts: 238
Joined: April 29th, 2017, 11:37 pm

Re: Better Odds

Post by Choicerer »

Yeah I sort of knew about that. Version 1.2 fixes a bug that might have prevented the mod from working as intended. (You might want to update it)
buddh
Posts: 25
Joined: April 28th, 2016, 9:49 am

Re: Better Odds

Post by buddh »

hi,

as I wrote to you in-game please implement the following:

The formula is for round k : chance_to_hit(k) +(-)= mod. where mod is a constant.

In short: You calc a modifier at the beginning of the battle. The const calcs to:

mod = base*chance_to_hit = base*(1- terr_def) .

Pseudocode:

const double mod = base(number_strikes)*(1 - terr_def).
int i = 1;

while(battle_on == true){

double dice_attacker = rand() % 100;


if (dice_attacker < chance_to_hit) {

chance_to_hit -= mod;
}
else{
chance_to_hit += mod;
//modulo limits;
}

} //end-of-while

I think you get the picture. Could you implement this one? base(2) = 20; base(3) = 15; base(4) = 10; base(n>4) = 10.
Or even base(2) = 16, base(3) = 12, base(4) = 8, base(n > 4) = 8;. Something along these lines.

I don't like luck stacking too much, because it causes strange modifications on next pieces which change the game a lot. As fun mod ok,
but please don't turn it on as default. You want the more serious players to pick on on this because it is worthwhile 8)

Thanks :) and thanks for the work you put into this. Awesome :D
Choicerer
Posts: 238
Joined: April 29th, 2017, 11:37 pm

Re: Better Odds

Post by Choicerer »

buddh wrote: March 26th, 2018, 6:03 am I don't like luck stacking too much, because it causes strange modifications on next pieces which change the game a lot. As fun mod ok,
but please don't turn it on as default. You want the more serious players to pick on on this because it is worthwhile 8)
Yes, I've also thought about this. What caused me to implement it and set is as default was the fact that people were complaining, insisting the mod wasn't working etc... They often have a hard time understanding how the mod works in essence - that it modifies the chance to hit, but it's still dependent on a randomly drawn value. This feature balances it out even more, but indeed it adds this quirk to the game. Yes, it might be better to switch this off by default... And add a longer description to explain exactly what the benefits and disadvantages of it are.
buddh wrote: March 26th, 2018, 6:03 am I think you get the picture. Could you implement this one? base(2) = 20; base(3) = 15; base(4) = 10; base(n>4) = 10.
Or even base(2) = 16, base(3) = 12, base(4) = 8, base(n > 4) = 8;. Something along these lines.
Ok, so, essentially, you want to halve the modifier. How about adding two options, yours and the one that we're using currently? I've hosted the mod a bit and my impression was that there still some are deviations and since this is a mod that is supposed to reduce the importance of chance in the equation, I feel halving it would make the change be too insignificant? But of course this is still down to testing and anyway I think a checkbox/slider to choose the impact of the modifier might be best?
buddh wrote: March 26th, 2018, 6:03 am Thanks :) and thanks for the work you put into this. Awesome :D
And thank you :). I think it's a really great idea. I definitely think luck has too much bearing on the outcome of battles in this game.
buddh
Posts: 25
Joined: April 28th, 2016, 9:49 am

Re: Better Odds

Post by buddh »

Choicerer wrote: March 26th, 2018, 7:48 am Yes, it might be better to switch this off by default... And add a longer description to explain exactly what the benefits and disadvantages of it are.
Hi, ok. I give you an example of how it changes the game mechanics: You plan a move lets say you must shoot down something from a mountain as dwarf as seen yesterday :eng: You can try to raise your odds by going with a likely fail ahead like you use your archer and hope the last arrow comes out miss, then you can ++ your gunner to make it from 60 to like 52. More later.
Choicerer wrote: March 26th, 2018, 7:48 am I feel halving it would make the change be too insignificant? But of course this is still down to testing and anyway I think a checkbox/slider to choose the impact of the modifier might be best?
yes and no ofc. Lets take a normal scenario, you try a kill with a spearman on a 60 with 3 strikes. What were the odds before?
p(0) = 0.6^3 = 0.216
p(1) = 3*0.6^2*0.4 = 0.432
p(2) = 3*0.4^2*0.6 = 0.288
p(3) = 0.4^3 = 0.064

with my proposed mode with a 15 and yours with a 30 these are the new results: (cth = 0.4, 15 => 6, 30 => 12).
p(0) = 0.6 * 0.54*0.48 = 0.15552 p(0) = 0.6*0.48*0.36 = 0.104
p(1) = 0.4*0.66*0.6 + 0.6*0.46*0.6 + 0.6*0.54*0.52 = 0.1584 + 0.1656 + 0.16848 = 0.49248 ...
p(1) = 0.4*0.72*0.6 + 0.6*0.52*0.6 + 0.6*0.48*0.64 = 0.1728 + 0.1872 + 0.18432 = 0.54432 ....

for that scenario things look similar but look how far they spread for the scenario: a grunt vs a 40 and a grunt vs a 60. 20*0.4 (cth) = 8 or 12, 40*0.4 = 16 or 24.

p(0|normal,60 def) = 0.6*0.6 = 0.36 p(0|B,60 def) = 0.6*0.52 = 0.312 p(0|A, 60 def) = 0.6*0.44 = 0.264
p(0|normal, 50 def) = 0.5*0.5 = 0.25 p(0|B, 50 def) = 0.5*0.4 = 0.2 p(0| A, 50 def) = 0.5*0.3 = 0.15
p(0|normal, 40 def) 0.4*0.4 = 0.16 p(0|B, 40 def) = 0.4*0.38 = 0.152 p(0|B, 40 def) = 0.4*0.2 = 0.08

I dont quite like how it diminishes the fail rate for 2 hit guys. So significantly imho.
I think 40 is over the top. maybe 10,20,30. Lets go for 10,20,30 ?

Let's try it out XD But without stacking plz. :mrgreen:
Choicerer
Posts: 238
Joined: April 29th, 2017, 11:37 pm

Re: Better Odds

Post by Choicerer »

buddh wrote: March 26th, 2018, 10:39 am
Choicerer wrote: March 26th, 2018, 7:48 am Yes, it might be better to switch this off by default... And add a longer description to explain exactly what the benefits and disadvantages of it are.
Hi, ok. I give you an example of how it changes the game mechanics: You plan a move lets say you must shoot down something from a mountain as dwarf as seen yesterday :eng: You can try to raise your odds by going with a likely fail ahead like you use your archer and hope the last arrow comes out miss, then you can ++ your gunner to make it from 60 to like 52. More later.
Yes, I do realise that. On the other hand, this forces you to waste an archer to do things you normally wouldn't. Another question is if people would really care to take such things into account or not. But I agree, it is a quirk.
buddh wrote: March 26th, 2018, 10:39 am
Choicerer wrote: March 26th, 2018, 7:48 am I feel halving it would make the change be too insignificant? But of course this is still down to testing and anyway I think a checkbox/slider to choose the impact of the modifier might be best?
yes and no ofc. Lets take a normal scenario, you try a kill with a spearman on a 60 with 3 strikes. What were the odds before?
p(0) = 0.6^3 = 0.216
p(1) = 3*0.6^2*0.4 = 0.432
p(2) = 3*0.4^2*0.6 = 0.288
p(3) = 0.4^3 = 0.064

with my proposed mode with a 15 and yours with a 30 these are the new results: (cth = 0.4, 15 => 6, 30 => 12).
p(0) = 0.6 * 0.54*0.48 = 0.15552 p(0) = 0.6*0.48*0.36 = 0.104
p(1) = 0.4*0.66*0.6 + 0.6*0.46*0.6 + 0.6*0.54*0.52 = 0.1584 + 0.1656 + 0.16848 = 0.49248 ...
p(1) = 0.4*0.72*0.6 + 0.6*0.52*0.6 + 0.6*0.48*0.64 = 0.1728 + 0.1872 + 0.18432 = 0.54432 ....

for that scenario things look similar but look how far they spread for the scenario: a grunt vs a 40 and a grunt vs a 60. 20*0.4 (cth) = 8 or 12, 40*0.4 = 16 or 24.

p(0|normal,60 def) = 0.6*0.6 = 0.36 p(0|B,60 def) = 0.6*0.52 = 0.312 p(0|A, 60 def) = 0.6*0.44 = 0.264
p(0|normal, 50 def) = 0.5*0.5 = 0.25 p(0|B, 50 def) = 0.5*0.4 = 0.2 p(0| A, 50 def) = 0.5*0.3 = 0.15
p(0|normal, 40 def) 0.4*0.4 = 0.16 p(0|B, 40 def) = 0.4*0.38 = 0.152 p(0|B, 40 def) = 0.4*0.2 = 0.08

I dont quite like how it diminishes the fail rate for 2 hit guys. So significantly imho.
I think 40 is over the top. maybe 10,20,30. Lets go for 10,20,30 ?

Let's try it out XD But without stacking plz. :mrgreen:
Yes, but you've made a mistake in the last line.
buddh wrote: March 26th, 2018, 10:39 am p(0|normal, 40 def) 0.4*0.4 = 0.16 p(0|B, 40 def) = 0.4*0.38 = 0.152 p(0|B, 40 def) = 0.4*0.2 = 0.08
buddh wrote: March 26th, 2018, 10:39 am 20*0.4 (cth) = 8 or (...) 40*0.4 = 16
So it should be 0.4*0.32 = 0.128 OR 0.4*0.24 = 0.96.
So not a 7% difference, but just 3%.
Overall what I can see is in unlikely scenarios there's about 3-5% chance less with my formula for them to happen, whereas the difference between our formulas in likely scenarios is less.
buddh
Posts: 25
Joined: April 28th, 2016, 9:49 am

Re: Better Odds

Post by buddh »

I fully agree.

What worries me most is that finishing a unit with 1/2 against 60s and 1/3 against 70s might become too easy.
Then blocking becomes meaningless in such instances because you then can three way such a piece easily.

yeah should have been 0.4*0.28 = 0.112.
because it is 20*0.6. It was a typo :).


Needed to calc a bit to see the effects. Maybe try your setting, but imho it squeezes heavily towards e-value, making it
a little bit low luck style.

Did you find a way to have it precalc the odds for the preview of combat? :shock:
Post Reply