Stupid or unlucky?

Discuss anything related to warbarons.

Re: Stupid or unlucky?

Postby KGB » Tue Aug 31, 2010 4:59 pm

Piranha,

The program Zajoman posted above was an earlier one showing a strength 6 vs strength 4 unit.

Here it is modified for the Spider vs Hero Stack battle

Code: Select all
int main(void)
{
   int hitsStack1 = 2;
   int hitsStack2 = 16;
   int strStack1 = 9;
   int strStack2 = 4;
   int winsStack1 = 0;
   int winsStack2 = 0;
   int unitsLeftStack1 = 0;
   int unitsLeftStack2 = 0;

   srand(time(NULL));
   
   for (int i=0; i<10000; i++)
   {
      while (hitsStack1 > 0 && hitsStack2 > 0)
      {
         int rollStack1 = (rand()%20) + 1;
         int rollStack2 = (rand()%20) + 1;
         
         if (rollStack1 <= strStack1 && rollStack2 > strStack2) hitsStack2--;
         if (rollStack2 <= strStack2 && rollStack1 > strStack1) hitsStack1--;
         
         if (hitsStack2 == 6) strStack2 = 7;   // Switch to Hv Calv
         if (hitsStack2 == 2) strStack2 = 8;  // Switch to Hero
      }
      
      if (hitsStack1 == 0)
      {
         winsStack2++;
         unitsLeftStack2 = unitsLeftStack2 + (hitsStack2+1)/2;
      }
      if (hitsStack2 == 0)
      {
         winsStack1++;
         unitsLeftStack1 = unitsLeftStack1 + (hitsStack1+1)/2;
      }
      
      hitsStack1 = 2;
      hitsStack2 = 16;
      
      strStack1 = 9;
      strStack2 = 4;
   }
   
   printf ("Spider Stack won %d battles with an average of %f units left\n", winsStack1, unitsLeftStack1/10000.0);
   printf ("Hero Stack Stack won %d battles with an average of %f units left\n", winsStack2, unitsLeftStack2/10000.0);
   printf ("The Spider Stack winning percentage is %f\n", (float)winsStack1/10000.0);
}



Note: This program could be easily modified to actually have a GUI and let players select the units on both sides, work out the bonus's and then do the battle.

If you want to simulate using the new combat system simply change these lines:

int hitsStack1 = 2;
int hitsStack2 = 16;
if (hitsStack2 == 6) strStack2 = 7; // Switch to Hv Calv
if (hitsStack2 == 2) strStack2 = 8; // Switch to Hero
hitsStack1 = 2;
hitsStack2 = 16;

to

int hitsStack1 = 4;
int hitsStack2 = 26;
if (hitsStack2 == 11) strStack2 = 7; // Switch to Hv Calv
if (hitsStack2 == 3) strStack2 = 8; // Switch to Hero
hitsStack1 = 4;
hitsStack2 = 26;

Note: Working out the avg units left is more complex in the 2nd case due to the uneven number of hits per unit so I am not showing that here.

KGB
Last edited by KGB on Tue Aug 31, 2010 5:05 pm, edited 1 time in total.
KGB
 
Posts: 3030
Joined: Tue Feb 16, 2010 12:06 am

Re: Stupid or unlucky?

Postby Zajoman » Tue Aug 31, 2010 5:04 pm

KGB wrote:Piranha,
Note: This program could be easily modified to actually have a GUI and let players select the units on both sides, work out the bonus's and then do the battle.
KGB


Do it! :D
Zajoman
 
Posts: 107
Joined: Thu Aug 12, 2010 6:56 pm

Re: Stupid or unlucky?

Postby piranha » Tue Aug 31, 2010 5:19 pm

Zajo, do you have a javascript version of this code?

Could you post it?
User avatar
piranha
Site Admin
 
Posts: 1189
Joined: Fri Feb 12, 2010 9:44 pm

Re: Stupid or unlucky?

Postby Zajoman » Tue Aug 31, 2010 6:08 pm

Here it is. You will need to modify it to simulate specific battles.

Code: Select all
function WarlordsTest()
{
   const DIE = 20;
   var HITS_STACK1 = 2;
   var HITS_STACK2 = 2;
   const CYCLES = 100000;

   var hitsStack1;
   var hitsStack2;
   var strStack1 = 4;
   var strStack2 = 4;
   var winsStack1 = 0;
   var winsStack2 = 0;
   var unitsLeftStack1 = 0;
   var unitsLeftStack2 = 0;

   for (i = 0; i < CYCLES; i++)
   {
      hitsStack1 = HITS_STACK1;
      hitsStack2 = HITS_STACK2;

      while (hitsStack1 > 0 && hitsStack2 > 0)
      {
         var rollStack1 = GetRandomInt(1, DIE);
         var rollStack2 = GetRandomInt(1, DIE);

         if (rollStack1 <= strStack1 && rollStack2 > strStack2) hitsStack2--;
         if (rollStack2 <= strStack2 && rollStack1 > strStack1) hitsStack1--;
      }

      if (hitsStack1 == 0)
      {
         winsStack2++;
         unitsLeftStack2 = unitsLeftStack2 + (hitsStack2 + 1) / 2;
      }
      if (hitsStack2 == 0)
      {
         winsStack1++;
         unitsLeftStack1 = unitsLeftStack1 + (hitsStack1 + 1) / 2;
      }
   }

   window.document.write("Attacker stack winning percentage is " + winsStack1 / CYCLES * 100 + "%.");
   //printf ("6 Strength Stack won %d battles with an average of %f units left\n", winsStack1, unitsLeftStack1/10000.0);
   //printf ("4 Strength Stack won %d battles with an average of %f units left\n", winsStack2, unitsLeftStack2/10000.0);
   //printf ("The 6 Strength Stack winning percentage is %f\n", (float)winsStack1/10000.0*100.0);
}

function GetRandomInt(min, max)
{
   if (min == max || min > max)
   {
      window.alert("GetRandomInt(): Incorrect arguments!");
      return null;
   }

   return min + Math.floor(Math.random() * (max + 1 - min));
}
Zajoman
 
Posts: 107
Joined: Thu Aug 12, 2010 6:56 pm

Re: Stupid or unlucky?

Postby KGB » Tue Aug 31, 2010 6:23 pm

My plan would be to take this J/S code Zajoman posted and change it so that:

1) Instead of a set strength you instead had an array of strengths (size 8 for attacker, size 32 for defender)
2) Add a GUI interface that lets users select:
- The battle terrain (L0-L3 city, open, hills, forest, swamp etc)
- The units for the attacker/defender (for heroes you select hero level from 1-10)
3) As a user select units you add that units strength into the strength array and increase the number of hits for the unit (by 2 now, by a different number in the new combat system in beta3)
4) Work out the bonus's for the various units (terrain, stack, hero, city)

Run the combat.

This shouldn't take more than the addition of a hundred lines of code + GUI interface. I'm OK coding in J/S but don't have great GUI knowledge. If Piranha could help with that since he's doing all the J/S for this game it would be great. For example the screen that lets you select production is almost perfectly designed to let users select the units for each side (just needs addition of heroes).

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

Re: Stupid or unlucky?

Postby piranha » Wed Sep 01, 2010 8:05 am

I've been testing a bit with this code this morning.

I got are the following results:

100.000 testruns
Attacker
5 str 4
2 str 7
1 str 8

Defender
1 str 9


2 HP
Attacker stack winning percentage is 98.381%.
Def survivors:0.01619
Attack survivors:5.24382
Def winnings:1619
Att winnings:98381


4 HP
Attacker stack winning percentage is 99.81400000000001%.
Def survivors:0.00186
Attack survivors:5.22596
Def winnings:186
Att winnings:99814


6 HP
Attacker stack winning percentage is 99.971%.
Def survivors:0.00029
Attack survivors:5.21262
Def winnings:29
Att winnings:99971


8 HP
Attacker stack winning percentage is 99.998%.
Def survivors:0.00002
Attack survivors:5.19964
Def winnings:2
Att winnings:99998




100.000 testruns
Attacker
str 5
str 7
str 7
str 7
str 8
str 9
str 11
str 10

Defender
str 4
str 4
str 5
str 5
str 8
str 8
str 6
str 12


2HP
Attacker stack winning percentage is 73.687%.
Def survivors:0.33346
Attack survivors:1.7308
Def winnings:26313
Att winnings:73687

4 HP
Attacker stack winning percentage is 81.041%.
Def survivors:0.20113
Attack survivors:1.63343
Def winnings:18959
Att winnings:81041

8 HP
Attacker stack winning percentage is 88.754%.
Def survivors:0.11281
Attack survivors:1.60438
Def winnings:11246
Att winnings:88754


I realize that this method does not make it impossible for the "wrong" side to win, but it does make a pretty big difference. The result becomes much more predictable. Looking at the first one moving from 2 HP to 4 HP takes away a lot of the spider side winning and at 8 HP its more or less guaranteed win.
Even though I want results to be predictable I also think the charm with the current model is that you don't know how it will go.

The second test was to simulate two quite strong hero armies. I think it shows that the predictable becomes a safer bet with more HP. While 2HP gives 27% for the weak army to win, 8HP gives 11%, thats a pretty significant difference.
Then there is the effect that even when the weaker army wins, it does take more damage.

It may turn out to not be enough but I think it worth testing it and continue from there.

About building a simulator with interface, I will do that, but I'm not sure if it will be in beta3 or 4.
User avatar
piranha
Site Admin
 
Posts: 1189
Joined: Fri Feb 12, 2010 9:44 pm

Re: Stupid or unlucky?

Postby Zajoman » Wed Sep 01, 2010 10:46 am

By adding an equal amount of HP to all units, you simply prolong battles, more rolls are done, and thus, randomness has a lesser impact as there is more/enough room for random numbers to even out. For instance, if you gave all units an insane amount of HP, say 1000, you would practically cut randomness out. At least in theory.
Zajoman
 
Posts: 107
Joined: Thu Aug 12, 2010 6:56 pm

Re: Stupid or unlucky?

Postby piranha » Wed Sep 01, 2010 12:04 pm

Isn't that you are after?
Its what I've been trying to do. That is the problem I have now that the results are so uneven that even if you try to play it safe you will lose many times.
User avatar
piranha
Site Admin
 
Posts: 1189
Joined: Fri Feb 12, 2010 9:44 pm

Re: Stupid or unlucky?

Postby Zajoman » Wed Sep 01, 2010 12:28 pm

No, it's not what I'm after. Randomness plays a vital role in any strategy game. Without it, it would be chess. In fact, randomness adds to the depth of strategy, exactly because you cannot predict results to the least detail and so you must prepare for (almost) any outcome in advance. What we're after is to cut out the insane extreme results, because they do not add to the game, they ruin it. If my chances of conquering a city are 99.98% and I lose it, there is no strategy involved and I cannot do anything to prevent such a loss. It's simply a bad game mechanic that sets me a mile back behind my opposition. If my chances of conquering a city are 75%, I must be prepared for what happens if the battle falls into the 25% and I lose. I attacked some neutral cities with only a slight advantage on my side - some well went, others didn't. And I didn't cry, because I was ready for bad results. I don't want to win every battle where my chance of winning is 51%. But certainly, I don't want to lose battles where my chance is almost 100%.
Zajoman
 
Posts: 107
Joined: Thu Aug 12, 2010 6:56 pm

Re: Stupid or unlucky?

Postby KGB » Wed Sep 01, 2010 1:12 pm

Piranha,

When you changed the number of hits I hope you changed the calculation for armies remaining. This line (and the other one like it)

unitsLeftStack2 = unitsLeftStack2 + (hitsStack2 + 1) / 2;

If you have 3 hits for all units then you need to add 2 and divide by 3. For 4 hits you add 3 and divide by 4. Otherwise you'll get the wrong number of units left. I assume you remembered to do this but just wanted to make sure you did.

The other thing to is to make sure you reset the hitsStack at the end of the battle (not just at the start of the program). I often forget to change where the hits get reset at the end of the battle when I fool around with more hits.

Note that you also have to change the number of hits when you switch strengths to the Hv Calv and Hero.



Two things for you to think about:

1) There is one thing that my program is *not* simulating but is important. That is I am not accounting for the assassination roll (First Strike as called by the game). So the percentages are actually slightly less for the spider due to the first strike roll occurring 7 times against the spider.

More importantly, the more hits you add (say 3 or 4 or 8 to all units) the bigger the importance of first strike. Killing a unit with 2 hits is nice but killing a unit with 8 is going to be *huge*. So if you decide in Beta3 to change all units to 8 hits then the Ghost + WolfRider with their large Assassination chances will end up being the most valuable units in the game.

2) In your second battle by increasing the number of hits you reduced the chance for a weaker but still viable stack to win a combat. Those 2 stacks are reasonably evenly matched at 2 hits a side (73-27). At 4 and 8 hits one stack is vastly better than the other so that in the 8 hit case the defender is really just nothing more than a minor annoyance (there must be some calculation errors in the avg units remaining in the 4 and 8 case because they should not be less when your winning % goes up. I suspect that's because you aren't doing the calculation right with the added hits).

I personally don't think those kind of battles are what the problem is. A matchup like that could and should go either way. The problem is that sometimes even with 8 hits one of those stacks (defender or attacker) is going to win with 6-8 units left instead of the 1-4 that *normally* occur. That's the problem, the extremes. That's really what needs to get eliminated (just like in the Spider battle what needs to be eliminated is not the Spider winning, but rather the Spider killing 8 units when it should only be killing 4-5 units. It just so happens that killing 8 units wins the battle).

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

PreviousNext

Return to Game discussion

Who is online

Users browsing this forum: No registered users and 11 guests

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