Пример #1
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);
     }
 }
Пример #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);
     }
 }