Inbreeding 101
[p]Hey all! Tyler here! I'm taking over the blog post this week to talk a little bit about...
INBREEDING
So, in a game about breeding cats, we knew pretty early on that being able to simulate inbreeding and birth defects associated with that was going to be important. After all, its kinda what we've done to cats and dogs in real life already, both accidentally AND on purpose. [/p][p]![]()
[/p][p]none of this is natural
Gameplay wise, if you have 2 identical cats, and breed them together, you would get a nearly identical kitten. If there is no penalty to inbreeding, you could then play the game with 4 copies of the same cat, forever. Over and over. Which is pretty antithetical to the "infinite different cats!" theme of the game. So the downside to that is birth defects tied to inbreeding. If you breed cats that are too closely related to each other, they have a chance of getting an inbred birth defect, which have negative effects tied to them.
Though, rarely, some of these inbred mutations have upsides attached to them as well[/p][p] [/p][p]
Anyway its pretty fun making a bloodline of cats that rivals or surpasses even the most inbred European royal families. Take a look at this family tree!
![]()
And yes, you can view these family trees in game... when you unlock them. ===== Anyway so, how do I actually compute "how inbred a cat is"? The initial thought is to just detect if the parents are related, and how related are they (how far back you have to check to find a common ancestor). But it turns out, if the family tree looks more like a spiderweb, even that is not super clearly defined. A cat can be an uncle brother or a grandma cousin or any number of relations that don't even have names. So I had to do *research* to figure out how to compute this.[/p][p][/p][p]My first thought is to just check what other games do. And well, it's not exactly a common thing for games to do. Not even dwarf fortress bothers with it. Well, there is one game series that does handle it at least, and that would be Crusader Kings. Since I've never played any of them, I just looked up on their wiki how they handle inbreeding, and learned that they use a fairly simple estimation where they just look back 5 generations and count how many unique ancestors there are. If characters are not related, there should be 32 unique ancestors, and that number shrinks rapidly if there was any inbreeding. [/p][p][/p][p]While I'm sure that works fine for crusader kings, and would *probably* be fine here as well, the fact that it was just an estimation that can't look back further than 5 generations didn't *feel right* to me and made me wonder like, there has to be some actual scientific research here right? Like how is this stuff computed in the real world and what contexts would that even show up in? Turns out, that context is dog breeding. This page was one of the first ones I stumbled on and gives a brief overview of what a "Coefficient of Inbreeding" (COI) is, and how that can be inaccurate if you don't check enough generations backward, along with some metrics for what an "acceptable" and "unacceptable" level of inbreeding is for dogs before there starts to be negative effects. This page is missing the actual math or algorithm to compute the COI, but since it had an actual term, I had a thing I could google for now.[/p][p][/p][p]I eventually stumbled upon this paper (which was not access restricted back when I was doing this initial research, but luckily I did download it before it locked) which had a recursive definition of how to compute the COI (also known as Coefficient of Kinship, or just Kinship):
For some reason academic papers love making formulas look overly complicated with greek symbols and junk everywhere, but its a fairly simple recursive definition that translates directly into just a couple of lines of code. To make this efficient for huge populations (like dog breeding pools), the trick they use is to cache the kinship between every possible pair of living dogs, and once a dog dies they no longer need their kinship relationships to be stored anymore and can be dropped from the database. So the cache stores N^2 values where N is the number of *living* dogs at any given time, and yet this algorithm remains accurate for as many generations backwards as there was data for. No compromises needed!
For mew since you're unlikely to ever have more than 100 or so cats at a given time, this means I can track kinship by storing ~10k values at most in the game's save file, which is a relatively small amount, and notably does not arbitrarily increase over time as you play for hundreds or thousands of hours. Someone can churn through a million cats, no problem, the inbreeding calculation will remain accurate and is fast enough to compute in real time. Is it all necessary? Would an easier, less accurate simulation have had basically the same effect? Maybe. But I do think its funny to say that Mewgenics has the most scientifically accurate inbreeding simulation of any game ever. I'm not one to half ass something if I can full ass it instead!
Anyway I now know way too much about inbreeding.[/p]
INBREEDING
Gameplay wise, if you have 2 identical cats, and breed them together, you would get a nearly identical kitten. If there is no penalty to inbreeding, you could then play the game with 4 copies of the same cat, forever. Over and over. Which is pretty antithetical to the "infinite different cats!" theme of the game. So the downside to that is birth defects tied to inbreeding. If you breed cats that are too closely related to each other, they have a chance of getting an inbred birth defect, which have negative effects tied to them.
For mew since you're unlikely to ever have more than 100 or so cats at a given time, this means I can track kinship by storing ~10k values at most in the game's save file, which is a relatively small amount, and notably does not arbitrarily increase over time as you play for hundreds or thousands of hours. Someone can churn through a million cats, no problem, the inbreeding calculation will remain accurate and is fast enough to compute in real time. Is it all necessary? Would an easier, less accurate simulation have had basically the same effect? Maybe. But I do think its funny to say that Mewgenics has the most scientifically accurate inbreeding simulation of any game ever. I'm not one to half ass something if I can full ass it instead!
Anyway I now know way too much about inbreeding.[/p]