def agent_state(self) -> Dict[str, Union[Dict[str, float], float]]: """Return agent position, rotation and horizon.""" return { **str_to_pos_for_cache(self.agent_position), "rotation": { "x": 0.0, "y": self.agent_rotation, "z": 0.0 }, "horizon": 1.0, }
def step( self, action_dict: Dict[str, Union[str, int, float]]) -> ai2thor.server.Event: """Take a step in the ai2thor environment.""" self._last_action = action_dict["action"] if action_dict["action"] == "RotateLeft": self.agent_rotation = (self.agent_rotation - 90.0) % 360.0 elif action_dict["action"] == "RotateRight": self.agent_rotation = (self.agent_rotation + 90.0) % 360.0 elif action_dict["action"] == "MoveAhead": pos = str_to_pos_for_cache(self.agent_position) if self.agent_rotation == 0.0: pos["x"] += 0.25 elif self.agent_rotation == 90.0: pos["z"] += 0.25 elif self.agent_rotation == 180.0: pos["x"] -= 0.25 elif self.agent_rotation == 270.0: pos["z"] -= 0.25 pos_string = pos_to_str_for_cache(pos) if pos_string in self.view_cache: self.agent_position = pos_to_str_for_cache(pos) return self.last_event
def to_pos(s): if isinstance(s, (Dict, Tuple)): return s if isinstance(s, float): return {"x": 0, "y": s, "z": 0} return str_to_pos_for_cache(s)
def currently_reachable_points(self) -> List[Dict[str, float]]: """List of {"x": x, "y": y, "z": z} locations in the scene that are currently reachable.""" return [str_to_pos_for_cache(pos) for pos in self.view_cache]