private int ancestorGenerations(int g = 0)
{
// to detect loop (if a creature is falsely listed as its own ancestor)
if (g > 99)
return 0;
int mgen = 0, fgen = 0;
if (mother != null)
mgen = mother.ancestorGenerations(g + 1) + 1;
if (father != null)
fgen = father.ancestorGenerations(g + 1) + 1;
if (isBred && mgen == 0 && fgen == 0)
return 1;
if (mgen > fgen)
return mgen;
else
return fgen;
}
/// <summary> /// Returns the number of generations to the oldest known ancestor /// </summary> /// <returns></returns> private int ancestorGenerations(int g = 0) { // to detect loop (if a creature is falsely listed as its own ancestor) if (g > 99) { return(0); } int mgen = 0, fgen = 0; if (mother != null) { mgen = mother.ancestorGenerations(g + 1) + 1; } if (father != null) { fgen = father.ancestorGenerations(g + 1) + 1; } if (isBred && mgen == 0 && fgen == 0) { return(1); } if (mgen > fgen) { return(mgen); } else { return(fgen); } }