Game Development Reference
In-Depth Information
The graphics in the Soldier Game are primitive, but the probabilistic simulation of the physics
of a group of charging soldiers is real. The soldiers are acting independently of each other, but
the behavior of the group (for example, the speed of the group) will be more or less equal to the
specified mean speed, and the distribution of speeds within the group of soldiers will follow the
Gaussian probability function. Of course, modeling crowd movement is not the only way to use
Monte Carlo techniques in your game simulations. There are many other applications, from
weather prediction to combat resolution, in which you will want some “structured” randomness.
Using Monte Carlo Methods to Estimate Functions
Another thing Monte Carlo methods can be used for is to estimate the values of complex func-
tions, and historically that was one of the motivations behind the development of Monte Carlo
techniques. To show an example of how it is done, let's use the Monte Carlo method to compute
the value of
. Consider a circle drawn inside a box as shown in Figure 15-8. The box is a square
with a width and height equal to 1 (the units don't matter in this example). The circle has a
radius equal to 0.5 and the origin of the circle is at x-y coordinates of (0.5, 0.5).
π
(0,1)
(1,1)
r = 0.5
(1,0)
(0,0)
Figure 15-8. To compute the value of π , start with a circle inside a box.
Let's say that a series of random number pairs are generated with values between 0 and 1.
These pairs correspond to x-y coordinates inside the box and/or sphere. The random numbers
are generated such that there is an equal probability of any number, in other words that the
probability distribution is a horizontal line. Every generated x-y point will lie inside the box, but
only some fraction of the points will lie inside the circle. The ratio of the number of points inside
the circle, n circle , to the total number of sample points, n total , is equal to the ratio of the area of
the circle to the area of the box.
2
n
π
r
circle
total
=
(15.9)
n
4
2
is treated as the unknown, Equation (15.9) can be rearranged to yield an expression in
terms of
If
π
π
.
n
n
π =
4
circle
(15.10)
total
Search WWH ::




Custom Search