From Naval Warfare to the Grimdark

I adapted a naval combat model to Warhammer 40k and built interactive calculators using iterative expected values, Markov chains, and Monte Carlo simulation. Monte Carlo wins for accuracy, but Markov chains reveal the probability distributions that expected values hide.



I played tabletop wargames throughout my childhood. Recreating Cannae, Waterloo and Warhammer 40k battles combined tactics, lore and mathematics in compelling ways. This post explores how I adapted mathematical techniques to simulate Warhammer 40k combat outcomes and clarify army unit choice decisions.

Know Your Enemy (And Your Odds)

When your Space Marines charge across the battlefield, you’re not just rolling dice—you’re conducting a symphony of probability. Each bolter shot, each power sword strike, each failed save creates cascading mathematical relationships that separate the victorious from the corpse-servitors. While faith in the Emperor sustains the soul, mathematical analysis, not faith alone, wins wars.

The application of maths to warfare is Operational Research. Applied to Warhammer, it’s called MathHammer1. Formalised during the Second World War2, Operational Research encompasses mathematical techniques for decision-making across logistics and targeting. This post examines three approaches: iterative modelling, Markov chains and Monte Carlo simulation.3

Beginning with the Salvo Model

In 1995, Captain Wayne Hughes modelled naval combat using differential equations—the Salvo Model of Modern Missile Combat4. Two fleets of ships exchange missiles until one is destroyed. This mirrors Warhammer 40k’s structure closely, so we can proceed quickly.

These are the equations that describe the fundamental mechanics:

Where:

  • X, Y = force strengths (ships, aircraft, etc.)
  • α = offensive firepower per unit
  • β = staying power (survival probability under fire)
  • t = time

Combat effectiveness depends on both the ability to deal damage (α) and the ability to survive it (β). The interaction between these creates non-linear dynamics where small advantages compound over time. Now we shall adapt the Salvo model to the mechanics of Warhammer 40k.

Adapting Theory to the Reality of Eternal War

Warhammer 40k combat follows a structured sequence, this is a simplified turn order:

  1. Hit Roll: Does the attack connect?
  2. Wound Roll: Does it penetrate defenses?
  3. Save Roll: Does armor/toughness prevent damage?
  4. Damage Application: How much harm is dealt?

This analysis assumes:

  1. Both units are in range.
  2. Neither unit engages in close combat.
  3. Both units have identical weapons.
  4. No special abilities or powers apply.
  5. No other units intervene.

The adapted equations become:

Hit Probability:

A Space Marine with WS 3+ hits on 4, 5, or 6: 3/6 = 50% chance.

Wound Probability (Strength vs Toughness):

Save Probability:

For Warhammer 40k, the adapted Salvo model equations become:

An example of Mortal Combat

Consider an example. Let’s calculate the expected damage when 5 Space Marines with bolters attack 10 Ork Boyz:

Space Marine Stats:

  • Models: 5
  • Attacks: 2 (bolter)
  • Weapon Skill: 3+ (hits on 4+)
  • Strength: 4
  • AP: 0
  • Damage: 1

Ork Boyz Stats:

  • Toughness: 5
  • Save: 6+
  • Wounds: 1

Step-by-step calculation:

  1. Total Attacks: 5 models × 2 attacks = 10 attacks
  2. Hit Probability: WS 3+ means hitting on 4+,
  3. Wound Probability: S4 vs T5 (S < T but S ≥ T/2),
  4. Failed Save Probability: 6+ save with AP 0
  5. Expected Damage:
  6. Models Killed:

Result: The Space Marines are expected to kill 1 Ork Boy per shooting phase.

But this is only one round of combat, for one unit vs another. We should consider how this might evolve over multiple rounds of combat. The remainder of this post examines three computational approaches, each with interactive examples to test their predictions.

Approach 1 - Iterative Expected Value

This simplest approach uses rough assumptions. Combat unfolds as sequential rounds where unit effectiveness decays with casualties. Unit 1 attacks first, dealing expected damage to unit 2, then unit 2 retaliates.

 ALGORITHM: Combat Attrition Simulation
 INPUT: unit1_stats, unit2_stats, unit1_models, unit2_models
 OUTPUT: surviving models for each unit

 1: WHILE unit1_models > 0 AND unit2_models > 0 DO
 2:   damage_to_unit2 ← calculate_expected_damage(unit1_current_models, unit2_stats)
 3:   damage_to_unit1 ← calculate_expected_damage(unit2_current_models, unit1_stats)
 4:
 5:   unit2_models ← unit2_models - ⌊damage_to_unit2 / unit2_wounds_per_model⌋
 6:   unit1_models ← unit1_models - ⌊damage_to_unit1 / unit1_wounds_per_model⌋
 7:
 8:   round_counter ← round_counter + 1
 9: END WHILE

The implementation enforces whole-number models only. When expected values yield 1.39 casualties, the calculation rounds down to 1.

The interactive calculator below simulates two-unit combat. Space Marines acting first typically win in 5 rounds with 6 survivors. If Ork Boyz attack first, combat extends considerably. Around 27 Boyz create near-parity. Test your own matchups below.

Unit 1

0-6 (0 = none)

2-6

0 or negative

Unit 2

0-6 (0 = none)

2-6

0 or negative

Unit 1 attacks first - flip to see how turn order affects the outcome

Limitations of this approach:

  • Uses expected values only, ignoring variance from dice rolls
  • Rounding masks probabilistic uncertainty
  • Assumes perfect proportional scaling with casualties
  • Cannot model statistical outliers

Markov chain analysis models actual probabilities, not just expected values.

Approach 2 - Markov Chain Analysis

Iterative analysis uses expected values, but real combat involves variance. Units deal more or less damage than predicted. Markov chains model this stochasticity.

The model assumes combat follows Markovian properties: future state probabilities depend only on the current state, not past states. This simplifies reality—weapons don’t degrade with use, for instance—but proves sufficient.

Key Markov chain concepts:

State Space: Every possible combination of remaining models for both units. For 5 vs 8 model combat: states = (0,0), (0,1), …, (5,8) = 54 total states

Transition Matrix: P(i,j) = probability of moving from state i to state j in one combat round.

Absorption Analysis: Terminal states where combat ends (one or both units eliminated).

Fundamental Matrix Calculation:

N = (I - Q)^(-1)

Where Q is the transient submatrix of the transition matrix.

State Transition Mathematics: For each current state (m1, m2):

ALGORITHM: Markov State Transition Matrix
INPUT: Current state space S = {(m₁, m₂) : m₁, m₂ ≥ 0}
OUTPUT: Transition probabilities T(s → s')

1: FOR each current state s = (m₁, m₂) ∈ S DO
2:   FOR each damage outcome k ∈ {0, 1, ..., max_damage} DO
3:     P(k|s) ← Binomial(n, p, k)
4:     WHERE n = total_attacks(s), p = hit_wound_save_chance
5:     
6:     s' ← (m₁ - ⌊k/w₁⌋, m₂ - ⌊k/w₂⌋)
7:     T[s][s'] ← T[s][s'] + P(k|s)
8:   END FOR
9: END FOR

The Markov chain simulator below shows Space Marines winning decisively in 5 rounds. With 27 Ork Boyz, Ork victory probability rises to 44.5%, though Marines retain advantage. Note: survivor counts assume that side wins. A Marine victory leaves 5 survivors; an Ork victory leaves 12.

Unit 1

0-6 (0 = none)

2-6

0 or negative

Unit 2

0-6 (0 = none)

2-6

0 or negative

Unit 1 attacks first - flip to see how turn order affects the outcome

Comparing iterative and Markov approaches reveals:

  • Combat outcomes vary widely around expected values
  • Win probabilities diverge significantly from predictions
  • Combat duration distributions show heavy skew
  • Rare decisive outcomes occur more often than expected

Approach 3 - Monte Carlo Simulation

Markov chains offer mathematical precision but face computational limits for complex scenarios. Monte Carlo simulation takes a different approach: simulate thousands of combats with actual dice rolls.

The Law of Large Numbers underpins Monte Carlo: with sufficient trials, sample statistics converge to population parameters. As simulations increase, results approach true outcomes. This convergence follows:

Where:

  • N = number of simulations/trials
  • X̄_N = sample mean from N trials
  • μ = true population mean
  • SE = standard error of the estimate
  • σ = population standard deviation
  • CI = confidence interval
  • z_α/2 = critical z-score for desired confidence level

The implementation follows this algorithm:

Simulation Process:

● ALGORITHM: Monte Carlo WH40k Combat Simulation
  INPUT: unit1, unit2, N_simulations
  OUTPUT: Combat statistics and probabilities

   1: results ← []
   2: FOR simulation ← 1 TO N_simulations DO
   3:   unit1_models ← initial_unit1_models
   4:   unit2_models ← initial_unit2_models
   5:   round_count ← 0
   6:   
   7:   WHILE (unit1_models > 0 AND unit2_models > 0) DO
   8:     // Unit 1 attacks
   9:     hits ← sum(roll_d6() ≥ unit1_WS for _ in range(unit1_models × unit1_attacks))
  10:     wounds ← sum(roll_d6() ≥ wound_target for _ in range(hits))
  11:     saves ← sum(roll_d6() ≥ save_target for _ in range(wounds))
  12:     damage ← (wounds - saves) × damage_per_attack
  13:     unit2_models ← unit2_models - min(damage // unit2_wounds, unit2_models)
  14:
  15:     // Unit 2 attacks (if alive)
  16:     // ... similar process
  17:
  18:     round_count ← round_count + 1
  19:   END WHILE
  20:
  21:   results.append({
  22:     'winner': determine_winner(unit1_models, unit2_models),
  23:     'rounds': round_count,
  24:     'survivors': max(unit1_models, unit2_models)
  25:   })
  26: END FOR
  27:
  28: analyze_results(results)

The simulator below runs thousands of combats with real dice rolls. Adjust simulation count to balance speed against precision. It includes detailed breakdowns of individual combats with actual results.

Unit 1

0-6 (0 = none)

2-6

0 or negative

Unit 2

0-6 (0 = none)

2-6

0 or negative

Unit 1 attacks first - flip to see how turn order affects the outcome

Simulation Settings

Key insights from Monte Carlo:

  • Combat variance exceeds player intuition
  • Identical matchups produce wildly different durations
  • Outliers often decide tournaments
  • Winning and losing streaks are mathematically normal

Conclusion: The War of MathHammer

Each approach illuminates different combat aspects. Iterative modelling shows how attrition compounds small advantages. Markov chains characterise uncertainty mathematically. Monte Carlo captures the full randomness of actual play.

These methods approximate model combat effectively. Classical military theory adapts to discrete gaming, and computation reveals insights unavailable through intuition.

The analysis extends naturally from single matchups to entire armies. Markov chains could model multi-unit engagements. Monte Carlo could incorporate Warhammer’s full ruleset. Extended further, it could optimise army lists and analyse meta-game balance.

From Hughes’ naval equations to Monte Carlo simulation, we see mathematical modelling evolve: from continuous to discrete, deterministic to stochastic, theoretical to computational. This progression explains why tools like UnitCrunch favour Monte Carlo for Warhammer analysis. Each method trades simplicity for insight.

References

Footnotes

  1. UnitCrunch is a really cool website that allows you to model wargames using their rules exactly. UnitCrunch uses Monte Carlo simulations to estimate unit performance.

  2. Harold Larnder, (1984) OR Forum—The Origin of Operational Research. Operations Research 32(2):465-476. Related to Lanchester’s Laws. While influential in military strategy, these laws lack extensive validation. The Salvo model provided a closer fit for Warhammer’s discrete mechanics.

  3. The Ruinous Powers would have you believe that understanding probability is forbidden knowledge, that only through chaos and blind luck can battles be won. This is heresy. The Emperor protects, but He also calculates. The machine-spirits of the Adeptus Mechanicus sing hymns of statistical analysis, and even the sacred STC templates from humanity’s golden age encoded mathematical precision into every circuit and cog. Potentially some readers might also find this analysis takes the fun out of the game. I would argue that if we’re able to use this sort of analysis to help craft better armies or prove systematic imbalances then it improves the quality of the game for everyone!

  4. Loading…