Beispiel #1
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);
     }
 }
Beispiel #2
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);
     }
 }
Beispiel #3
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);
     }
 }