Пример #1
0
    def __init__(self, IP, AIPort, scenario_name, simulate_compression):
        self.control_noise = True
        self.SERVER_PLAT = "linux"
        self.SERVER_IP = IP
        self.SERVER_PORT = AIPort
        self.connect_mode = 1
        self.DURATION_INTERVAL = etc.DURATION_INTERVAL
        self.simulate_compression = simulate_compression
        self.scenario_name = scenario_name
        self.mozi_service = MoziService(IP,
                                        AIPort,
                                        self.scenario_name,
                                        connect_mode=self.connect_mode)

        self.action_space = 4
        self.action_max = 1
        self.element_item_count = 7
        self.observation_space = 7 * 2

        self.last_situation_time = None
        self.red_unit_list = None
        self.blue_unit_list = None
        self.observation = None
        self.red_side_name = "红方"
        self.blue_side_name = "蓝方"
Пример #2
0
 def connect_mozi_server(self, websocket_Ip, websocket_port):
     """
     连接墨子服务器
     param :
     websocket_server 要连接的服务器的ip
     websocket_port 要连接的服务器的端口
     :return:
     """
     pylog.info("connect_mozi_server")
     if self.connect_mode == 1:
         self.mozi_service = MoziService(websocket_Ip, websocket_port,
                                         self.scenario_name)
         return True
     # server_address = r"ws://%s:%d/websocket" % ('60.205.207.206', 9998)
     server_address = r"ws://%s:%d/websocket" % (websocket_Ip,
                                                 websocket_port)
     pylog.info(server_address)
     for i in range(10):
         try:
             self.websocket_connect = create_connection(server_address)
             break
         except:
             pylog.info("can not connect to %s." % server_address)
             time.sleep(2)
             self.websocket_connect = None
     #
     if self.websocket_connect is None:
         pylog.warning("Interrupted, can not connect to %s." %
                       server_address)
         return False
     #
     self.websocket_connect.send("{\"RequestType\":\"StartServer\"}")
     result = self.websocket_connect.recv()
     print("connect server result:%s" % result)
     jsons = json.loads(result)
     self.ai_server = jsons['IP']
     self.ai_port = jsons['AIPort']
     self.mozi_task = MoziService(self.server_ip, self.aiPort,
                                  self.scenario_name)
     return True