Esempio n. 1
0
        public static StructValue Create(object v,
                                         Func <StructValue, StructValue, StructValue> mergeOp,
                                         Func <StructValue, StructValue, StructValue> diffOp,
                                         Func <StructValue, StructValue, bool> isFulFilledByOP,
                                         Func <StructValue, StructValue, StructValue, bool> isBetterOp,
                                         EValueType tp
                                         )
        {
            var o = new StructValue();

            o.v               = v;
            o.mergeOp         = mergeOp;
            o.diffOp          = diffOp;
            o.isFulfilledByOP = isFulFilledByOP;
            o.isBetterOp      = isBetterOp;
            o.tp              = tp;
            return(o);
        }
Esempio n. 2
0
 /// <summary>
 /// write into 'difference', anything in 'this' and not fulfilled by 'other'
 /// </summary>
 public int MissingDifference(ReGoapState <T, W> other, ref ReGoapState <T, W> difference, int stopAt = int.MaxValue)
 {
     lock (values)
     {
         var count = 0;
         foreach (var pair in values)
         {
             T           key       = pair.Key;
             StructValue thisValue = pair.Value;
             StructValue otherValue;
             bool        hasOtherValue = other.values.TryGetValue(key, out otherValue);
             if (
                 !hasOtherValue ||                    //not exist in other
                 !thisValue.IsFulfilledBy(otherValue) //not fulfilled by other
                 )
             {
                 count++;
                 if (difference != null)
                 {
                     if (hasOtherValue)
                     {
                         difference.values[key] = thisValue.DiffWith(otherValue);
                     }
                     else
                     {
                         difference.values[key] = thisValue;
                     }
                 }
                 if (count >= stopAt)
                 {
                     break;
                 }
             }
         }
         return(count);
     }
 }
Esempio n. 3
0
 // keep only missing differences in values
 public int ReplaceWithMissingDifference(ReGoapState <T, W> other, int stopAt = int.MaxValue, Func <KeyValuePair <T, W>, W, bool> predicate = null, bool test = false)
 {
     lock (values)
     {
         var count  = 0;
         var buffer = values;
         values = values == bufferA ? bufferB : bufferA;
         values.Clear();
         foreach (var pair in buffer)
         {
             T           key       = pair.Key;
             StructValue thisValue = pair.Value;
             StructValue otherValue;
             bool        hasOtherValue = other.values.TryGetValue(key, out otherValue);
             if (
                 !hasOtherValue || //not exist in other
                 !thisValue.IsFulfilledBy(otherValue)     //not fulfilled by other
                 )
             {
                 count++;
                 if (hasOtherValue)
                 {
                     values[key] = thisValue.DiffWith(otherValue);
                 }
                 else
                 {
                     values[key] = thisValue;
                 }
                 if (count >= stopAt)
                 {
                     break;
                 }
             }
         }
         return(count);
     }
 }
Esempio n. 4
0
 /// <summary>
 ///
 /// </summary>
 public int MissingDifference(ReGoapState <T, W> curState, int stopAt = int.MaxValue)
 {
     lock (values)
     {
         var count = 0;
         foreach (var pair in values)
         {
             StructValue precondValue = pair.Value;
             StructValue curValue;
             if (
                 !curState.values.TryGetValue(pair.Key, out curValue) || //current-state doesn't have corresponding entry for this precond
                 !precondValue.IsFulfilledBy(curValue)                   //current-state doesn't fullfil this precond
                 )
             {
                 count++;
                 if (count >= stopAt)
                 {
                     break;
                 }
             }
         }
         return(count);
     }
 }
Esempio n. 5
0
        public static bool IntBigger_IsBetterOP(StructValue effect, StructValue curState, StructValue target)
        {
            int vSelf = Convert.ToInt32(effect.v);

            return(vSelf > 0);
        }
Esempio n. 6
0
 public static bool IntGreaterEqual_IsFulfilledByOP(StructValue goal, StructValue other)
 {
     return(Convert.ToInt32(goal.v) >= Convert.ToInt32(other.v));
 }
Esempio n. 7
0
 public static bool DefaultIsBetterOP(StructValue self, StructValue other, StructValue target)
 {
     return(Equals(self.v, target.v));
 }
Esempio n. 8
0
 public static bool EqualMatchOP(StructValue self, StructValue other)
 {
     return(Equals(self.v, other.v));
 }
Esempio n. 9
0
 public static StructValue KeepDiffOp(StructValue self, StructValue other)
 {
     return(self);
 }
Esempio n. 10
0
 public static StructValue ReplaceMergeOP(StructValue self, StructValue other)
 {
     return(other);
 }
Esempio n. 11
0
 public bool IsFulfilledBy(StructValue other)
 {
     return(isFulfilledByOP(this, other));
 }
Esempio n. 12
0
        public StructValue DiffWith(StructValue other)
        {
            var newOne = diffOp(this, other);

            return(newOne);
        }
Esempio n. 13
0
        //public static implicit operator W(StructValue st)
        //{
        //    return (W)st.v;
        //}

        public StructValue MergeWith(StructValue other)
        {
            var newOne = mergeOp(this, other);

            return(newOne);
        }
Esempio n. 14
0
 public static StructValue CopyCreate(ref StructValue proto, object v)
 {
     return(Create(v, proto.mergeOp, proto.diffOp, proto.isFulfilledByOP, proto.isBetterOp, proto.tp));
 }
Esempio n. 15
0
        public static bool IntSmaller_IsBetterOP(StructValue effect, StructValue curState, StructValue target)
        {
            int vEff = Convert.ToInt32(effect.v);

            return(vEff < 0);
        }
Esempio n. 16
0
        public static bool FloatSmaller_IsBetterOP(StructValue effect, StructValue curState, StructValue target)
        {
            float vEffect = Convert.ToSingle(effect.v);

            return(vEffect < 0);
        }
Esempio n. 17
0
 public bool IsBetter(StructValue other, StructValue target)
 {
     return(isBetterOp(this, other, target));
 }