# Path: planner/effects.py
# class ValueEffect(Effect):
#   def __init__(self, value):
#     super(self.__class__, self).__init__()
#     self.value = value
#   def __call__(self, *args):
#     return self.value
#   def __repr__(self):
#     return 'VE' + str_object((self.value,))
# 
# Path: planner/conditions.py
# class SubstateCondition(Condition):
#   def __init__(self, substate):
#     super(self.__class__, self).__init__()
#     self.substate = substate
#     self.variables = frozenset(substate.variables())
#   def __contains__(self, substate):
#     return all(var in substate and substate[var] == value for var, value in self.substate)
#   def __str__(self):
#     return 'SC' + str_args(self.substate.__dict__['__hash_dict'])
#   __repr__ = __str__


from .states import *
from misc.utils import *
from .effects import ValueEffect
from .conditions import SubstateCondition
    from strips.operators import derive_state

class Operator(object):
  def __init__(self, args):
    self.args = args
    for k, v in args.items():
      setattr(self, k, v)
    self.conditions = []
    self.effects = {}
  def __contains__(self, state):
    return all(state in precondition for precondition in self.conditions)
  def apply(self, state):
    return State(dict(list(state) + [(var, effect(state)) for var, effect in self.effects.items()]))
  def __call__(self, state):
    if state not in self: return None
    return self.apply(state)
  def __iter__(self):
    yield self
  def __len__(self):
    return 1
  def fixed_conditions(self):
    fc = {}
    for condition in self.conditions:
      if isinstance(condition, SubstateCondition):
        for var, value in condition.substate:
          if var in fc and fc[var] != value:
            raise RuntimeError('Condition has conflicting conditions')
          fc[var] = value
    return fc
  def fixed_effects(self):
    return {var: effect.value for var, effect in self.effects.items()

# Path: planner/effects.py
# class ValueEffect(Effect):
#   def __init__(self, value):
#     super(self.__class__, self).__init__()
#     self.value = value
#   def __call__(self, *args):
#     return self.value
#   def __repr__(self):
#     return 'VE' + str_object((self.value,))
# 
# Path: planner/conditions.py
# class SubstateCondition(Condition):
#   def __init__(self, substate):
#     super(self.__class__, self).__init__()
#     self.substate = substate
#     self.variables = frozenset(substate.variables())
#   def __contains__(self, substate):
#     return all(var in substate and substate[var] == value for var, value in self.substate)
#   def __str__(self):
#     return 'SC' + str_args(self.substate.__dict__['__hash_dict'])
#   __repr__ = __str__


# Path: planner/operators.py
from .states import *
from misc.utils import *
from .effects import ValueEffect
from .conditions import SubstateCondition
    from strips.operators import derive_state


class Operator(object):
  def __init__(self, args):
    self.args = args
    for k, v in args.items():
      setattr(self, k, v)
    self.conditions = []
    self.effects = {}
  def __contains__(self, state):
    return all(state in precondition for precondition in self.conditions)
  def apply(self, state):
    return State(dict(list(state) + [(var, effect(state)) for var, effect in self.effects.items()]))
  def __call__(self, state):
    if state not in self: return None
    return self.apply(state)
  def __iter__(self):
    yield self
  def __len__(self):
    return 1
  def fixed_conditions(self):
    fc = {}
    for condition in self.conditions:
      if isinstance(condition, SubstateCondition):
        for var, value in condition.substate:
          if var in fc and fc[var] != value:
            raise RuntimeError('Condition has conflicting conditions')
          fc[var] = value
    return fc
  def fixed_effects(self):
    return {var: effect.value for var, effect in self.effects.items()

            if isinstance(effect, ValueEffect)}