
Lanchester's Law
by marimo team
Interactive simulation of Lanchester's Laws of combat
About this notebook
This notebook simulates combat between two armies and tests Lanchester's Square Law. It uses a custom BattleWidget built with anywidget. The widget runs many battles across a grid of blue army sizes against 200 red units. The notebook plots the simulation results with polars and Altair. It also states the Square Law equations with marimo Markdown and LaTeX.
You set the unit stats through a form. Sliders control hit points, damage, attack range, move speed, and a speed multiplier. A dropdown sets the spawn mode to sides or mixed. The simulation starts after you submit the form. You then see the armies fight in the widget. Line charts show each army size over time. Scatter plots compare the final blue survivors against the count that the Square Law predicts. A second dropdown lets you pick one run and view its army sizes in an Altair chart.
The BattleWidget accepts a grid_spec that sweeps blue units from 200 to 990. Each point runs one battle with a random seed. The simulation records unit counts every 0.2 seconds up to 30 seconds. The predicted blue minimum uses the square root of the difference of squared start counts. This value only stays real when the blue force starts larger than the red force.











