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); }
/// <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); } }
// 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); } }
/// <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); } }
public static bool IntBigger_IsBetterOP(StructValue effect, StructValue curState, StructValue target) { int vSelf = Convert.ToInt32(effect.v); return(vSelf > 0); }
public static bool IntGreaterEqual_IsFulfilledByOP(StructValue goal, StructValue other) { return(Convert.ToInt32(goal.v) >= Convert.ToInt32(other.v)); }
public static bool DefaultIsBetterOP(StructValue self, StructValue other, StructValue target) { return(Equals(self.v, target.v)); }
public static bool EqualMatchOP(StructValue self, StructValue other) { return(Equals(self.v, other.v)); }
public static StructValue KeepDiffOp(StructValue self, StructValue other) { return(self); }
public static StructValue ReplaceMergeOP(StructValue self, StructValue other) { return(other); }
public bool IsFulfilledBy(StructValue other) { return(isFulfilledByOP(this, other)); }
public StructValue DiffWith(StructValue other) { var newOne = diffOp(this, other); return(newOne); }
//public static implicit operator W(StructValue st) //{ // return (W)st.v; //} public StructValue MergeWith(StructValue other) { var newOne = mergeOp(this, other); return(newOne); }
public static StructValue CopyCreate(ref StructValue proto, object v) { return(Create(v, proto.mergeOp, proto.diffOp, proto.isFulfilledByOP, proto.isBetterOp, proto.tp)); }
public static bool IntSmaller_IsBetterOP(StructValue effect, StructValue curState, StructValue target) { int vEff = Convert.ToInt32(effect.v); return(vEff < 0); }
public static bool FloatSmaller_IsBetterOP(StructValue effect, StructValue curState, StructValue target) { float vEffect = Convert.ToSingle(effect.v); return(vEffect < 0); }
public bool IsBetter(StructValue other, StructValue target) { return(isBetterOp(this, other, target)); }