diff --git a/Gym_new.py b/Gym_new.py index 94537764944b3909dff96b06ef5a008166c2ce25..c67dc38c70db3d62e41fee106ab8f3a6b0a9a4ba 100644 --- a/Gym_new.py +++ b/Gym_new.py @@ -24,48 +24,50 @@ class Gym: self.logger.addHandler(logging.StreamHandler()) print('New gym instance IP:', host, 'Port:', port, 'Playername:', player) - # Call reset function of environment and returns observation + # Call reset function of environment and returns observation, reward, done, info # Send data to reset enviroment async def reset(self, delta): message = json.dumps([['reset'], delta], sort_keys=True, indent=4) data = [] await self.send_websocket(message, data) - test = json.loads(data[0]) - reward = test[3] - observation = test[0:3] - done = test[4] - info = 0 + all_information = json.loads(data[0]) + reward = all_information[3] + observation = all_information[0:3] + done = all_information[4] + info = all_information[5] return observation, reward, done, info # send action to env returns observation, reward, done, info + # Obeservation is an array with the following information: + # [speed, steering-angle, [length of all sensors (starting straight and then clockwise around the car)]] # creates JSON object async def step(self, action, delta): global maxaction - test_message = [] + message = [] if action.find("accelerate")!=-1: - test_message.append( "accelerate") + message.append( "accelerate") if action.find("left")!= -1: - test_message.append( "steer_left") + message.append( "steer_left") if action.find("right")!= -1: - test_message.append("steer_right") + message.append("steer_right") if action.find("brake")!= -1: - test_message.append("brake") + message.append("brake") if action.find("reverse")!= -1: - test_message.append("reverse") + message.append("reverse") if action.find("screen_on")!= -1: - test_message.append("screen_on") + message.append("screen_on") if action.find("screen_off")!= -1: - test_message.append("screen_off") + message.append("screen_off") - message = json.dumps([test_message,delta], sort_keys=True, indent=4) + message = json.dumps([message,delta], sort_keys=True, indent=4) data = [] await self.send_websocket(message, data) - test = json.loads(data[0]) - reward = test[3] - observation = test[0:3] - done = test[4] - info = test[5] + all_information = json.loads(data[0]) + reward = all_information[3] + observation = all_information[0:3] + done = all_information[4] + info = all_information[5] return observation, reward, done, info async def connect_websocket(self):