Class Effect
java.lang.Object
edu.uky.cs.nil.tt.world.Effect
- All Implemented Interfaces:
Logical
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal PropositionA condition which, if true, means this effect will occurfinal ExpressionThe value or expression whose value will be assigned to the variablefinal VariableThe variable whose value will be modified -
Constructor Summary
ConstructorsConstructorDescriptionEffect(Proposition condition, Variable variable, Expression value) Constructs a new effect with a condition, variable, and value.Effect(Variable variable, Expression value) Constructs a new effect with a variable and value and whose condition isnull. -
Method Summary
Modifier and TypeMethodDescriptionIf this effect'sconditionholds, this method applies this effect's change to a given state.booleaninthashCode()substitute(Function<Object, Object> substitution) Returns a logical object identical to this one, except that its logical elements have been replaced according to the given substitution.toString()static StringConverts an array of effects to a string, similar in format to aconjunction.
-
Field Details
-
condition
A condition which, if true, means this effect will occur -
variable
The variable whose value will be modified -
value
The value or expression whose value will be assigned to the variable
-
-
Constructor Details
-
Effect
Constructs a new effect with a condition, variable, and value.- Parameters:
condition- a condition which, if true, means the effect will occur, and if false, means the condition will not occur, and if null, will be ignored (treated like it is true)variable- the variables whose value will be changedvalue- an expression whose value will be assigned to the variable
-
Effect
Constructs a new effect with a variable and value and whose condition isnull.- Parameters:
variable- the variables whose value will be changedvalue- an expression whose value will be assigned to the variable
-
-
Method Details
-
toString
Converts an array of effects to a string, similar in format to aconjunction.- Parameters:
effects- the effects to convert to a string- Returns:
- a string representation of the effects
-
equals
-
hashCode
-
toString
-
substitute
Description copied from interface:LogicalReturns a logical object identical to this one, except that its logical elements have been replaced according to the given substitution. A substitution defines how some logical formula (the input to the function) should be replaced with a different formula (the output of the function).- Specified by:
substitutein interfaceLogical- Parameters:
substitution- a function which maps logical formula that should be replaced to the formula they should be replaced with- Returns:
- an identical object, except that its logical formula have been replaced according to the substitution
-
apply
If this effect'sconditionholds, this method applies this effect's change to a given state. Specifically, if this effect's condition is null or if itevaluatestotruein the state before this effect would occur, this method returns a copy of the given state with this effect'svariableset to this effect'svalue. Evaluating the condition and the value both happen in the state before this effect is applied, and the effect is applied to the state after.- Parameters:
before- the state in which this effect's condition and value will be evaluated inafter- the state to which this effect will be applied (this state will not be modified by this method)- Returns:
- a copy of the after state with this effect's variable set to this effect's value (if the condition was null or hold in the before state), or the after state if the condition does not hold in the before state
-