Jump to content
  • Advertisement
Sign in to follow this  

Animal breeding

This topic is 4124 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I' currently working on a browser based game about duelling animals/pets. There are both races and classes in the game. For example: Dragon (water) - good agility, fast but not so much armour (like a rogue) Dragon (desert) - hard skin (much armour), normal damage and good in taking aggro from enemies (useful as a tank). To make the game harder and more interesting users will be able to breed new animals. To tell the truth there will be three ways of acquiring new animals: 1. Find them. Users will be able to hire special animal hunters who travel the lands looking for eggs. The better the hunters are (more expensive) the better eggs will they be able to find. 2. Trade them. All users will be able to trade animals with each other. 3. Breed them. By selecting two animals and putting them in a special enclosed space the animals will be able to mate and lay eggs. The first two ways of getting new animals are quite easy to create and does not affect the game balance. The third alternative does! Of course I can choose which races and classes that should and shouldn't be able to mate. That's not a real problem. If two animals with different classes mate I'll make the offspring one of the classes and not a combination of the two. The problem is how to solve the issue with over powered animals. I mean: I don't want the animals to get better and better. That would damage the game balance. This is how I have planned to create the breeding system:
// change the strength?
if (rand_func() == 1)
    // Calculate the difference between animal 1 and 2 and then generate a random number between 0 and the difference...
    // Add the generated number to animal 1's strength  
    $pet[1]["strength"] += rand_tal($pet[1]["strength"]-$pet[2]["strength"]);
// loop it for the rest of the stats...
What do you think of this? Users should benefit from spending time on breeding new animals, but still it must be hard to get super animals... Suggestions how to improve it?

Share this post

Link to post
Share on other sites
This is a good idea, but does not allow the pet to be more powerful than the parents. True you don't want the new breed to be TOO strong, but by using your method, you actually make each new breed weaker and weaker, the exact opposite of what you were afraid of.

Ok, my idea, would be to set some specific stats, like for example:


Now, say a desert dragon mates with a water dragon, like in your example.

Water would have high speed, and deser would have high armor and health.

So low armomr+high armor= average armor
So Normal health + Hight health= High health OR normal health (random probably)
So slow speed + high speed= Any speed (low, average, or high)
So Normal attack+normal attack= normal (or even low) attack

So your results could be

Water Dragon: Normal Health, Low Armor, High speed, Normal attack
Desert Dragon: High health, high Armor, low speed, normal attack
Offspring (example): Normal health, Normal Armor, High speed, normal attack

So this could then be balanced by the value of the original 2 dragons, and maybe even have to pay for a random offspring. Using the type of examples I used above. Also, you could have common and uncommon birth defects/boosters to hurt or help the offspring's stats

(Note: the low, normal, and high, were jsut example ranges. these would be number values that do have importance)

Just my 2 cents, hopefully it helps :)


Share this post

Link to post
Share on other sites
Guest Anonymous Poster
The problem with your solution is that, with enough (in)breeding, your more dedicated users will have dragons with high stats in everything. They could breed 2 dragons with one high and one low stat each until both stats are about even, and then breed the resulting dragon with each parent, and then offspring's offspring, etc, until a dragon is achieved with high stats in both. Breed that dragon with another with a high stat, and eventually over the course of time the perfect dragon will be created. This could be offset by having a higher weight on low values, but that just increases the time it would take to have a max dragon.

I think a better solution would be to give each monster random genes that affect the stats. Offspring dragons keep 1 random gene from each of it's parents, and the rest are randomized. This reduces the effectiveness of inbreeding, as even a parent who is good in all attributes will only pass one good one to its offspring.

Share this post

Link to post
Share on other sites
Assuming all stats are equally valuable, you could simply breed with the parents then normalize the stats of the offspring. If you want all creatures to be equally powerful, you could just normalize the values to the same amount.

For instance, say you had at least two stats: strength and speed. You breed a fast animal with a strong one and get offspring with stats: Strength = 3 and Speed = 4.

StrengthNormalized = Strength / Sqrt( Strength^2 + Speed^2 + ... );
SpeedNormalized = Speed / Sqrt( Strength^2 + Speed^2 + ... );

If you wanted to make this a super powered creature:

SuperPower = 2;
StrengthNormalized *= SuperPower;
SpeedNormalized *= SuperPower;

Not sure if this is what you were going for though...

Share this post

Link to post
Share on other sites
yes, maybe I should make a lot of the breeding randomized, but still: that would also make breeding kind of dull... You want to be able to make an impact of the offspring.

Any thoughts about making the offspring unable to breed? This way users would have to mate the animals several times to get a good offspring and I wouldn't have to worry about "super offspring".

But the question about how the mating should look like is still on the table. How do you make a good and exciting breeding system which players will enjoy playing around with? There must be a reason for players to keep mating their animals as well as functions with which players can help design the offspring.

Share this post

Link to post
Share on other sites
What about basing breeding of real style genetics?

Each stat could be either dominate or recessive. When two animals breed their offspring taken on the dominate traits of the parents, if the stat is dominance is the same for both parents then it is chosen at random. Then do +-2% on set the child stats

So if you had:

Desert Dragon
Health – D - 10
Speed – R - 3
Armor – D - 10
Damage – R - 4

Water Dragon
Health – R - 3
Speed – D – 10
Armor – R - 0
Damage – R - 6

Child - 1
Health – R - 9
Speed – D - 12
Armor – D - 10
Damage – R - 5

Child - 2
Health – D - 12
Speed – D - 8
Armor – R - 8
Damage – R - 7

Breeding Child 1 and Child 2
Health – R - 12
Speed – D - 9
Armor – R - 10
Damage – R - 4

You could even start adding defects into the mix. The more you breed members of the same family together the more likely you are to have a stat halved.

Share this post

Link to post
Share on other sites
The best way is to use a genetic algorithm (don't worry the name is more scary than they really are).

A Genetic Algorithm (GA) is really just a string of values. These values are just a set of instructions that your program interprets to build the data set for the creature. In other words, very much like any normal Data File.

The real difference comes when you copy the Gene (the Data File). In a GA, you don't want a perfect copy (otherwise there would be no variations and therefore no "evolution").

So, what you can do is to purposely introduce errors. These would be random changes to the data in the Gene. Other methods involve cutting up 2 (or more) and pasting them back together into 1 (and throwing out the unused parts).

The real trick with the GAs is how you construct the Gene Data File. You need to make it robust so that these errors won't necessarily corrupt the data so that you can't effectively read it.

This is easier than it sounds, especially for a GA that would suit this kind of game.

For starters, lets think about the Gene as a string of characters. Each character represents a level up of a stat. So if you had a Strength Stat and use the letter 'S' to represent it, then each 'S' that occurs in the Gene would increase the strength Stat by 1 (starting from 0).

If the Gene is a limited size, then if the player breeds a creature that is high in Strength, then other stats will have to be reduced. This is because each time the 'S' appears in the gene, it prevents another symbol for another stat from being there.

Now here is where we can add a bit more complexity.

In normal data files, you will deal with headers and other separations in the file structures, what we can do now is exactly the same as that, however, we will be using it as a GA and this will allow us to generate fairly complex behaviours of the GA.

What we can do with the GA is to create Chromosomes. These Chromosomes are really just two different sections of the Data File that is the GA. We can then process them differently. This means that we can have multiple aspects of the creature and not have them competing for gene space.

For instance, in one "Chromosome" we might have all the "Stats" of the creature (strength, dexterity, health, etc), but we can then have a second chromosome which we use for the creatures special abilities (fire breath, hiding, etc).

As the configuration of the first Chromosome has no effect on the second Chromosome, the two are no in competition. Increasing the number of genes that are devoted to the creature's Strength will not have any impact on how many genes can be devoted to its ability to breath fire.

If you want to get really complex, you could have genes that can appear in multiple Chromosomes (and more than just 2 chromosomes as well).

This system does not really support "junk" genes because if you include them they will rapidly get "evolved" out. There are various GA systems that need "junk" genes, but they are far too complex for this kind of game system.

The only other complexity you might want to add into the GA system is to have 2 copies of each chromosome. You would of course only use 1 of them to determine how to convert the GA into the creature description (abilities and stats).

To use this, you would include 1 copy of each Chromosome from each Parent. As each parent has 2 you would randomly select it.

This is actually one area where Junk genes can be used (and you will see why it is much too complex for this kind of game).

What yo vcan have is genes in a chromosome that does not contribute the the creature's fitness (stats and abilities), however, these "Non Coding" genes could be used to change the chance that that particular chromosome would be selected during breeding. This would make each chromosome have more or less chance at being passed on in breeding than it's pair, however, the more chance this chromosome has of being passed on, the less fit the resulting creature will be.

This can also be extended and more Junk gene types can be sued to change the chance that one of the pair will be selected to be used for the creature description (this is like a dominant or receive gene).

So, the basics of GAs are quite simple, but they can become quite complex, and as there is a spectrum of complexity, it means you can select the complexities that you want, and leave out others.

You don't have to use the Genes to "Hard Code" the creature. The genes could describe the creatures ability to learn (or develop) that aspect. So a High Strength value might not mean that the creature has a high strength Stat, but it could mean that the Strength stat is easier to increase in training and others.

This would be the best method as it allows for the players to not only breed their creatures, but also lets them train their creatures. And how they train them will have an effect on the creatures final performance.

EG: A creature might have a high ability to learn to breath fire, but if it is never taught how, then even though the potential is there, the creature never develops it.

Share this post

Link to post
Share on other sites
Original post by Edtharan
The best way is to use a genetic algorithm (don't worry the name is more scary than they really are).
(See the "Creatures" games.)

Share this post

Link to post
Share on other sites
I'd also aim for a realistic implementation of genetics, but I'd go a bit further.

1. Genes encode phenotypes, which are specific manifestation of a trait.

2. A locus is a specific data point within a chromosome. It is essentially a genetic variable.

3. A gene lives at a particular locus.

4. Each phenotype a gene codes for may be individually dominant or recessive.

5. Creatures have two copies of each loci.

6. When two creatures breed, they select which of the two gene for each locus they pass on at random.

This is essentially an extended form of Edtharan's system: the differences are that each gene codes for more one phenotype, and gene placement may (possibly) be limited by more than just "this chromosome for attributes, this chromosome for abilities".

Because each gene codes for multiple traits, super-creatures can be made hard to acquire by combining a recessive supertrait with a dominant defect: breeding to maximize strength, say, might tend to minimize agility.

Here's a simple example where, to save time, I haven't considered rules 5 and 6:

genus "Dragon"
locus 8;

The dragon has 8 loci.

// Dragon (water) - good agility, fast but not so much armour (like a rogue)
"Dragon (Water)": "Dragon"
gene (Agility +5, Armour -3);
gene (Speed +5, Armour -1);
gene (LungCapacity +6, Armour -3);
gene (Damage -6, Agility +1);
gene (Agility +3);
gene (Speed +3, Armour -1);
gene (Speed +1, Damage -3);
gene (Damage -2, Agility +2);

This individual has Agility +10, Armour -8, Speed +9, LungCapacity +6, Damage -11.

// Dragon (desert) - hard skin (much armour), normal damage and good in taking aggro from
// enemies (useful as a tank).
"Dragon (Desert)": "Dragon"
gene (Armour +5, Damage +10);
gene (Speed -3, Damage +1);
gene (Armour +7);
gene (Damage +3, Agility -7);
gene (LungCapacity -1);
gene (Speed -2, Armour -1);
gene (Damage -11);
gene (Agility -3);

This individual has Agility -10, Armour +11, Speed -5, LungCapacity -1, Damage +3.

One possible offspring is:

// Dragon (Oasis) - Average; quite high lung capacity.
"Dragon (Oasis)": "Dragon"
gene (Armour +5, Damage +10);
gene (Speed +5, Armour -1);
gene (LungCapacity +6, Armour -3);
gene (Damage -6, Agility +1);
gene (LungCapacity -1);
gene (Speed -2, Armour -1);
gene (Speed +1, Damage -3);
gene (Damage -2, Agility +2);

This individual has Agility +3, Armour +1, Speed +3, LungCapacity +5, Damage +2.

Out of the available pool of genes, Dragon (Desert) already has the possibly maximum armour of +11. OTOH, careful breeding could increase its Damage to +13 without any negative effects.

An important element of this scheme is to keep the genes hidden. You can of course show the value of each trait. (Although you might prefer to require that the player actually test a particular trait to know its level.)

For example, breeding the desert dragon can eventually produce an offspring which inflicts massive amounts of damage, but if the player doesn't know that, and if most offspring of radically different individuals (and a rogue and a tank are that, I think) are somewhat average, the game will reward those players who take the time to perfect their breeding skills.

Edit: If it's not a persistent-world multiplayer game, you could defeat the problem of people publishing mating guides by randomizing the genes (although keeping the total value of each trait for each species the same) when a game begins. I'm not sure how you'd fix this in a Massively-Multiplayer Online Breeding Game.

Using dominance relationships will also help. For example, if the strong desert dragon's damage was recessive, then a player would probably have to resort to inbreeding to keep the damage in subsequent generations, which would limit his ability to improve other traits for that stock.

Share this post

Link to post
Share on other sites
Thanks for all ideas!

Say I choose to go with 2 genes with stats (strength, agility and intellect for example). Each gene has its own structure and while breeding a script chooses a random of these genes. The first thing I think about when reading about this is how to make the genes look the same, but not exactly the same. Should the breeding result in two identical genes with which I change some letters in one of them?

For example:
Gene 1:
Gene 2 (change 10-20%):
OR you can only change the dominant and recessive parts for each letter

I can make the game so after breeding and exchanging genes (one gene from each parent is copied to the offspring) the genes are mixed up (some letters from each gene change place with the letter on the other gene). But this could make two totally different genes in one animal. One can be a gene of a tank and the other one can be a gene of a rogue. It would be quite confusing if a tank mates with a rogue and the offspring becomes a healer/mage (the rogue carried a healer gene while the tank carried a mage gene). We’ll see if I choose to go with one or two sets of genes.

What I also like about this system is that you can control how many letters each animal has. If a low-level animal (each letter in the gene is one level) mates with a high-level animal this could result in an animal with a number of letters in the gene between high-level (lets say 40) and low-level (say 10).

There’s one problem with the dominant and recessive letters: after a while all letters in a gene will be dominant. If a dominant letter always “win” over a recessive one the recessive ones will soon disappear. How do you introduce the recessive letters in an offspring?

To have different chromosomes sounds like a good idea. I like the idea where you have a chromosome that tells how good the creature is in learning different things. This will create a more complex system where animals are really different from each other. I just have to find a good way to sore everything in the database.

Nathan Baum: Your idea is great, but it’s harder to control since if a user breed it right they can really create good animals since there’s no real roof of each gene/locus.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!