Skip to content

Instantly share code, notes, and snippets.

@brismithSFHS
Created December 13, 2022 04:28
Show Gist options
  • Save brismithSFHS/24d4ff21f0ce8084d466049e164a3c48 to your computer and use it in GitHub Desktop.
Save brismithSFHS/24d4ff21f0ce8084d466049e164a3c48 to your computer and use it in GitHub Desktop.
In this program, I was trying to test out which situations in Warhammer 40k are better for troops to be in light cover, and when they are better for troops to be in dense cover. I wanted to test this so that I could decide between the Vexilla Defensor or Vexilla Magnifica for an Adeptus Custodes army.
public class LightOrDense
{
public static void main(String[] args)
{
int lightWins = 0; //Vexilla defensor - light cover: +1 to saving throws, invluns not affected
int denseWins = 0; //Vexilla magnifica - dense cover: -1 to hit
int insigLightWins = 0;
int ties = 0;
int spins = 1000000;
//accounting for:
//hit roll, wound roll, AP with 2+/4++ save
//not accounting for:
//any types of re-rolls
//damage values, feel no pain, etc.
for(int hit = 2; hit <= 6; hit++) //needed number to hit
{
for(int wound = 2; wound <= 6; wound++) //needed number to wound
{
for(int AP = 0; AP <= 5; AP++) //AP value, assuming all custodes targets are 2+/4++
{
int lightFails = 0; //number of unsaved wounds getting through in either situation
int denseFails = 0;
int hitRoll = 0; //vars I need
int woundRoll = 0;
int saveRoll = 0;
int armorSave = 0;
for(int i = 0; i < spins; i++) //do the whole thing
{
hitRoll = (int) ((Math.random() * 6) + 1);
if(hitRoll >= hit) //light cover path
{
woundRoll = (int) ((Math.random() * 6) + 1);
if(woundRoll >= wound)
{
saveRoll = (int) ((Math.random() * 6) + 1);
armorSave = 2 + AP - 1;
if(armorSave < 2) //1s always fail
armorSave = 2;
if(armorSave > 4) //using the invuln
armorSave = 4;
if(saveRoll < armorSave)
lightFails++;
}
}
if(hitRoll - 1 >= hit) //dense cover path
{
woundRoll = (int) ((Math.random() * 6) + 1);
if(woundRoll >= wound)
{
saveRoll = (int) ((Math.random() * 6) + 1);
armorSave = 2 + AP;
if(armorSave > 4) //using the invuln
armorSave = 4;
if(saveRoll < armorSave)
denseFails++;
}
}
}
if(lightFails < denseFails)
{
int percent = (int) (Math.round(denseFails*1.0/(lightFails+denseFails)*100));
if (percent != 50)
{
lightWins++;
System.out.println("Light Cover is better for " + hit + "+hit, " + wound + "+wound, AP -" + AP + " " + percent + "%");
}
else
{
ties++;
System.out.println("Tie for " + hit + "+hit, " + wound + "+wound, AP -" + AP);
}
}
else if (lightFails > denseFails)
{
int percent = (int) (Math.round(denseFails*1.0/(lightFails+denseFails)*100));
if (percent != 50)
denseWins++;
else
{
ties++;
System.out.println("Tie for " + hit + "+hit, " + wound + "+wound, AP -" + AP);
}
}
else
{
ties++;
System.out.println("Tie for " + hit + "+hit, " + wound + "+wound, AP -" + AP);
}
}
}
}
System.out.println("There were " + ties + " statistical ties.");
System.out.println("Light Cover (Vexilla defensor) is better in " + lightWins + " situations.");
System.out.println("Dense Cover (Vexilla magnifica) is better in " + denseWins + " situations.");
}
}
/*Takeaways, from running this a few times:
-Wound roll doesn't matter for this simulation
-Didn't try to model hit re-rolls or modifiers to hit
-2+ to hit, AP -1 or AP -2, Light Cover is better
-3+ to hit, AP -1 or AP -2, Light Cover is better
-4+ to hit, AP -1, Light Cover is better
-4+ to hit, AP -2 is a statistical tie
-5+ to hit, AP -1 is a statistical tie
-In any other situation, Dense Cover is better
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment