Stupid or unlucky?

Discuss anything related to warbarons.

Re: Stupid or unlucky?

Postby Zajoman » Tue Sep 07, 2010 1:26 pm

Piranha,

If I'm not mistaken, the only dynamic strength should be the versus flyers bonus, as all other bonuses should be calculated once before a battle starts. I know it's not like that now in the game, but KGB told me it was going to be like that in beta 3, as was in DLR. The versus flyer bonus is already implemented in my solution. And, even if you stick to these dynamic strengths (like W4), it's no big deal. I'm trying to make my solution work how beta 3 intends to work, not how it works now (at least from what I know). If you plan to divert from W2 (or DLR) system a lot in the future, then I'm not sure about any solution.

I don't know about shuffling a 1-20 array. It might easily work the same way if the numbers get shuffled to more or less follow a sequence. What works unfailingly is doing a huge number of loops with huge number of calls to mt_rand().

In my solution, I'm using the predefined strength difference table so for one single hit there is only one single roll.

KGB,

Say you have results from 1000 battle simulations. How exactly would you do the cutting off now? After those 1000 simulations, you run a single battle and see if it fits into the 1000 simulations, but how exactly? I thought I had a clear idea of this, but as I approached implementation, I realized I didn't.
Zajoman
 
Posts: 107
Joined: Thu Aug 12, 2010 6:56 pm

Re: Stupid or unlucky?

Postby KGB » Tue Sep 07, 2010 3:23 pm

Zajoman,

How exactly would you do the cutting off now? After those 1000 simulations, you run a single battle and see if it fits into the 1000 simulations, but how exactly?


That's the easy part.

Look back to the post where I showed the distribution results for the 8v8 stack (page 3). I've posted it here below.

Stack 1 won 7391 battles with an average of 1.726800 units left
Stack 2 won 2609 battles with an average of 0.331100 units left
Stack 1 Survivor Distribution: 1859 2756 1642 786 267 75 6 0
Stack 2 Survivor Distribution: 2155 239 183 31 1 0 0 0
The Attacking Stack winning percentage is 0.739100

What's important are the survivor distributions of each result. So in my example I ran 10000 times. 10% cut off is 1000 occurrences. Basically, the numbers you see are the % results for each individual result. So the 1859 number mean that 18.59% of the time Stack 1 wins with 1 man left, 2756 means 27.56% of the time stack 1 wins with 2 men left etc.

There are 2 ways you can then do the 10% cut off.

1) A hard cut off at 1000 results (10%). So any count <1000 is dropped. This leaves:

Stack 1 Survivor Distribution: 1859 2756 1642
Stack 2 Survivor Distribution: 2155

As the only valid results in the 90% range. Which is stack 1 winning with 1,2 or 3 men or stack 2 winning with 1 man.

2) A soft cut off at roughly 88-92%. You get this by summing up the results and stop when you reach 1000. Note that it's highly unlikely you will 1000 right on. So you stop at the largest value <1000 when summing.

So for stack 1 you get 0+6+75+267. Since adding 786 to that is more than 1000 you don't include the 786 result.
So for stack 2 you get 0+0+0+1+31+183+239. Since adding 2155 to that is more than 1000 you don't include the 2155.

What's left are the results you accept.

Stack 1 Survivor Distribution: 1859 2756 1642 786
Stack 2 Survivor Distribution: 2155

Which is stack 1 winning with 1,2,3 or 4 men or stack 2 winning with 1 man.


I prefer the soft cap because it gives just a bit more range of results. But either method is acceptable to me.


So when you do your 'real' combat you just check to see if it's one of the accepted results. If not you re-do it.

There is one caveat that needs to be added. In any 1-1 battle (1 unit vs 1 unit) you should never do the simulation. Instead just do one combat and take the results. That allows a 1-1 battle to always give the underdog unit a chance (ie a single bat can kill a single dragon). In a similar way regardless of how one sided a battle is (Eg A hero a 7 dragons vs 2 bats) there should always be a valid result that allows the super weak stack to kill 1 enemy unit (so the valid results would be hero+dragons winning with 0 or 1 lost man even thought the 1 lost man case is WAY <10%).

KGB
KGB
 
Posts: 3030
Joined: Tue Feb 16, 2010 12:06 am

Re: Stupid or unlucky?

Postby Zajoman » Tue Sep 07, 2010 6:04 pm

Hmm. An interesting idea crossed my mind as I was trying to understand that. How about keeping track of rolls that favoured the attacker and rolls that favoured the defender. In my method, I simply generate a random number between 0 and 1 and when this number is lesser than the attacker's chance to hit, the attacker hits, if not, the defender hits. So in this method, every roll below 0.5 favours the attacker and every roll above 0.5 favours the defender. Now you just run one battle and see the ratio between favoured rolls. If one side was favoured much more than the other, you run the battle again, until the rolls fit into a defined cap. So for example if a battle takes 20 rolls to finish and 18 of those 20 rolls favour one side, you run it again, as it is a 90% favour of one side, which is too much.

I'm going to play with this a bit now.
Zajoman
 
Posts: 107
Joined: Thu Aug 12, 2010 6:56 pm

Re: Stupid or unlucky?

Postby Zajoman » Tue Sep 07, 2010 6:25 pm

Well, that doesn't work. I tried one Light Infantry vs 8 Scouts and rarely Light Infantry won, because it's stronger in 1 to 1 face offs, so even with 50% distribution of rolls, it wins. Which is bad. I'll try to play more with this to see if I can come up with something usable.
Zajoman
 
Posts: 107
Joined: Thu Aug 12, 2010 6:56 pm

Re: Stupid or unlucky?

Postby KGB » Tue Sep 07, 2010 6:33 pm

Why not just use the actual combat algorithm?

The 50% thing isn't modeling the real algorithm correctly which is why you have this problem. The light infantry should kill 2-3 scouts on average and 4-5 on a really lucky day.

Or are you still searching for a way to speed up doing the 1000 simulations?

KGB
KGB
 
Posts: 3030
Joined: Tue Feb 16, 2010 12:06 am

Re: Stupid or unlucky?

Postby Zajoman » Tue Sep 07, 2010 7:04 pm

Ya, this idea would drastically reduce the number of simulations.
Zajoman
 
Posts: 107
Joined: Thu Aug 12, 2010 6:56 pm

Re: Stupid or unlucky?

Postby piranha » Tue Sep 07, 2010 7:12 pm

I've rewritten my battle function today.

I used the same idea to just do one roll per attack by first calculating the chance that one unit will win and then roll a percentage and see if it meets the chance to win.
Will this not give a proper result?

I can do 1000 runs with 7v7 units in 0,7 sec now which should be okay.

I will make a separate simulation function that doesn't bother about writing results or do the critical strike function to further optimize the speed.
It should work I think.
User avatar
piranha
Site Admin
 
Posts: 1189
Joined: Fri Feb 12, 2010 9:44 pm

Re: Stupid or unlucky?

Postby Zajoman » Tue Sep 07, 2010 7:16 pm

Yes, it should definitely work, what KBG wrote about cutting off. I just got this idea and wanted to try it out. It doesn't work no matter what I do with it.
Zajoman
 
Posts: 107
Joined: Thu Aug 12, 2010 6:56 pm

Re: Stupid or unlucky?

Postby KGB » Tue Sep 07, 2010 7:26 pm

Piranha,

piranha wrote:I used the same idea to just do one roll per attack by first calculating the chance that one unit will win and then roll a percentage and see if it meets the chance to win.
Will this not give a proper result?


I don't understand what you mean when you say "first calculating the chance that one unit will win and then roll a percentage and see if it meets the chance to win".

Are you saying that if a strength 1 unit faces a strength 2 unit and the winning percentage for the strength 2 unit is say 66% you just roll a percentage dice and if it's 66% of less you say the strength 2 unit won?

If that's what you are doing then no, it doesn't work.

The reason it doesn't work is that when more than 1 unit is involved you aren't handling the fact that a unit can be partially damaged before it faces the next unit.

In other words if 1 strength 2 unit faces 2 strength 1 units and assuming the strength 2 unit kills the 1st strength 1 unit when it faces the next strength 1 unit it can have 1 or 2 hits left. Obviously the chance of then beating that 2nd unit depends greatly on how many hits are left (1 or 2). Your one calculation isn't applying partial damage or handing partial damage. So as more units get involved the method will get further from the actual numbers.

So at the very least you have to add in partial damage calculations. So that when you do a percentage roll you are not doing a pure win/loss but rather Unit1-win2hits/Unit1-win1hit/Unit2-win2hits/Unit2-win1hit percentage roll. The carry on all the partial damage and adjust the winning percentage on the next unit faced and so on.

KGB
Last edited by KGB on Tue Sep 07, 2010 7:32 pm, edited 1 time in total.
KGB
 
Posts: 3030
Joined: Tue Feb 16, 2010 12:06 am

Re: Stupid or unlucky?

Postby piranha » Tue Sep 07, 2010 7:31 pm

I meant hit, not win.
I'm calculating the chance for a unit to hit the other unit.

Lets say if its 66% chance that the attacking unit will hit the defending unit I roll 1-100 and if I get less or 66 its a hit for the attacking unit.

I'm using this to calculate the chance for a hit:

Unit 1, STR 5, Chance to hit 25% (5/20) (with 20 sided dice)
Unit 2, STR 7, Chance to hit 35% (7/20) (with 20 sided dice)

One battle round
Unit 1 hits: 0.25 * 0.65 = 16.25%
Unit 2 hits: 0.75*0.35 = 26.25%
Any other outcome will result in the dices are thrown again.

Probability for a hit after eventual re rolls:
26.25 / (26.25+16.25) = 61.8% for unit 2
16.25 / (26.25+16.25) = 38.2 % for unit 1

In this case I would roll and if its 61.8% or less its a hit for unit2 otherwise a hit for unit1.
User avatar
piranha
Site Admin
 
Posts: 1189
Joined: Fri Feb 12, 2010 9:44 pm

PreviousNext

Return to Game discussion

Who is online

Users browsing this forum: No registered users and 12 guests

cron
Not able to open ./cache/data_global.php