- Code: Select all
<script type="text/javascript">
function WarlordsTest()
{
var attwinning = 0;
var defwinning = 0;
const DIE = 20;
var HITS_STACK1 = 2;
var HITS_STACK2 = 2;
const CYCLES = 100000;
var strarrStack1 = new Array;
var hitarrStack1 = new Array;
var strarrStack2 = new Array;
var hitarrStack2 = new Array;
var hitsStack1;
var hitsStack2;
strarrStack1[0] = 5;
strarrStack1[1] = 7;
strarrStack1[2] = 7;
strarrStack1[3] = 7;
strarrStack1[4] = 8;
strarrStack1[5] = 9;
strarrStack1[6] = 11;
strarrStack1[7] = 10;
strarrStack2[0] = 4;
strarrStack2[1] = 4;
strarrStack2[2] = 5;
strarrStack2[3] = 5;
strarrStack2[4] = 8;
strarrStack2[5] = 8;
strarrStack2[6] = 6;
strarrStack2[7] = 12;
hitarrStack1[0] = 8;
hitarrStack1[1] = 8;
hitarrStack1[2] = 8;
hitarrStack1[3] = 8;
hitarrStack1[4] = 8;
hitarrStack1[5] = 8;
hitarrStack1[6] = 8;
hitarrStack1[7] = 8;
hitarrStack2[0] = 8;
hitarrStack2[1] = 8;
hitarrStack2[2] = 8;
hitarrStack2[3] = 8;
hitarrStack2[4] = 8;
hitarrStack2[5] = 8;
hitarrStack2[6] = 8;
hitarrStack2[7] = 8;
var r = 0;
var q = 0;
var winsStack1 = 0;
var winsStack2 = 0;
var unitsLeftStack1 = 0;
var unitsLeftStack2 = 0;
for (i = 0; i < CYCLES; i++)
{
//hitsStack1 = HITS_STACK1;
//hitsStack2 = HITS_STACK2;
r = 0;
q = 0;
for(var p=0; p < 250; p++)
{
//window.document.write(r+","+hitarrStack2.length+"<br />");
while (hitarrStack1[q] > 0 && hitarrStack2[r] > 0)
{
/*
var strStack2 = strarrStack2[r];
var hitsStack2 = hitarrStack2[r];
*/
var rollStack1 = GetRandomInt(1, DIE);
var rollStack2 = GetRandomInt(1, DIE);
if (rollStack1 <= strarrStack1[q] && rollStack2 > strarrStack2[r]) hitarrStack2[r]--;
if (rollStack2 <= strarrStack2[r] && rollStack1 > strarrStack1[q]) hitarrStack1[q]--;
}
//alert (hitsStack1+","+hitarrStack2[r]);
if (hitarrStack1[q] == 0)
{
//alert("hello");
q++;
if(q == hitarrStack1.length) {break;}
//unitsLeftStack2 = unitsLeftStack2 + (hitsStack2 + 1) / 2;
}
if (hitarrStack2[r] == 0)
{
//alert("hello2");
r++;
if(r == hitarrStack2.length) {break;}
//winsStack1++;
//unitsLeftStack1 = unitsLeftStack1 + (hitsStack1 + 1) / 2;
}
}
if(r == hitarrStack2.length)
{
winsStack1++;
hitarrStack2[0] = 8;
hitarrStack2[1] = 8;
hitarrStack2[2] = 8;
hitarrStack2[3] = 8;
hitarrStack2[4] = 8;
hitarrStack2[5] = 8;
hitarrStack2[6] = 8;
hitarrStack2[7] = 8;
hitarrStack1[0] = 8;
hitarrStack1[1] = 8;
hitarrStack1[2] = 8;
hitarrStack1[3] = 8;
hitarrStack1[4] = 8;
hitarrStack1[5] = 8;
hitarrStack1[6] = 8;
hitarrStack1[7] = 8;
var Defsurvivors = hitarrStack2.length - r;
var Attsurvivors = hitarrStack1.length - q;
defwinning = defwinning+Defsurvivors;
attwinning = attwinning+Attsurvivors;
}
if(q == hitarrStack1.length)
{
winsStack2++;
hitarrStack1[0] = 8;
hitarrStack1[1] = 8;
hitarrStack1[2] = 8;
hitarrStack1[3] = 8;
hitarrStack1[4] = 8;
hitarrStack1[5] = 8;
hitarrStack1[6] = 8;
hitarrStack1[7] = 8;
hitarrStack2[0] = 8;
hitarrStack2[1] = 8;
hitarrStack2[2] = 8;
hitarrStack2[3] = 8;
hitarrStack2[4] = 8;
hitarrStack2[5] = 8;
hitarrStack2[6] = 8;
hitarrStack2[7] = 8;
var Defsurvivors = hitarrStack2.length - r;
var Attsurvivors = hitarrStack1.length - q;
defwinning = defwinning+Defsurvivors;
attwinning = attwinning+Attsurvivors;
}
}
var Defsurvivors = defwinning / CYCLES;
var Attsurvivors = attwinning / CYCLES;
window.document.write("Attacker stack winning percentage is " + winsStack1 / CYCLES * 100 + "%. <br />Def survivors:"+Defsurvivors+" <br />Attack survivors:"+Attsurvivors+"<br />Def winnings:"+winsStack2+"");
window.document.write("<br />Att winnings:"+winsStack1);
window.document.write("<br />Att winnings:"+winsStack1);
//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));
}
</script>
<div onclick="WarlordsTest();" style="width: 200px; height:100px; border:solid 1px;"></div>
You can take a look at the code if you suspect there are some errors. Could be for sure.
I agree that I want to get rid of those extremes, but what is a good way to do that. Having a sharp edge where if you have 90% to win you will always win seems wrong to me. Its kind of talks against the dice system that is making battles quite exciting compared to chess battles that are not so exciting

I also realize what you say about the fact that being just slightly weaker than the other army will give you really bad odds of winning with more hits.
But these two things kind of work against each other. You want the more powerful army to win, at the same time you don't want the odds to be so much better.
As the system is now, if you have your best hero army and it has 75% chance of winning a battle and instead you lose pretty big, is that okay? When is it not okay to lose any more.
I find it really hard to draw some sort of line where the cut off should be.
I'm not too experienced in math programming, if you have some idea, could it not be tested with this simulation code? If you want some sort of ease effect or something?