示例#1
0
        public static void AssertGenericType(this TicNode node, StatePrimitive desc, StatePrimitive anc,
                                             bool isComparable = false)
        {
            var generic = node.State as ConstrainsState;

            Assert.IsNotNull(generic);
            if (desc == null)
            {
                Assert.IsFalse(generic.HasDescendant);
            }
            else
            {
                Assert.AreEqual(desc, generic.Descedant);
            }

            if (anc == null)
            {
                Assert.IsFalse(generic.HasAncestor);
            }
            else
            {
                Assert.AreEqual(anc, generic.Ancestor);
            }

            Assert.AreEqual(isComparable, generic.IsComparable, "IsComparable claim missed");
        }
示例#2
0
 public bool Apply(ConstrainsState ancestor, StatePrimitive descendant, TicNode ancestorNode, TicNode descendantNode)
 {
     if (ancestor.Fits(descendant))
     {
         ancestorNode.State = descendant;
     }
     return(true);
 }
示例#3
0
 public bool Apply(ConstrainsState ancestor, StatePrimitive descendant, TicNode ancestorNode,
                   TicNode descendantNode)
 {
     if (!ancestor.HasAncestor)
     {
         return(true);
     }
     return(descendant.CanBeImplicitlyConvertedTo(ancestor.Ancestor));
 }
示例#4
0
        public void GetLastCommonAncestor(PrimitiveTypeName a, PrimitiveTypeName b, PrimitiveTypeName expected)
        {
            var result = new StatePrimitive(a).GetLastCommonPrimitiveAncestor(new StatePrimitive(b)).Name;

            Assert.AreEqual(expected, result);
            var revresult = new StatePrimitive(b).GetLastCommonPrimitiveAncestor(new StatePrimitive(a)).Name;

            Assert.AreEqual(expected, revresult);
        }
示例#5
0
        public void GetFirstCommonDescedant(PrimitiveTypeName a, PrimitiveTypeName b, PrimitiveTypeName expected)
        {
            var result = new StatePrimitive(a).GetFirstCommonDescendantOrNull(new StatePrimitive(b))?.Name;

            Assert.AreEqual(expected, result);
            var revresult = new StatePrimitive(b).GetFirstCommonDescendantOrNull(new StatePrimitive(a))?.Name;

            Assert.AreEqual(expected, revresult);
        }
示例#6
0
        public void GetFirstCommonDescendantToAnyReturnsSelf(PrimitiveTypeName type)
        {
            var result = new StatePrimitive(type).GetFirstCommonDescendantOrNull(StatePrimitive.Any).Name;

            Assert.AreEqual(type, result);
            var reversed = StatePrimitive.Any.GetFirstCommonDescendantOrNull(new StatePrimitive(type)).Name;

            Assert.AreEqual(type, reversed);
        }
示例#7
0
        public void GetFirstCommonDescedant_returnsNull(PrimitiveTypeName a, PrimitiveTypeName b)
        {
            var result = new StatePrimitive(a).GetFirstCommonDescendantOrNull(new StatePrimitive(b));

            Assert.IsNull(result);
            var revresult = new StatePrimitive(b).GetFirstCommonDescendantOrNull(new StatePrimitive(a));

            Assert.IsNull(revresult);
        }
示例#8
0
        public static TicNode AssertAndGetSingleGeneric(this ITicResults result, StatePrimitive desc,
                                                        StatePrimitive anc, bool isComparable = false)
        {
            Assert.AreEqual(1, result.GenericsCount, "Incorrect generics count");
            var genericNode = result.GenericNodes.Single();

            AssertGenericType(genericNode, desc, anc, isComparable);
            return(genericNode);
        }
示例#9
0
        public static void SetCall(this GraphBuilder builder, StatePrimitive ofTheCall, params int[] argumentsThenResult)
        {
            var types = new ITicNodeState[argumentsThenResult.Length];

            for (int i = 0; i < types.Length; i++)
            {
                types[i] = ofTheCall;
            }
            builder.SetCall(types, argumentsThenResult);
        }
示例#10
0
        public bool Apply(StatePrimitive ancestor, ConstrainsState descendant, TicNode _, TicNode descendantNode)
        {
            descendant.AddAncestor(ancestor);
            var result = descendant.GetOptimizedOrNull();

            if (result == null)
            {
                return(false);
            }
            descendantNode.State = result;
            return(true);
        }
示例#11
0
        public Player()
        {
            avatarID     = new StatePrimitive <string>();
            networkID    = new StatePrimitive <string>();
            roleID       = new StatePrimitive <string>();
            ownedItemIDs = new StatePrimitiveList <string>();

            healthLevel = new StatePrimitive <float>();
            hungryLevel = new StatePrimitive <float>();
            thirstLevel = new StatePrimitive <float>();
            temperature = new StatePrimitive <float>();
        }
示例#12
0
 public bool Apply(StatePrimitive ancestor, ConstrainsState descendant, TicNode ancestorNode, TicNode descendantNode)
 {
     if (descendant.Fits(ancestor))
     {
         if (descendant.Prefered != null && descendant.Fits(descendant.Prefered))
         {
             descendantNode.State = descendant.Prefered;
         }
         else
         {
             descendantNode.State = ancestor;
         }
     }
     return(true);
 }
示例#13
0
        public void GetLastCommonAncestorToSelfReturnsSelf(PrimitiveTypeName type)
        {
            var result = new StatePrimitive(type).GetLastCommonPrimitiveAncestor(new StatePrimitive(type)).Name;

            Assert.AreEqual(type, result);
        }
示例#14
0
 public GenericConstrains(StatePrimitive ancestor = null, StatePrimitive descendant = null, bool isComparable = false)
 {
     Ancestor     = ancestor;
     Descendant   = descendant;
     IsComparable = isComparable;
 }
示例#15
0
        public void GetLastCommonAncestorToAnyReturnsAny(PrimitiveTypeName type)
        {
            var result = new StatePrimitive(type).GetLastCommonPrimitiveAncestor(StatePrimitive.Any);

            Assert.AreEqual(StatePrimitive.Any, result);
        }
示例#16
0
 public bool Apply(ConstrainsState ancestor, StatePrimitive descendant, TicNode ancestorNode, TicNode descendantNode)
 => ApplyAncestorConstrains(ancestorNode, ancestor, descendant);
示例#17
0
 public bool Apply(ICompositeState ancestor, StatePrimitive descendant, TicNode _, TicNode __)
 => false;
示例#18
0
 public Item()
 {
     modelID = new StatePrimitive <string>();
 }
示例#19
0
 public bool Apply(StatePrimitive ancestor, StatePrimitive descendant, TicNode _, TicNode __)
 => descendant.CanBeImplicitlyConvertedTo(ancestor);
示例#20
0
 public bool Apply(StatePrimitive ancestor, StatePrimitive descendant, TicNode _, TicNode __)
 => true;
示例#21
0
 public bool Apply(StatePrimitive ancestor, ConstrainsState descendant, TicNode _, TicNode __)
 => !descendant.HasDescendant || descendant.Descedant.CanBeImplicitlyConvertedTo(ancestor);