The FIGHT 3 flow is analogous to the one for FIGHT 2, but both of these differ
slightly from the FIGHT 1 flow (Fig. 13.4). To calculate FIGHT 1 we do not need a
ghost of STOCK 1, because we always know the value of that stock—earlier we set
it to 1.
Once we calculated the length of the winner of the fights in each pair of worms,
that worm will die, too. We model the winner’s death with the outflows from the
respective LIFE stocks, such as
LIFE 2 EXPIRES ¼ LIFE 2:
ð13:6Þ
The LIFE 1, LIFE 2, and LIFE 3 stocks are used to calculate the lengths of the
next generation of worms. For each pair of offspring we flip a coin, as we have done
in previous chapters:
COIN 1 ¼ RANDOM 0; 1
ð Þ
ð13:7Þ
COIN 2 ¼ RANDOM 0; 1
ð Þ
ð13:8Þ
COIN 3 ¼ RANDOM 0; 1
ð Þ
ð13:9Þ
Then we compute the length of the new worms based on the outcome of the coin
toss. We interpret numbers below .5 as tail and in that case make the length of one
new worm 1 unit less than that of the winner of the fight, and we make the other
offspring 2 units shorter. For numbers above .5 we make the offspring 1 and 2 units
longer, respectively. For example,
NEW WORM 1 ¼ IF LIFE 1 > 0 AND COIN 1 < :5
ð
Þ THEN LIFE 1 À 1
ELSE IF LIFE 1 > 0 AND COIN 1 > :5
ð
Þ THEN LIFE 1 þ 1
ELSE 0
ð13:10Þ
Fig. 13.4
13.1 Artificial Worm Model
111
Précédent

- 119/419

Suivant