Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. def get_world_observations(agent_host):
  2. """ get world observations from the agent's most recent world state
  3. args: malmo agent host (created beforehand in an outer scope)
  4. return: world observation (dict of info:value)
  5. """
  6. world_state = agent_host.peekWorldState()
  7. while True:
  8.  
  9. # valid world state: get observations
  10. if world_state.number_of_observations_since_last_state > 0:
  11. msg = world_state.observations[-1].text
  12. obs = json.loads(msg)
  13.  
  14. # check for any errors
  15. for err in world_state.errors:
  16. logging.error(err)
  17. if "entities" not in obs:
  18. logging.error("no entities in the world")
  19. exit(1)
  20.  
  21. return obs
  22.  
  23. # invalid world state: get another one asap
  24. else:
  25. world_state = agent_host.getWorldState()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement