Example #1
0
def test_mis_008():
    """ Tests the MIS response """
    daide_str = 'MIS ( FRA FLT BRE ) ( FRA AMY MAR )'
    game = Game(map_name='standard')
    game.add_rule('NO_CHECK')
    game.set_orders('FRANCE', ['A PAR - BUR'])
    phase_name = 'S1901M'
    power = game.get_power('FRANCE')
    response = responses.MIS(phase_name=phase_name, power=power)
    assert isinstance(response, responses.MIS), 'Expected a MIS response'
    assert bytes(response) == str_to_bytes(daide_str)
def compute_ratio(game_json):
    if game_json['map'] != 'standard':
        return 0, 0, 0
    nb_supports = 0
    nb_cross_supports = 0
    nb_effective_cross_supports = 0
    game = Game()
    game.add_rule('IGNORE_ERRORS')
    for phase in game_json['phases']:
        if phase['name'][-1] != 'M':
            continue
        phase_data = GamePhaseData.from_dict(phase)
        game.set_phase_data(phase_data, clear_history=True)
        game.add_rule('IGNORE_ERRORS')

        # Get nb_supports
        for _, orders in game.get_orders().items():
            for order in orders:
                order_tokens = order.split()
                if len(order_tokens) < 3:
                    continue
                if order.split()[2] == 'S':
                    nb_supports += 1

        phase_cross_supports = check_cross_support(game)
        nb_cross_supports += len(phase_cross_supports)

        # Determine effective cross supports
        if len(phase_cross_supports) > 0:
            results = {
                normalized_unit(unit): result
                for unit, result in phase_data.results.items()
            }
            for cross_support in phase_cross_supports:
                # If the supportee's move is a failure, pass
                if len(results.get(cross_support.supportee_unit,
                                   ['void'])) > 0:
                    continue

                # Modify the support to hold
                modified_phase_data = GamePhaseData.from_dict(phase)
                supporter = cross_support.supporter
                support_order_idx = modified_phase_data.orders[
                    supporter].index(cross_support.supporter_order)
                modified_phase_data.orders[supporter][
                    support_order_idx] = to_hold(cross_support.supporter_order)

                # Process the phase to see if the supportee fails
                game.set_phase_data(modified_phase_data, clear_history=True)
                game.add_rule('IGNORE_ERRORS')
                modified_phase_data = game.process()
                modified_results = {
                    normalized_unit(unit): result
                    for unit, result in modified_phase_data.results.items()
                }
                if len(modified_results[cross_support.supportee_unit]) > 0:
                    nb_effective_cross_supports += 1

    return nb_supports, nb_cross_supports, nb_effective_cross_supports