Sign in to follow this  
Posselosse

Animal breeding

Recommended Posts

Posselosse    108
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
Crimehawk    122
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:

Health
Armor
Speed
Attack

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 :)

Matt

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
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
kindjie    290
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
Posselosse    108
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
TechnoGoth    2937
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
Edtharan    607
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
Nathan Baum    1027
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
Posselosse    108
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:
asssaissaiiasiasiias
Gene 2 (change 10-20%):
IssASissaiiaSiasiias
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
TechnoGoth    2937
Well, what you mention does already happen. For instance if both your parents have blue eyes you can still have green eyes, even though the blue eye trait maybe dominant .

How about using a base two system with this for you genes? You have strength, agility, and intelligence genes the ‘slot’ they are in determines whether the amount of points they get for that gene. So have strength in slot 6 would give +32 strength

So let take the desert dragon
aaIaSS

Water dragon
siISaA

Now if we want to determine which traits the offspring will have we can say that dominant (uppercase) has 45% chance of being inherited and recessive (lower case) has 25% chance, the remainder is the chance for mutation. Mutation being a randomly selected gene and dominance.

So the oasis dragon breeding would look like this:

1- 25% a, 25% s, 50% mutation
2- 25% a, 25% i, 50% mutation
4- 90% I, 10% mutation
8- 45% S, 25% a, 30% mutation
16- 45% S, 25% a, 30% mutation
32- 45% S, 45,% A, 10% mutation



Share this post


Link to post
Share on other sites
Texas Brigade    199
Real-Life Genetics is a pretty good system, in my opinion. The basics are simple and seem like they would suffice. It would be really cool to add in things like gene linkage, codominance, incomplete dominance, etc. but this might be more than you're looking for. First, to avoid confusion when I say genes, a gene is a single unit that specifies one trait, like agility, strength, and intelligence. The organism's genome consists of many different genes.

One way I see to make variable traits for dragons is to have multiple genes for the trait. Have six genes for strength, and have them each add a certain amount to the strength if they're dominant (or recessive, if you want).

One thing no one has addressed is the possibility of negative genes. There should be some detrimental traits, like "smoke-breath" that disables their ability to breath fire or a gene that makes them particularly susceptible to a disease. People have mentioned inbreeding as a penalty, but inbreeding itself is not a penalty. The AP near the top basically had the right idea. Inbreeding basically decreases the number of heterozygotes (organisms with two different copies of the gene) in the population in favor of homozygotes(organisms with two identical copies of the same gene). If you inbreed two lines of an organism separately for a while, then combine them, you get a whole bunch of genetically-identical super-organisms (called Hybrid Vigor) that get the best traits possible. This is how domestic corn was developed. Inbreeding is a problem in reality because there are negative genes (which are pretty much all recessive), and inbreeding make more of the offspring homozygous for the negative genes, which causes disease. If you add some negative genes, you would discourage rampant inbreeding, which otherwise would easily produce super-dragons.

TechnoGoth is right about recessive genes being there. The recessive may get masked by the dominant gene, but it is still present to be passed on. In fact, if you have a randomly mating population experiencing no sort of selection whatsoever, the frequency of the recessive version of the gene (not the trait, mind you) will stay the same through an infinite generations.

That was a long post. If you are intrigued by real-life genetics, there's probably a lot of the web or you could PM me and I could expound on how to implement it more.

Share this post


Link to post
Share on other sites
Edtharan    607
Quote:
(See the "Creatures" games.)

Yes. They used GAs there. They also used Neural Networks too.

Quote:
Real-Life Genetics is a pretty good system, in my opinion.

Yes, Real Life Genetics is a good system, however, for games, it can be too complex. You don't want your players to need a Degree in Genetics or Animal Husbandry just to play the game. :D.

Use the K.I.S.S principle. Keep it simple.

I think 2 copies of each chromosome and having multiple chromosomes is complexity enough.

If you just have a letter code (or just a number) that codes for a particular trait and the number of those codes in a chromosome will indicate the level of that trait is good enough for a game.

So using this coding system:
S=Strength
D=Dexterity
I=Inteligence

You might have a creature like this:

Chromosome A1: SSSIDDIDSDIDDDS
Chromosome A2: DIIDSIISIDSISSI


The creature will select (randomly) which chromosome to use for this creature (when it breeds it will again randomly select one of these chromosomes to pass on each time it breeds).

So it might choose the first Chromosome and have it's Stats:
Strength: 5
Dexterity: 7
Intelligence: 3

or it might have selected the second chromosome and ended up with stats like:
Strength: 5
Dexterity: 3
Intelligence: 7

You could have a second chromosome pair used for something completely unrelated to the creatures Stats, like the colouring of the creature (you could use another chromosome for each graphical component).

Like this:
R=Red
B=Blue
G=Green


Chromosome B1: RRGBGBRGRBRGRRBGGBG
Chromosome B2: GRBBBRBBGBBRGGBRRGB

Which would set the colour of the creature.

Also when breeding you can make random mutations to the chromosome too. So Chromosome A1 might mutate like this:
S'D'SIDDIDSDIDDDS


Mutation insures there will always be variation.

[quote]People have mentioned inbreeding as a penalty, but inbreeding itself is not a penalty.[quote]
I don't think inbreeding should be explicitly made a penalty. Keep it simple. The fun a game like this has is in the breeding. The players will want to be able to take two good creatures and breed them for specific traits. They won't want to have to deal with the creature's breeding history (which if they can trade them between each other they will not be easily able to track anyway) to avoid inbreeding.

What you really need to capture in any GA system for this kind of game is Variation and Selection. Anything else just begins to complicate matters and makes it harder for players to understand what is going on and then use that understanding to make meaningful decisions.

If the game was just about the breeding, this kind of complexity would be justified, but as breeding isn't the main focus, then more complexity like this (just to make it closer to real life genetics), in my opinion, is not justified.

Quote:
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).

Variable length Chromosomes can be handled, but it adds a lot of complexity to your GA system. I would say it isn't really worth it for this type of game.

The easies way (but not exactly how it occurs in real life genetics) is to allow 3 more mutations, rather than just the mutation that changes one code into another code (like in my example earlier in this post).

The 3 new mutations are:
1) Additions: This allows you to add in a new code letter at a random point in a chromosome, which extends the length of the chromosome.

2) Deletions: This is the opposite of the Addition mutation. This causes a random code letter to be removed shortening the length of the chromosome.

3) Breakages: this is designed to stop genomes becoming too long. The longer the chromosome length, the more likely this mutation will occur. The breakage causes the chromosome to split at a random point along it and one part being discarded. The other section is kept and use as the chromosome in the creature.

This will cause very dramatic mutations (that would essentially be a genetic disease that can be passed on and might not actually show up for a couple of generations). This would make the more powerful creatures (longer genomes so they can have more code letters to increase traits) harder to breed (and thus be rarer and more valuable), which works in well for the trading aspect of the game.

This is another complexity that I would not recommend adding unless you thought it would contribute to the fun of the game. It might be justified, as it adds to the trading aspect of the game, and not just to the breeding aspect.

Quote:
I just have to find a good way to sore everything in the database.

If you are having set length chromosomes, then Arrays are your friend here. Each Chromosome can be stored in an array and if you are using paired chromosomes, then just add an extra dimension to the array. Multiple chromosomes can be handled by using multiple arrays in a data structure

For example:
If you have a chromosome length of 15 codes, then you could just use an array like this:

GenomeA [15][2]
GenomeB [20][2]
GenomeC [5][2]
...

This will allow you to have different sized chromosomes in the same creature (however, each pair has to be the same length and each creature has the same length chromosomes).

Variable length chromosomes can either be handled by a linked list, or by dynamic arrays.

For files, just use something like a delimited file (like Space delimited - where each chromosome is separated by a space) and read it in as a text file one character at a time.

Eg:

SSSIDDIDSDIDDDS DIIDSIISIDSISSI RRGBGBRGRBRGRRBGGBG GRBBBRBBGBBRGGBRRGB

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this