async def play(self, ws, observation):
        success = True
        request_data = api.Request(
            data=api.RequestData(ability_id=True, unit_type_id=True, upgrade_id=True)
        )
        await asyncio.wait_for(ws.send(request_data.SerializeToString()), 5)
        try:
            result = await asyncio.wait_for(ws.recv(), 5)
            data_response = api.Response.FromString(result)
            game_data = data_response.data

            request_game_info = api.Request(game_info=api.RequestGameInfo())
            await asyncio.wait_for(ws.send(request_game_info.SerializeToString()), 5)
            result = await asyncio.wait_for(ws.recv(), 5)
            game_info_response = api.Response.FromString(result)

            # If game is still on
            if game_data.units:
                obj = decode_observation(observation.observation.observation, game_data, game_info_response)
                obs = MessageToDict(observation)
                obs = str(obs)
                obs = obs.replace("\'", "\"")
                obs = obs.replace("False", "false")
                obs = obs.replace("True", "true")
                obs = json.loads(obs,encoding="UTF-8")
                game_meta = api.Request(
                    game_info=api.RequestGameInfo()
                )
                await ws.send(game_meta.SerializeToString())
                result = await ws.recv()
                game_meta = api.Response.FromString(result)
                game_meta = MessageToDict(game_meta)
                game_meta = str(game_meta)
                game_meta = game_meta.replace("\'", "\"")
                game_meta = game_meta.replace("False", "false")
                game_meta = game_meta.replace("True", "true")
                game_meta = json.loads(game_meta,encoding="UTF-8")
                game_meta = game_meta.get("gameInfo", None)
                game_meta.pop("modNames")
                game_meta.pop("options")
                game_meta.pop("mapName")
                if("localMapPath" in game_meta.keys()):
                    game_meta.pop("localMapPath")
                game_meta.pop("playerInfo")
                game_meta.update(game_meta["startRaw"])
                game_meta.pop("startRaw")
                game_meta.pop("mapSize")
                await self.process_step(ws, obj, raw=(obs, game_meta, game_data))
                # function = self.decision_function
                # alvailable_actions = self.query_alvailable_actions()
                # to_do_action = function(observation, alvailable_actions)
                # while(to_do_action and alvailable_actions):
                #    self.send_order(self, to_do_action)
                #    to_do_action = self.query_alvailable_actions()
        except asyncio.TimeoutError:
            return False
        return True
Exemple #2
0
def multiPanel(panel_type, unit_index):
    # log.debug("Multi Panel:\ntype=%d\nunit_index=%d" % (panel_type, unit_index))
    request = sc2api_pb2.Request()
    action = request.action.actions.add()
    action.action_ui.multi_panel.type = panel_type
    action.action_ui.multi_panel.unit_index = unit_index
    return request
Exemple #3
0
def controlGroupRecall(action_input, index):
    # log.debug("Control Group Recall:\naction=%d\nindex=%d" % (action, index))
    request = sc2api_pb2.Request()
    action = request.action.actions.add()
    action.action_ui.control_group.action = action_input
    action.action_ui.control_group.control_group_index = index
    return request
Exemple #4
0
def unitSelectPoint(x, y, click_type):
    # log.debug("Selecting Point:\nx=%d\ny=%d\nclick_type=%d" % (x, y, click_type))
    request = sc2api_pb2.Request()
    action = request.action.actions.add()
    action.action_feature_layer.unit_selection_point.selection_screen_coord.x = x
    action.action_feature_layer.unit_selection_point.selection_screen_coord.y = y
    action.action_feature_layer.unit_selection_point.type = click_type
    return request
Exemple #5
0
def moveCamera(x, y):
    # log.debug("Moving Camera:\nx-axis=%d\ny-axis=%d" % (x, y))
    request = sc2api_pb2.Request()
    action = request.action.actions.add()
    action.action_feature_layer.camera_move.center_minimap.x = x
    action.action_feature_layer.camera_move.center_minimap.y = y
    #print(request.ListFields()) #For debugging
    return request
Exemple #6
0
def chat(message):
    # log.debug("Sending message to all chat:\n%s" % message)
    request = sc2api_pb2.Request()
    action = request.action.actions.add()
    action_chat = action.chat.add()
    action_chat.message = message
    action_chat.channel = sc2api_pb2.ActionChat.Broadcast
    #print(request.ListFields()) #For debugging
    return request
Exemple #7
0
def unitCommandMinimap(ability_id, x, y, queue_command):
    # log.debug("Unit Command Screen:\nability_id=%d\nx=%d\ny=%d\queue_command=%r"
    #             % (ability_id, x, y, queue_command))
    request = sc2api_pb2.Request()
    action = request.action.actions.add()
    action.action_feature_layer.unit_command.ability_id = ability_id
    action.action_feature_layer.unit_command.target_minimap_coord.x = x
    action.action_feature_layer.unit_command.target_minimap_coord.y = y
    action.action_feature_layer.unit_command.queue_command = queue_command
    return request
Exemple #8
0
def unitSelectScreenArea(x_start, y_start, x_end, y_end, add):
    # log.debug("Selecting Screen Area:\nx_start=%d\ny_start=%d\nx_end=%d\ny_end=%d\nadd=%r" %
    #             (x_start, y_start, x_end, y_end, add))
    request = sc2api_pb2.Request()
    action = request.action.actions.add()
    screen_selection = action.action_feature_layer.unit_selection_rect.selection_screen_coord.add(
    )
    screen_selection.p0.x = x_start
    screen_selection.p0.y = y_start
    screen_selection.p1.x = x_end
    screen_selection.p1.y = y_end
    action.action_feature_layer.unit_selection_rect.selection_add = add
    return request