Game Development Reference
In-Depth Information
independently of each other, but their behavior will tend to follow the trends defined by the
probability function.
As an example, let's write a simple Monte Carlo simulation to model an army of soldiers
charging across the field. The simplest approach to use in this situation is to have all of the
soldiers move at the same speed, but this is not a very satisfying solution. In real life, unless the
army is highly disciplined, the individual soldiers would move at different rates of speed. Some
soldiers would simply run faster than others, and there might be some less-brave soldiers who
slow down to let their comrades reach the enemy first.
A more elegant solution is to use a probability function to assign speeds to individual
soldiers. A mean value can be assigned, say 5 m/s , and the actual speeds assigned to the soldiers
will be some random distribution about the mean value. This approach results in a more real-
istic look for the charging soldiers.
We will implement the Monte Carlo approach to the speed of a group of charging soldiers
in a game called the Soldier Game. The GUI display for the Soldier Game is shown in Figure 15-5. In
a more sophisticated game, the soldiers might be displayed using realistic 3-D renderings, but
here they are represented by + signs. Initially, the soldiers are lined up in two rows waiting for
the order to charge. The GUI has text fields in which the user can specify the mean and standard
deviation of the probability function curve. A Start button sets the soldiers in motion and a
Reset button stops the simulation and returns the soldiers to their starting positions.
Figure 15-5. The Soldier Game GUI display
When the Start button is pressed, the soldiers begin to charge down the display. The rate
at which an individual soldier will run at any given point in time will be determined using a
Gaussian distribution function and a random number generator. Figure 15-6 shows a typical
display partway through the charge. The line is no longer straight because the soldiers are
acting independently and have different speeds.
Search WWH ::




Custom Search