def connect(self, timeout=600): RemoteEnvironment.connect(self, timeout) # Get action- and state-specs from our game. self.protocol.send({"cmd": "get_spec"}, self.socket) response = self.protocol.recv(self.socket, "utf-8") # Game's name self.game_name = response.get("game_name") # keep non-mandatory for now # Observers if "observation_space_desc" not in response: raise TensorForceError("Response to `get_spec` does not contain field `observation_space_desc`!") self.observation_space_desc = response["observation_space_desc"] # Action-mappings if "action_space_desc" not in response: raise TensorForceError("Response to `get_spec` does not contain field `action_space_desc`!") self.action_space_desc = response["action_space_desc"] if self.discretize_actions: self.discretize_action_space_desc() # Invalidate our states- and actions caches. if "states" in self.__dict__: del self.__dict__["states"] if "actions" in self.__dict__: del self.__dict__["actions"]
def connect(self): RemoteEnvironment.connect(self) # Get action- and state-specs from our game. self.protocol.send({"cmd": "get_spec"}, self.socket) response = self.protocol.recv(self.socket) if "observation_space_desc" not in response or "action_space_desc" not in response: raise TensorForceError( "ERROR in UE4Environment.connect: no observation- or action-space-desc sent " "by remote server!") # observers self.observation_space_desc = response["observation_space_desc"] # action-mappings self.action_space_desc = response["action_space_desc"] if self.discretize_actions: self.discretize_action_space_desc() # Invalidate our states- and actions caches. if "states" in self.__dict__: del self.__dict__["states"] if "actions" in self.__dict__: del self.__dict__["actions"]
def __init__( self, host="localhost", port=6025, connect=True, discretize_actions=False, delta_time=1/60, num_ticks=4 ): """ Args: host (str): The hostname to connect to. port (int): The port to connect to. connect (bool): Whether to connect already in this c'tor. discretize_actions (bool): Whether to treat axis-mappings defined in UE4 game as discrete actions. This would be necessary e.g. for agents that use q-networks where the output are q-values per discrete state-action pair. delta_time (float): The fake delta time to use for each single game tick. num_ticks (int): The number of ticks to be executed in a single act call (each tick will repeat the same given actions). """ RemoteEnvironment.__init__(self, host, port) # RemoteEnvironment should send a name of the game upon connection. self.game_name = None self.action_space_desc = None self.observation_space_desc = None self.discretize_actions = discretize_actions self.discretized_actions = None self.delta_time = delta_time self.num_ticks = num_ticks # Our tcp messaging protocol to use (simple len-header + msgpack-numpy-body). self.protocol = MsgPackNumpyProtocol() if connect: self.connect()