Designer's Notebook: More Sex(es) in Computer Games
April 1, 2003
This month's column is slightly expanded from an excerpt of Andrew Rollings' and my long-awaited book on game design, Andrew Rollings and Ernest Adams on Game Design (due out from New Riders Publishing this May).
Most artificial life games, like Petz or The Sims, are about managing a small number of particular individuals. But some A-life games are closer to the "research" definition of A-life; they're about managing a population of creatures over time. Rather than concentrating on improving (or not!) the lives of individuals, the object of the game is to achieve certain things with the population as a whole. By far the most successful of these is the Creatures series from Creature Labs (formerly Cyberlife). In Creatures, you manage a small group of beings called Norns. Norns have a certain amount of AI, and they can be taught things through repetition, like the animals in Petz. Norns also have distinct genetic characteristics. Unlike either the people in The Sims or the animals in Petz, they have a limited life span, so the game is about breeding generation after generation of Norns and exploring and manipulating their world indirectly through them.
Designing a Genome
To create a game in which you crossbreed creatures and get new, unique individuals, you need to devise a genome: a set of descriptors (genes) that define all the important characteristics of the creature. These characteristics should include everything about the creature that can vary from individual to individual: shape, size, coloration, and so on. You can leave out details that are common to all creatures. For example, if all your creatures will have two eyes and that will never change, there's no need to store a gene called Number of Eyes. Genes can have any number of possible values, from binary (striped or spotted?) to floating-point numbers (height of creature in meters).
When two individuals reproduce, they mix their genes somehow, and you will need to define how this is done. For a quantitative value such as height, the initial temptation is to average them. Don't do this. Within a very few generations, all your creatures will be the same height, or very nearly. In fact, human genetics works differently. We have not one value for each characteristic, but two, one inherited from the mother and one from the father. These two values are called alleles. If a person's two alleles for the same trait don't match, one of them dominates according to a rule (the allele for brown eyes dominates the allele for blue, so people with one brown allele and one blue allele will have brown eyes). When a human reproduces, one of the two alleles is chosen at random to go on to the next generation. This means that it's possible for a brown-eyed person to still pass on the allele for blue eyes. Otherwise, the allele for blue eyes would disappear from the population almost immediately.
A Norn checks out the beach scene in Creatures.
As for quantitative values such as weight, in humans, they tend to be controlled by multiple genes and influenced by environmental factors as well. You can define these mechanisms any way you like; you certainly don't have to do it the way humans do. As research goes on, geneticists are finding that mechanisms for genetic recombination and expression are quite complex and vary a lot even within a single species.
Mutation is a change to a gene that occurs as a result of some environmental factor. Radiation is well known as being mutagenic; so are some chemicals. Mutation has the benefit that it introduces random new values into the gene pool. Bear in mind that mutation doesn't normally affect the individual whose genes are mutated; it affects only his offspring. Of course, some of these changes can be detrimental or even lethal to the individual that inherits them. For the purposes of your game, you probably don't want to allow lethal mutations-those that produce miscarriages or stillborn offspring. If your creatures' gestation period is long, it wastes time and doesn't add anything of value to the gene pool.
Life Span, Maturity, and Natural Selection
Each of your creatures needs a natural life span, or your population will explode. (In Creatures, the life span of a Norn is about 30 real-time minutes.) If you want your population to evolve through natural selection -- that is, to become better adapted to its environment -- then your creatures also need a period of immaturity, when they are not fertile, followed by a period of maturity, when they are. Natural selection works only if it kills off creatures with maladaptive genes before they are old enough to reproduce. If creatures could reproduce immediately after they were born, maladaptive genes would never leave the gene pool. For example, suppose that a creature's genes are such that it is unable to recognize food. This creature should die of starvation very soon. Whatever genetic values determine its food-recognition ability are clearly maladaptive. However, if it can reproduce immediately, those genes will be passed on. For natural selection to take place, you will have to design environmental hazards or other mechanisms (such as starvation) that tend to kill off young individuals with poor genes before they get the chance to pass on those genes.
(One of the reasons there are so many diseases associated with aging in humans is that those diseases catch you only after you have had the chance to reproduce. There's no natural selection against genes for arthritis and osteoporosis because those are diseases that occur later in life, after people have already had children.)
If there's one thing we know about evolution, it's that it's very slow -- at least, if it works purely through random mutation and natural selection (evidence is growing to suggest that it's more complex than that). The life span of the Norns in Creatures is really too long for the player to breed hundreds of generations. If you want evolution to be a part of your game, you'll need to find ways of making it work nonrandomly or keep the life span of your creatures very short. Of course, the shorter the lifespan is, the less chance a given creature has to exhibit an interesting behavior, so there's a balance to be struck.
Inheritance of Acquired Characteristics
Long ago, in the morning of the world, the first zebra was pure white. But one day, there was a great fire amid the grasses of the savanna. The zebra stood deep in a pond for safety. When she came out, she was very wet. And as she passed through the burned grasses and reeds on the shore of the pond, the cinders left black stripes all along her sides. And from that day to this, all zebras have had black stripes along their sides.
Inheritance of acquired characteristics is a fancy term for this old children's-story idea. People used to think it was how evolution worked -- if giraffes stretched up their necks to get food, the next generation of giraffes would have slightly longer necks, and so on. In fact, the opposite is true: Giraffes with short necks tend to starve without reproducing, leaving only giraffes with long necks in the gene pool. The outcome is the same, but the mechanism is entirely different. Stretching your neck doesn't change your genes.
However, you're designing a computer game. There's no reason you can't include inheritance of acquired characteristics if you want to. If the player pours blue ink over one of his creatures, that could change the creature's genes to produce blue offspring. In fact, this provides a convenient way for the player to do his own genetic engineering. Instead of fiddling with the creature's genes in a rather artificial user interface, he can fiddle with the creature directly to change its genes.
Notice that learned information is also an acquired characteristic. Humans are not born knowing arithmetic; they have to be taught it. When you teach a human arithmetic, unfortunately, that doesn't cause her children to be born knowing it because the learning goes into her brain, not into her genes. In a game, however, there's a good reason for storing learned behavior in genes as well. If your creatures need to learn something important to survive, it's unlikely that the player will want to teach each individual one by one. It would be better for the player to teach one individual and then for that learning to be expressed in the genes of its offspring so that the player never has to teach them again.
Alternatively, the creatures could store the information in their brains and then begin to teach each other. Of course, you could allow the content of the teaching to change over time, producing behaviors slightly different from what the player originally intended. If certain teachings produce adaptive behavior, they themselves could be selected for, just as genes are. (The notion that ideas behave the way genes do is called memetics and is a highly controversial topic in academic circles. We're talking about computer games, however, and we can do whatever we like.)
How Many Sexes?
Sexual reproduction has the advantage over asexual reproduction in that it mixes up the genes and creates unique new individuals, which might be better adapted to their environment. You don't have to restrict your number of sexes to two, but it is the most efficient mechanism. Two is a convenient number of sexes because it has the maximum probability that two individuals of opposite sexes will find each other when roaming around their habitat, if all are required to be together to reproduce.
Here's an example. Let's assume that you have equal numbers of each sex in the population, and it takes a certain amount of time for a given individual to find another one and determine whether it is a member of the opposite sex. In a two-sex species, there's a 50-50 chance that any other individual is of the opposite sex; that's not bad odds. But if three sexes are required for reproduction, it is harder for all three to find each other. A given individual would need to find two others, which takes longer (there's more chance of being eaten in the meantime), and the odds aren't as good, either. Suppose that I'm of sex A, and I need to find two other creatures of sexes B and C, respectively. When I find the first one, the chance is 1/3rd that it is also of sex A (no use to me) and 2/3rds that it is of sex B or C, either of which will do for now. Let's suppose that it's of sex B. Now the two of us have to go hunt for another creature of sex C. The chance of any given creature being of sex C is only 1/3rd. So, the total probability that I'll find members of the sexes I need when I bump into two random individuals is only 2/9ths (2/3 × 1/3) instead of 50%. And of course, it gets worse the more sexes you have. (For you math types, the formula is
where n is the number of sexes.)
This describes the case where members of all the sexes must be present to reproduce. On the other hand, some fungi have multiple sexes and any two non-alike individuals can reproduce. In this case, the probability is better than it is for humans: if there are 5 sexes and I'm of sex A, then the probability that any one other individual is of a different sex from me is 4/5ths [ the formula is (n - 1) / n] or 80%. That's obviously much better than 50%, and continues to improve the more sexes there are. Go fungi!
Of course, that's based on bumping into other creatures at random; in practice, most animals have mechanisms for finding members of the opposite sex. You don't have to stick to that rule of having equal numbers of each sex, either. Beehives contain one fertile female (the queen), hundreds of infertile females (the workers), and a few fertile males (the drones). And the sex of creatures need not be determined by their genes at all. The sex of many reptiles is determined by the temperatures of their eggs during gestation. Eggs at the top of the pile, nearer the sun, develop into females; the cooler ones at the bottom develop into males.
What Does the Player Do?
A genetic A-life game might not seem to have much for the player to do: Wind it up and watch it go. However, there is actually a fair number of things she might do. For example, she can create completely new individuals and add them to the population to observe how their genes influence the population. She can add and remove environmental hazards that would tend to weed out certain genes. She can play with the rate and nature of mutation by adding or modifying mutagenic objects or areas of the environment. She can also mate particular individuals to select for particular characteristics (with animals, this is considered useful and is called breeding; with people, it is considered evil and is called eugenics).