Exemple #1
0
def parse_healthbars_legacy(top_to_bottom, bottom_to_top, debug=None):
    """
    Determines the health of each player.

    Requires two passes (from top to bottom, bottom to top) to determine all the player healths.

    :param top_to_bottom:
    :param bottom_to_top:
    :param debug:
    :return: list of tuples containing (name, health)
    """
    healthbars = []
    for img in [top_to_bottom, bottom_to_top]:
        for player in range(0, 8):
            name_config = '--psm 7 --oem 3'
            health_config = '--psm 7 -c tessedit_char_whitelist=1234567890 -c load_system_dawg=false -c load_freq_dawg=false'
            name = _parse_image_for_text(img[0][player], name_config, 1, debug, debugger.ParseHealthbars)
            health = utils.convert_string_to_integer(
                _parse_image_for_text(img[1][player], health_config, 1, debug, debugger.ParseHealthbars))
            if health != -1:
                healthbars.append((name, int(health)))
    return healthbars
Exemple #2
0
def parse_healthbars(imgs, debug=None):
    """
    Determines the health of each player.

    :param imgs:
    :param debug:
    :return: list of tuples containing (name, health)
    """
    healthbars = []
    for player in list(zip(imgs[0], imgs[1])):
        name_config = '--psm 7 --oem 3'
        health_config = '--psm 7 -c tessedit_char_whitelist=1234567890'
        name = ""
        if player[0] is not None:
            name = _parse_image_for_text(player[0], name_config, 1, debug, debugger.ParseHealthbars)
        health = utils.convert_string_to_integer(
            _parse_image_for_text(player[1], health_config, 4, debug, debugger.ParseHealthbars))
        if health != -1:
            healthbars.append((name, int(health)))
        else:
            cleaned_name = utils.clean_string(name)
            if cleaned_name.isdigit():
                healthbars.append(("", int(cleaned_name)))
    return healthbars
Exemple #3
0
def parse_gold(img, debug=None):
    config = '--psm 8 --oem 3 -c tessedit_char_whitelist=1234567890'
    return utils.convert_string_to_integer(_parse_image_for_text(img, config, 1, debug, debugger.ParseGold))
Exemple #4
0
def run_complete_parser_test(testcase, img, data, gameBoard):
    if "shop" in data:
        shop = parser.parse_shop(board.crop_shop(img, gameBoard),
                                 testcase.debug)
        shop = [
            utils.find_matching_string_in_list(unit, testcase.unit_lookup)
            for unit in shop
        ]
        print("Asserting shop: {}".format(shop))
        testcase.assertEqual(data["shop"], shop)
    if "level" in data:
        level = parser.parse_level(board.crop_level(img, gameBoard),
                                   testcase.debug)
        print("Asserting level: {}".format(level))
        testcase.assertEqual(data["level"], level)
    if "stage" in data:
        stage = parser.parse_stage(board.crop_stage(img, gameBoard),
                                   testcase.debug)
        if not utils.assert_stage_string_format(stage):
            stage = parser.parse_stage(board.crop_stage_early(img, gameBoard),
                                       testcase.debug)
        print("Asserting stage: {}".format(stage))
        testcase.assertEqual(data["stage"], stage)
    if "timer" in data:
        timer = parser.parse_timer(board.crop_timer(img, gameBoard),
                                   testcase.debug)
        if timer == -1:
            timer = parser.parse_timer(board.crop_timer_early(img, gameBoard),
                                       testcase.debug)
        print("Asserting timer: {}".format(timer))
        testcase.debug.show()
        testcase.assertEqual(data["timer"], timer)
    if "gold" in data:
        gold = parser.parse_gold(board.crop_gold(img, gameBoard),
                                 testcase.debug)
        print("Asserting gold: {}".format(gold))
        testcase.assertEqual(data["gold"], gold)
    if "players" in data:
        if isinstance(data["players"], list):
            players = parser.parse_players(board.crop_players(img, gameBoard),
                                           testcase.debug)
            print("Asserting players: {}".format(players))
            for player in players:
                if player == "You":
                    continue
                res = utils.find_matching_string_in_list(
                    player, data["players"])
                testcase.assertIsNot(
                    res, "", "Unable to find match for {}".format(player))
        elif isinstance(data["players"], dict):
            cropped_circles = board.crop_healthbar_circles(img, gameBoard)
            result = parser.parse_healthbar_circles(cropped_circles,
                                                    testcase.debug)
            cropped_healthbars = board.crop_healthbars(img, gameBoard, result)
            healthbars = parser.parse_healthbars(cropped_healthbars,
                                                 testcase.debug)
            print("Asserting healthbars: {}".format(healthbars))
            player_names = data["players"].keys()
            for healthbar in healthbars:
                res = utils.find_matching_string_in_list(
                    healthbar[0], player_names)
                health = healthbar[1]
                if res == "" and healthbar[0].isdigit():  # Own HP Testcase
                    health = utils.convert_string_to_integer(healthbar[0])
                testcase.assertEqual(health, data["players"][res])