コード例 #1
0
        /// <summary>
        /// Processes primitive effects.
        /// </summary>
        /// <param name="relativeState">Relative state to be modified.</param>
        private void ProcessPrimitiveEffects(IRelativeState relativeState)
        {
            foreach (var positivePredicate in Effects.GroundedPositivePredicateEffects)
            {
                if (relativeState.HasPredicate(positivePredicate))
                {
                    relativeState.RemovePredicate(positivePredicate);
                }
            }

            foreach (var negatedPredicate in Effects.GroundedNegativePredicateEffects)
            {
                if (relativeState.HasNegatedPredicate(negatedPredicate))
                {
                    relativeState.RemoveNegatedPredicate(negatedPredicate);
                }
            }

            foreach (var objectFunction in Effects.GroundedObjectFunctionAssignmentEffects)
            {
                var groundedValue = GroundingManager.GroundTermDeep(objectFunction.Value, OperatorSubstitution, relativeState);

                ConstantTerm constantValue = groundedValue as ConstantTerm;
                if (constantValue != null)
                {
                    if (relativeState.GetObjectFunctionValue(objectFunction.Key) == constantValue.NameId)
                    {
                        relativeState.AssignObjectFunction(objectFunction.Key, ObjectFunctionTerm.UndefinedValue);
                    }
                }
            }

            foreach (var numericFunction in Effects.GroundedNumericFunctionAssignmentEffects)
            {
                NumericAssignmentsBackwardsReplacer replacer = new NumericAssignmentsBackwardsReplacer(Effects.GroundedNumericFunctionAssignmentEffects, GroundingManager, OperatorSubstitution, new Substitution());
                INumericExpression reducedAssignExpression   = replacer.Replace(numericFunction.Value);

                Number assignNumber = reducedAssignExpression as Number;
                if (assignNumber != null)
                {
                    if (relativeState.GetNumericFunctionValue(numericFunction.Key).Equals(assignNumber.Value))
                    {
                        relativeState.AssignNumericFunction(numericFunction.Key, NumericFunction.UndefinedValue);
                    }
                }
            }
        }