예제 #1
0
 public void AddPastMate(BloodLineMember pastMate)
 {
     if (!this._pastMates.Contains(pastMate))
     {
         _pastMates.Add(pastMate);
     }
 }
예제 #2
0
 public void AddChild(BloodLineMember child)
 {
     if (!this._children.Contains(child))
     {
         _children.Add(child);
     }
 }
예제 #3
0
 public void AddSibling(BloodLineMember sibling)
 {
     if (!this._siblings.Contains(sibling))
     {
         _siblings.Add(sibling);
     }
 }
예제 #4
0
 public void AddParent(BloodLineMember parent)
 {
     if (!this._parents.Contains(parent))
     {
         _parents.Add(parent);
     }
 }
예제 #5
0
 public BloodRelationInstance(BloodLineMember subject, BloodLineMember target, List <BloodRelationType> relationChain, BloodRelationDef relationDef)
 {
     this.Subject           = subject;
     this.Target            = target;
     this.RelationTypeChain = relationChain;
     this.RelationDef       = relationDef;
 }
예제 #6
0
        private static bool _findMostDirRec(BloodLineMember subject, BloodLineMember target, List <BloodRelationType> list, int depthLeft, BloodRelationType checkingFrom)
        {
            if (depthLeft == 0)
            {
                return(false);
            }
            if (subject.Parents.Contains(target))
            {
                list.Add(BloodRelationType.Parent);
                return(true);
            }
            if (subject.Siblings.Contains(target))
            {
                list.Add(BloodRelationType.Sibling);
                return(true);
            }
            if (subject.Children.Contains(target))
            {
                list.Add(BloodRelationType.Child);
                return(true);
            }

            if (checkingFrom != BloodRelationType.Parent)
            {
                foreach (var parent in subject.Parents)
                {
                    if (_findMostDirRec(parent, target, list, depthLeft - 1, BloodRelationType.Child))
                    {
                        list.Add(BloodRelationType.Parent);
                        return(true);
                    }
                }
            }

            if (checkingFrom != BloodRelationType.Sibling)
            {
                foreach (var sibling in subject.Siblings)
                {
                    if (_findMostDirRec(sibling, target, list, depthLeft - 1, BloodRelationType.Sibling))
                    {
                        list.Add(BloodRelationType.Sibling);
                        return(true);
                    }
                }
            }

            if (checkingFrom != BloodRelationType.Child)
            {
                foreach (var child in subject.Children)
                {
                    if (_findMostDirRec(child, target, list, depthLeft - 1, BloodRelationType.Parent))
                    {
                        list.Add(BloodRelationType.Child);
                        return(true);
                    }
                }
            }
            return(false);
        }
예제 #7
0
        public static BloodRelationInstance DeterminRelation(BloodLineMember subject, BloodLineMember target, int MaxDepth = 3)
        {
            var relationChain = BuildRelationChain(subject, target, MaxDepth);

            if (relationChain != null)
            {
                var def      = TryMatchRelationChainToDef(relationChain);
                var relation = new BloodRelationInstance(subject, target, relationChain, def);
                return(relation);
            }
            return(null);
        }
예제 #8
0
        public static List <BloodRelationType> BuildRelationChain(BloodLineMember A, BloodLineMember B, int MaxDepth)
        {
            var chain = new List <BloodRelationType>();

            if (_findMostDirRec(A, B, chain, MaxDepth, BloodRelationType.UNSET))
            {
                chain.Reverse();
                return(chain);
            }
            else
            {
                return(null);
            }
        }
예제 #9
0
        public static BloodLineMember NewBloodlineMember(IEnumerable <BloodLineMember> parents, IPopInstance pop)
        {
            var newMember = new BloodLineMember(pop);

            foreach (var parent in parents)
            {
                newMember.AddParent(parent);
                parent.AddChild(newMember);

                foreach (var otherParent in parents.Where(x => x != parent))
                {
                    parent.AddPastMate(otherParent);
                }

                foreach (var child in parent.Children.Where(x => x != newMember))
                {
                    child.AddSibling(newMember);
                    newMember.AddSibling(child);
                }
            }
            return(newMember);
        }
예제 #10
0
        //private Dictionary<string, List<BloodRelationInstance>> _knownRelations;
        //public List<BloodRelationInstance> GetKnownRelations(BloodLineMember member)
        //{
        //    if (_knownRelations == null)
        //        _knownRelations = new Dictionary<string, List<BloodRelationInstance>>();

        //    var key = member.Villager.InstanceId.ToString();
        //    if (_knownRelations.ContainsKey(key))
        //        return _knownRelations[key];

        //    return null;
        //}

        //public static void TryAddNewRelation(BloodRelationInstance instance)
        //{
        //    var check = CheckForKnownRelation(instance.Subject, instance.Target);
        //    if (check != null)
        //        return;

        //    var key = instance.Subject.Villager.InstanceId.ToString();
        //    if (_knownRelations.ContainsKey(key))
        //        _knownRelations[key].Add(instance);
        //    else
        //        _knownRelations.Add(key, new List<BloodRelationInstance> { instance });
        //}

        //public static BloodRelationInstance CheckForKnownRelation(BloodLineMember subject, BloodLineMember target)
        //{
        //    var rel = GetKnownRelations(subject)?.Where(x => x.Target == target);
        //    if (!(rel?.Any() ?? false))
        //        return null;
        //    else
        //        return rel.Single();
        //}

        public static bool HasRelation(BloodLineMember A, BloodLineMember B, int MaxDepth = 3)
        {
            var instance = DeterminRelation(A, B, MaxDepth);

            return(instance != null);
        }