Class Effect

java.lang.Object
edu.uky.cs.nil.tt.world.Effect
All Implemented Interfaces:
Logical

public class Effect extends Object implements Logical
An effect is a logical formula that describes one way that an action modifies one state variable.
Author:
Stephen G. Ware
  • Field Details

    • condition

      public final Proposition condition
      A condition which, if true, means this effect will occur
    • variable

      public final Variable variable
      The variable whose value will be modified
    • value

      public final Expression value
      The value or expression whose value will be assigned to the variable
  • Constructor Details

    • Effect

      public Effect(Proposition condition, Variable variable, Expression value)
      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 changed
      value - an expression whose value will be assigned to the variable
    • Effect

      public Effect(Variable variable, Expression value)
      Constructs a new effect with a variable and value and whose condition is null.
      Parameters:
      variable - the variables whose value will be changed
      value - an expression whose value will be assigned to the variable
  • Method Details

    • toString

      public static String toString(Effect[] effects)
      Converts an array of effects to a string, similar in format to a conjunction.
      Parameters:
      effects - the effects to convert to a string
      Returns:
      a string representation of the effects
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • substitute

      public Effect substitute(Function<Object,Object> substitution)
      Description copied from interface: Logical
      Returns 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:
      substitute in interface Logical
      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

      public State apply(State before, State after)
      If this effect's condition holds, this method applies this effect's change to a given state. Specifically, if this effect's condition is null or if it evaluates to true in the state before this effect would occur, this method returns a copy of the given state with this effect's variable set to this effect's value. 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 in
      after - 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