public static List <Ape> GetSisters(ApeFamilyTree familyTree, Ape ape)
        {
            ApeFamily family = ape.GetFamily();

            if (family != null)
            {
                return(family.Children.Where(elem => elem != ape && elem.Gender != GenderType.Male).ToList());
            }
            return(new List <Ape>());
        }
        public static List <Ape> GetSiblings(ApeFamilyTree familyTree, Ape ape)
        {
            ApeFamily family = ape.GetFamily();

            if (family != null)
            {
                return(family.Children.Where(elem => elem != ape).ToList());
            }
            return(new List <Ape>());
        }
        public static List <Ape> GetDaughthers(ApeFamilyTree familyTree, Ape ape)
        {
            ApeFamily family = familyTree.GetApeFamilies().SingleOrDefault(p => p.Partners.Contains(ape));

            if (family != null)
            {
                return(family.Children.Where(c => c.Gender == GenderType.Female).ToList());
            }
            return(new List <Ape>());
        }
        public static List <Ape> GetBrotherInLaws(ApeFamilyTree familyTree, Ape ape)
        {
            List <Ape> result = new List <Ape>();

            result.AddRange(GetBrothers(familyTree, ape.GetSpouse()));
            List <Ape> sisters = GetSisters(familyTree, ape);

            foreach (var sister in sisters)
            {
                result.Add(sister.GetSpouse());
            }
            return(result);
        }
        public static List <Ape> GetGrandDaugthers(ApeFamilyTree familyTree, Ape ape)
        {
            ApeFamily  family        = familyTree.GetApeFamilies().SingleOrDefault(p => p.Partners.Contains(ape));
            List <Ape> children      = GetChildren(familyTree, ape);
            List <Ape> grandChildren = new List <Ape>();

            foreach (var child in children)
            {
                grandChildren.AddRange(GetChildren(familyTree, child).Where(c => c.Gender == GenderType.Female));
            }

            return(grandChildren);
        }
        public ApeFamily(string name, List <Ape> partners, List <Ape> children)
        {
            Name = name;

            Partners = partners;

            Ape maleApe   = partners.SingleOrDefault(a => a.GetGender() == GenderType.Male);
            Ape femaleApe = partners.SingleOrDefault(a => a.GetGender() == GenderType.Female);

            maleApe?.AddSpouse(femaleApe);
            femaleApe?.AddSpouse(maleApe);


            Children = children;
        }
示例#7
0
 public void AddSpouse(Ape ape)
 {
     ape._depthLevel = _depthLevel;
     _spouse         = ape;
 }