int main(void)
{
int hitsStack1 = 16;
int hitsStack2 = 16;
int strStack1 = 6;
int strStack2 = 4;
int winsStack1 = 0;
int winsStack2 = 0;
int unitsLeftStack1 = 0;
int unitsLeftStack2 = 0;
srand(time(NULL));
// Do this battle 10000 times
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 (hitsStack1 == 0)
{
winsStack2++;
unitsLeftStack2 = unitsLeftStack2 + (hitsStack2+1)/2;
}
if (hitsStack2 == 0)
{
winsStack1++;
unitsLeftStack1 = unitsLeftStack1 + (hitsStack1+1)/2;
}
hitsStack1 = 16;
hitsStack2 = 16;
}
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);
}
Users browsing this forum: No registered users and 6 guests