Пример #1
0
        public static StructValue FloatSub_DiffOp(StructValue self, StructValue other)
        {
            float       v      = Convert.ToSingle(self.v) - Convert.ToSingle(other.v);
            StructValue newOne = StructValue.CopyCreate(ref self, v);

            return(newOne);
        }
Пример #2
0
        public static StructValue FloatAdd_MergeOP(StructValue self, StructValue other)
        {
            float       v      = Convert.ToSingle(self.v) + Convert.ToSingle(other.v);
            StructValue newOne = StructValue.CopyCreate(ref self, v);

            return(newOne);
        }
Пример #3
0
        public static StructValue IntAdd_MergeOP(StructValue self, StructValue other)
        {
            int         v      = Convert.ToInt32(self.v) + Convert.ToInt32(other.v);
            StructValue newOne = StructValue.CopyCreate(ref self, v);

            return(newOne);
        }
Пример #4
0
        public static StructValue IntSub_DiffOp(StructValue self, StructValue other)
        {
            int         v      = Convert.ToInt32(self.v) - Convert.ToInt32(other.v);
            StructValue newOne = StructValue.CopyCreate(ref self, v);

            return(newOne);
        }
Пример #5
0
        /// <summary>
        ///
        /// if all arithmetic values don't make the better towards goal
        ///     return true;
        /// else
        ///     return false;
        ///
        /// </summary>
        public bool IsNotHelpfulAtAll(ReGoapState <T, W> effect, ReGoapState <T, W> precond, ReGoapState <T, W> curState)
        {
            lock (values) lock (effect.values)
                {
                    bool nonHelpful = true;
                    foreach (var pair in effect.values)
                    {
                        T           key         = pair.Key;
                        StructValue effectValue = pair.Value;
                        StructValue curStateValue;

                        if (effectValue.tp == StructValue.EValueType.Arithmetic)
                        {
                            StructValue goalValue;
                            curState.values.TryGetValue(key, out curStateValue);

                            if (values.TryGetValue(key, out goalValue))
                            {// if a goal is satisfied already, then this effect is not useful (not really, but this helps to prune the search tree)
                                if (goalValue.IsFulfilledBy(effectValue))
                                {
                                    var defValue = StructValue.CopyCreate(ref goalValue, 0);
                                    if (!goalValue.IsFulfilledBy(defValue)) //if the goal has just been satified by this effect, okay
                                    {                                       //e.g: for non-neg int, goalValue > 0
                                        nonHelpful = false;
                                        break;
                                    }
                                }
                                else if (effectValue.IsBetter(curStateValue, goalValue)) //not fulfill the target, but make it better towards target
                                {
                                    nonHelpful = false;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            StructValue goalValue;
                            if (values.TryGetValue(key, out goalValue))
                            {
                                if (goalValue.IsFulfilledBy(effectValue))
                                {
                                    curState.values.TryGetValue(key, out curStateValue);
                                    if (!curStateValue.Inited || !goalValue.IsFulfilledBy(curStateValue))
                                    {
                                        nonHelpful = false;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    return(nonHelpful);
                }
        }