Exemplo n.º 1
0
def execute(world_state, action_sequence):
    """Executes an action sequence on a world state.

	TODO: This code assumes the world state is a string. However, you may sometimes
	start with an AlchemyWorldState object. I suggest loading the AlchemyWorldState objects
	into memory in load_data, and moving that part of the code to load_data. The following
	code just serves as an example of how to 1) make an AlchemyWorldState and 2) execute
	a sequence of actions on it.

	Inputs:
		world_state (str): String representing an AlchemyWorldState.
		action_sequence (list of str): Sequence of actions in the format ["action arg1 arg2",...]
			(like in the JSON file).
	"""
    alchemy_world_state = AlchemyWorldState(world_state)
    fsa = AlchemyFSA(alchemy_world_state)

    for action in action_sequence:
        split = action.split(" ")
        act = split[0]
        arg1 = split[1]

        # JSON file doesn't contain  NO_ARG.
        if len(split) < 3:
            arg2 = NO_ARG
        else:
            arg2 = split[2]

        fsa.feed_complete_action(act, arg1, arg2)

    return fsa.world_state()
Exemplo n.º 2
0
 def _create_action_word_encoding(self):
     starter_world_state = AlchemyWorldState(STARTER_STATE)
     fsa = AlchemyFSA(starter_world_state)
     actions = fsa.valid_actions()
     for (i, action) in enumerate(actions):
         for action_word in action:
             if action_word not in self.action_word_to_idx:
                 self.action_word_to_idx[action_word] = len(self.action_word_to_idx)
     self._add_supplementary_tokens(self.action_word_to_idx)
Exemplo n.º 3
0
 def _create_action_encoding(self):
     starter_world_state = AlchemyWorldState(STARTER_STATE)
     fsa = AlchemyFSA(starter_world_state)
     actions = fsa.valid_actions()
     for (i, action) in enumerate(actions):
         action_string = ' '.join(action)
         self.action_to_idx[action_string] = len(self.action_to_idx)
     self._add_supplementary_tokens(self.action_to_idx)
     self.num_actions = len(self.action_to_idx)
Exemplo n.º 4
0
def execute(world_state, action_sequence):
    """Executes an action sequence on a world state.
    Inputs:
        world_state (str): String representing an AlchemyWorldState.
        action_sequence (list of str): Sequence of actions in the format ["action arg1 arg2",...]
            (like in the JSON file).
    """
    alchemy_world_state = AlchemyWorldState(world_state)
    fsa = AlchemyFSA(alchemy_world_state)

    for action in action_sequence:
        split = action.split(" ")
        act = split[0]
        arg1 = split[1]
        if len(split) < 3:
            arg2 = NO_ARG
        else:
            arg2 = split[2]
        fsa.feed_complete_action(act, arg1, arg2)
    return fsa.world_state()
Exemplo n.º 5
0
 def execute_seq(self, actions):
     fsa = AlchemyFSA(self)
     for action in actions:
         peek_state = fsa.peek_complete_action(*action)
         if peek_state:
             fsa.feed_complete_action(*action)
     return fsa.state()