Esempio n. 1
0
    def result(self, state: str, action: Action):
        """ Return the state that results from executing the given
        action in the given state. The action must be one of
        self.actions(state).

        :param state: state entering node
        :param action: Action applied
        :return: resulting state after action
        """
        # TODO implement
        new_state = FluentState([], [])
        kb = PropKB()
        kb.tell(decode_state(state, self.state_map).pos_sentence())
        action.check_precond(kb, action.args)
        action.act(kb, action.args)
        for clause in kb.clauses:
            if kb.ask_if_true:
                new_state.pos.append(clause)
            else:
                new_state.neg.append(clause)
        return encode_state(new_state, self.state_map)
Esempio n. 2
0
    def result(self, state: str, action: Action):
        """ Return the state that results from executing the given
        action in the given state. The action must be one of
        self.actions(state).

        :param state: state entering node
        :param action: Action applied
        :return: resulting state after action
        """
        kb = PropKB()
        kb.tell(decode_state(state, self.state_map).pos_sentence())

        if not action.check_precond(kb, action.args):
            return state
        action.act(kb, action.args)
        new_state = FluentState(kb.clauses, [])

        return encode_state(new_state, self.state_map)
Esempio n. 3
0
    def result(self, state: str, action: Action):
        """ Return the state that results from executing the given
        action in the given state. The action must be one of
        self.actions(state).

        :param state: state entering node
        :param action: Action applied
        :return: resulting state after action
        """
        kb = PropKB()
        curr_state = decode_state(state, self.state_map)
        kb.tell(curr_state.pos_sentence())
        # If the given action cannot be done in the current state,
        # then we return the current state.
        if not action.check_precond(kb, action.args):
            return state
        # Do the action with the current knowledge base.
        action.act(kb, action.args)
        # Construct the new_state straight from the knowledge base.
        new_state = "".join(['T' if kb.ask_if_true(s) else 'F' for s in self.state_map])
        return new_state
Esempio n. 4
0
 def is_possible(action: Action) -> bool:
     return action.check_precond(kb, action.args)