Modeling Combat with Applications to Real Time Strategy Games

This Means War! Modeling Combat with Applications to
Real Time Strategy Games
Alex Chen
February 25, 2012
1
Introduction
In this lab, we will be simulating various battle situations and equations. We will be exploring
the idea that for the same physical situation, there can be many mathematical or statistical
models to express the same idea.
“All models are wrong, but some are useful.” – George P. Box.
Corollary: “Many models are useful, but some are useless.” – Alex Chen
One of the challenges in choosing a proper model is to consider the appropriate level of detail
for the situation: an all-inclusive model can result in too many parameters, clouding the situation, while a model that disregards important processes can be inaccurate.
Another important consideration is computational complexity. A model may be accurate
and simple to describe, but simulations can still be cost-prohibitive. Also, greater accuracy in
one part of the model may be useless if the main model inaccuracy comes from a different part.
Lastly, there is also the question of what insights we would like to derive. Semi-analytic
estimates can be useful as sanity checks and in deriving general properties such as scaling behavior. On the other hand, stochastic simulations can be useful in learning more about the
structure of typical solutions, in computing probabilities, confidence intervals, etc.
We will look at examples illustrating these concepts. Many of my questions will perhaps be
more open-ended than you will normally see, and I have deliberately left in some of my “mistakes” in this lab to show my thought processes and why some experiments were ultimately
invalid (but still worth thinking about!).
2
Review of the Lanchester System
We have already seen the basic Lanchester ODE system:
dx
dt = −by,
dy
dt = −ax,
The Lanchester square law is
2
(x(t)) −
b
2
(y(t)) = C.
a
1
(1)
Figure 1: A diagram of the focus fire concept.
In particular, setting C = 0, gives the initial conditions x(0), y(0) that make the two armies
evenly matched:
b
2
2
(x(0)) = (y(0)) .
a
3
The Effect of Focus Fire
In combat situations, focusing fire on an enemy’s weak points is an especially important concept.
This idea is also simulated in the real time strategy world in the following way:
Suppose initially X has x(0) soldiers, Y has y(0). Also, each soldier, instead of being eliminated by one unit of attack, has a certain number of “hit points.” That is, a soldier is only
eliminated if it takes H units of damage.
In order to examine the effect of focus fire, we suppose that X fires at each soldier of Y
uniformly, while Y targets one soldier of X until it eliminates it (causes H units of damage),
then moves on to the next target. Since Y’s soldiers will not be depleted (only damaged), it
does the same amount of damage to X at any time. X, however, loses its soldiers as before
(with a slight modification to account for the change to a discrete number of soldiers). Then the
Lanchester equations are modified in this way:
dx
b
dt = − H y(0),
(2)
dy
a
dt = − H dx(t)e,
where d·e denotes the ceiling function.
Question 1: How much does “focus fire” help the side that uses it? Let H = 1 and use the
approximation dx(t)e = x(t). Then solve for x, y and find the times t1 , t2 such that x(t1 ) = 0 =
y(t2 ). This solution should give you a relation between x(0) and y(0) similar to the Lanchester
square law
b
2
2
(x(0)) = (y(0)) .
a
Check your calculations by opening FocusFireBattle.m and choosing different starting
army sizes for x(1).
2
4
Building a Discrete Model
We can solve for the model numerically by writing the derivatives as discrete derivatives (i.e.
dx
xk+1 −xk
from t = k4t to t = (k + 1)4t. Then equation (4) is approximated as:
dt ≈
4t
k+1
x
= xk − 4t by k
(3)
k+1
y
= y k − 4t axk
and then solving for the solution at the time step k + 1 in terms of the solution at the time
step k with the initial conditions x0 = x(0) and y 0 = y(0). The termination condition is when
either xk ≤ 0 or y k ≤ 0.
4.1
A Discrete Poisson Model
In order to give the underdog a fair chance (everyone loves an underdog!), we convert the model
into a stochastic (probabilistic) one. Assign the number of troops eliminated in each iteration
to be a Poisson random variable with rate given by the opponent’s firepower.
This gives a closely related discrete Lanchester model:
k+1
x
= xk − P ois(by k ),
(4)
k+1
y
= y k − P ois(axk ),
Question 2: What disadvantage(s) do you see in building a stochastic (probabilistic) model
instead of a deterministic one? What advantage(s)?
Question 3: What interesting questions can you come up with (perhaps in regards to the
variation of parameters, the end result, the termination time, etc.), and how do they translate
mathematically/statistically?
3
5
Possible Interesting Questions
You may have found some interesting questions to ask in response to Question 2 on the previous
page. Here are some that may have been on the list–you are welcome to explore these or your
own. For some of these questions, I have not yet found a definitive answer myself (although I
have strong support and suspicions). That’s research!
Open the file PoissonBattle.m.
5.1
Quick, Decisive Battles or Attrition?
Question 4: If outnumbered, is it better to risk everything in a quick battle, or hope that
attrition plays in your favor? (high a, b vs. low a, b)
In PoissonBattle.m, test the values a = b = 10, a = b = 1, a = b = 0.1, a = b = 0.01 and use
x(0) = 100, y(0) = 90.
Question 4a: What differences do you see in your results in terms of probability of victory
or mean survivors?
Question 4b: Are any of these results strange? Is the model invalid for some parameters?
Why?
5.2
Attrition in the Limit
Question 5: What happens as a, b → 0+ (fixed
a
b )?
Note that it is difficult to test this past a = b = 0.01 since the simulations take too long.
Can you guess whether the probability of winning goes toward some limit?
One way to check this semi-analytically is to observe that for a, b → 0+ , a Poisson distribution looks approximately Bernoulli (taking on only the values 0 or 1):
We say a random variable X is Bernoulli if
P (X = 1) = p = 1 − P (X = 0).
4
The reason for this is that as the Poisson rate approaches 0, the probability of more than
1 occurrence becomes very small compared to the probability of 0 or 1 occurrence. Then our
model becomes:
k+1
x
= xk − Bern(by k ),
(5)
k+1
y
= y k − Bern(axk ),
If for now, we fix p = by k and q = axk , the system becomes a repeated simulation of Bernoulli
variables, which gives a binomial variable for each equation:
k
x = x0 − B(k, p),
(6)
y k = y 0 − B(k, q),
Question 5a: When are these modeling assumptions close to accurate and when are they
extremely inaccurate?
The mean and variance of B(k, p) are kp, kp(1 − p), respectively. With this simplified model,
we can see that the mean and variance are about the same (since 1 − p ≈ 1).
Question 5b: Under this model, do you expect the probability of victory for X to approach
0.5, 1 or somewhere in between?
Just for your information: we approximated the Poisson random variables P oisson(by k ), P oisson(axk )
for small by k , axk by the Bernoulli variables Bernoulli(by k ), Bernoulli(axk ). For large by k , axk ,
we can also approximate P oisson(by k ), P oisson(axk ) by the normal variables N (by k , by k ), N (axk , axk )
(mean = variance = by k and mean = variance = axk ):
k+1
x
= xk − N (by k , by k ),
(7)
k+1
y
= y k − N (axk , axk ),
Another way to approximate the system is by fixing the “attack values” (i.e., the mean
and the variance of the random variable). This also makes the system much easier to analyze
theoretically (but we won’t be doing this for this lab).
k+1
x
= xk − N (by(0), by(0)),
(8)
k+1
y
= y k − N (ax(0), ax(0)),
Question 5c: Run NormalApproxBattle.m and compare the results to those obtained
by NormalBattle.m and PoissonBattle.m. Do the results seem to be approximated well by
fixing the attack values ax(0) and by(0)? When does the approximation work well?
As we take t → 0+ , we get a differential equation in continuous time, a “Stochastic Differ5
ential Equation (SDE)”:
√
dx = −by dt + √by dW1 ,
dy = −ax dt + ax dW2 ,
(9)
where W1 , W2 are Brownian motions. Brownian motion is a very well-studied concept
with applications to many fields and has several nice properties that allow it to be studied both
theoretically and numerically.
5.3
Mean and Variance of Survival Rates
Question 6: Is the mean survival rate similar to that seen from the Lanchester (deterministic)
square law?
5.4
Large Battles vs. Small Battles
Question 7: Are there differences between large battles vs. small battles? (i.e. probability of
victory for x(0) = 1000, y(0) = 900 vs. x(0) = 10, y(0) = 9) Why might these differences or
similarities occur?
The ultimate take-home message is that modeling can be done in many different ways, and
there is no explicitly “correct” method. Secondly, mathematics and statistics can be used in aa
wide variety of applications, sometimes a bit unexpected. Lastly, for all you gamers out there,
hopefully this lab gets you thinking more about the connection between mathematics/statistics
and video games!
6