The calculator simulates a Total Battle fight and searches for the troop counts that deal the most damage. Full rules and sources are in battle-mechanics.md in the repository root; the key points:
- Stacks. Every troop type is one stack. Stack strength = count × unit strength × (1 + general strength bonuses); matchup bonuses are not part of it.
- Chance-based effects. Double damage, strike two squads, counter-attack, dodge, block and similar chances are never simulated: we assume the worst luck and model only what happens for certain. They are shown as "not simulated".
- Turn order. Sides alternate stack by stack, each side's next stack is the one that has not acted yet with the highest current stack strength (count × unit strength; a stack that lost units acts later). When one side has no stacks left to act, the other side's remaining stacks act one after another. A stack destroyed before its turn is skipped. The first striker is a coin flip, so everything is simulated both ways.
- Targeting. A stack hits the enemy stack where min(potential damage, target health pool) is largest (always damage-based; equal damage goes to the strongest enemy unit type). Enemy strikes use the same rule with potential = count × strength × matchup; equal values go to the larger health pool, then random in game (the simulator pessimistically hits a stack that has not acted yet). Health is a pool: no overflow, and casualties are the drop in ceil(pool / unit health). Bonuses are summed before they are applied once; double-damage chance is an expected value.
- Overwhelming enemy. Epic squads (Fenrir, Eternal Legion, Shadow, Famine, Insanity) are modelled with unlimited reserves by default (real squad sizes vary; enter counts under Advanced to model a finite squad): they never die, and each of their strikes wipes the player stack with the highest current total health. Your stacks keep striking until all of them are gone (there is no round limit). This is why many stacks of staggered health beat one big stack: each extra stack absorbs one strike and buys other stacks another attack.
- Damage formula. Per-unit strike damage = base strength × (1 + (G + matchup %) / 100), where G is the sum of all general strength bonuses and the matchup % is added. Health = base × (1 + H/100). Confirmed against two real battle reports.
- Round start. Round 1 is opened by the first striker; each later round is opened by the side opposite to the previous round's last actor (in practice the enemy, since you usually field more stacks).
- Score. Valor and experience in the reports are exactly proportional to the health of killed enemies, so the score is effectively damage (default). Kill counts are expected values (damage / unit health, fractional) and shown as a secondary metric. "Strike two squads" is ignored (worst case: it never triggers).
- Losses. When a finite target is destroyed in both strike orders the damage score saturates at its total health, so the optimizer ranks the winning lineups by weighted casualties — one unit's weight is its revive cost (from the game config) × a per-category modifier (mercenaries ×0.5, dominance monsters ×2, everything else ×1; 0 = expendable) — and finally by the smallest deployment. Because a won battle saturates the score, the LP's pool-filling seed hides leaner armies, so a budget sweep re-solves at fractions of your pools and reports the smallest army that still clears the squad ("Smallest clearing army"). Against unlimited epic reserves the target is never destroyed and none of this applies; turn it off for a pure damage race. Casualties (per stack and total, weighted) are shown in the results.
- Commanders. Hero and captain levels add leadership / dominance / authority; captains also add their strength/health bonuses (level bonus + ascension-star bonus, additive with research, talents and manual %). Conditional (group march) and PvP-only bonuses are excluded.
- Pools. Leadership, Dominance and Authority are independent budgets.
- Optimizer. For a fixed kill order and attack order the damage is linear in the counts, so an LP picks counts; the real simulator then scores the rounded result. A greedy/local search chooses which stacks to use and in which order. Classic ladder, single-stack and - for finite targets - strike-sized ladder baselines are always evaluated (the strike-sized one sizes each stack to exactly what one enemy round can kill, computed from the enemy's real count × strength × matchup instead of the ×2-per-tier approximation).
- Assumptions / open questions. What decides round 1's first striker is unknown. Chance-based effects are never simulated (worst case). Research/talent labels are matched conservatively; always check the shown bonus profile.