/// <summary> /// Applies the effect backwards to the given conditions. /// </summary> /// <param name="conditions">Conditions.</param> public override IConditions ApplyBackwards(IConditions conditions) { if (IsRelevant(conditions) == EffectRelevance.RELEVANT) { IConditions newConditions = (IConditions)conditions.Clone(); newConditions.RemoveConstraint(Assignment); newConditions = newConditions.ConjunctionWith(Conditions); return(conditions.DisjunctionWith(newConditions)); } return(conditions); }
/// <summary> /// Applies the operator backwards to the given target conditions. The result is a new set of conditions. /// </summary> /// <param name="conditions">Conditions for the application.</param> /// <param name="operatorPreconditions">Operator preconditions.</param> /// <returns>Preceding conditions.</returns> public IConditions ApplyBackwards(IConditions conditions, ISimpleConditions operatorPreconditions) { IConditions newConditions = (IConditions)conditions.Clone(); foreach (var effect in this) { newConditions = effect.ApplyBackwards(newConditions); } newConditions = newConditions.ConjunctionWith(operatorPreconditions); return(newConditions); }
/// <summary> /// Creates a conjunction of the current conditions and the specified other conditions. /// </summary> /// <param name="other">Other conditions.</param> /// <returns>Conjunction of the current conditions and the given other conditions.</returns> public IConditions ConjunctionWith(IConditions other) { if (other is ConditionsClause || other is ConditionsContradiction) { return(other.ConjunctionWith(this)); } Conditions otherConditions = other as Conditions; Debug.Assert(otherConditions != null); if (IsConflictedWith(otherConditions)) { return(new ConditionsContradiction()); } Conditions conditions = (Conditions)Clone(); conditions.AddConditions(otherConditions); return(conditions); }