예제 #1
0
def test_i_7b__only_one_build_in_a_home_supply_center__not_validated():
    # Russia has captured two territories, everyone else has stayed put
    player_units = vanilla_dip.generate_starting_player_units()
    player_units['Russia'] = {
        Unit(UnitTypes.FLEET, 'Sweden Coast'),
        Unit(UnitTypes.TROOP, 'Warsaw'),
        Unit(UnitTypes.TROOP, 'Ukraine'),
        Unit(UnitTypes.FLEET, 'Rumania Coast'),
    }

    helper = AdjustmentHelper(
        [
            PlayerHelper('Russia', [
                AdjustmentCommandHelper(AdjustmentCommandType.CREATE,
                                        UnitTypes.TROOP, 'Moscow'),
                AdjustmentCommandHelper(AdjustmentCommandType.CREATE,
                                        UnitTypes.TROOP, 'Moscow'),
            ]),
        ],
        player_units=player_units,
    )

    results = helper.resolve()
    expected_results = vanilla_dip.generate_starting_player_units()
    expected_results['Russia'] = {
        Unit(UnitTypes.FLEET, 'Sweden Coast'),
        Unit(UnitTypes.TROOP, 'Warsaw'),
        Unit(UnitTypes.TROOP, 'Ukraine'),
        Unit(UnitTypes.FLEET, 'Rumania Coast'),
        Unit(UnitTypes.TROOP, 'Moscow'),
    }
    assert results == expected_results
예제 #2
0
def test_i_1a__too_many_build_orders__with_validation():
    """
    This test has been modified from the DATC -- it includes a build from a non-home territory, which
    fails for a completely separate reason, before we even reach order resolution.
    """

    # Germany has captured one new territory, all other players have stayed still
    player_units = vanilla_dip.generate_starting_player_units()
    player_units['Germany'] = {
        Unit(UnitTypes.FLEET, 'Holland Coast'),
        Unit(UnitTypes.TROOP, 'Prussia'),
        Unit(UnitTypes.TROOP, 'Tyrolia'),
    }

    helper = AdjustmentHelper(
        [
            PlayerHelper('Germany', [
                AdjustmentCommandHelper(AdjustmentCommandType.CREATE,
                                        UnitTypes.TROOP, 'Berlin'),
                AdjustmentCommandHelper(AdjustmentCommandType.CREATE,
                                        UnitTypes.TROOP, 'Kiel'),
                AdjustmentCommandHelper(AdjustmentCommandType.CREATE,
                                        UnitTypes.TROOP, 'Munich'),
            ]),
        ],
        player_units=player_units,
    )

    with pytest.raises(AssertionError):
        helper.resolve__validated()
예제 #3
0
def test_i_6__building_in_owned_supply_center_that_is_not_a_home_supply_center(
):
    # Germany has captured Warsaw, and moved out
    player_units = vanilla_dip.generate_starting_player_units()
    player_units['Germany'] = {
        Unit(UnitTypes.FLEET, 'Kiel Coast'),
        Unit(UnitTypes.TROOP, 'Munich'),
        Unit(UnitTypes.TROOP, 'Ukraine'),
        Unit(UnitTypes.TROOP, 'Berlin'),
    }
    player_units['Russia'] = {
        Unit(UnitTypes.FLEET, 'St. Petersburg South Coast'),
        Unit(UnitTypes.TROOP, 'Moscow'),
        Unit(UnitTypes.FLEET, 'Sevastopol Coast'),
    }

    owned_territories = vanilla_dip.generate_home_territories()
    owned_territories['Germany'] = {'Kiel', 'Munich', 'Berlin', 'Warsaw'}
    owned_territories['Russia'] = {'St. Petersburg', 'Sevastopol', 'Moscow'}

    with pytest.raises(AssertionError):
        AdjustmentHelper(
            [
                PlayerHelper('Germany', [
                    AdjustmentCommandHelper(AdjustmentCommandType.CREATE,
                                            UnitTypes.TROOP, 'Warsaw'),
                ]),
            ],
            player_units=player_units,
            owned_territories=owned_territories,
        )
def test_j_1a__too_many_remove_orders__validated():
    """
    This test has been modified from the DATC -- it includes a disband of a unit that does not exist,
    which fails for a completely separate reason, before we even reach order resolution.
    """

    # France has lost one territory to England, all other players have stayed still
    player_units = vanilla_dip.generate_starting_player_units()
    player_units['England'] = {
        Unit(UnitTypes.FLEET, 'English Channel'),
        Unit(UnitTypes.TROOP, 'Brest'),
        Unit(UnitTypes.TROOP, 'Edinburgh'),
    }
    player_units['France'] = {
        Unit(UnitTypes.FLEET, 'Mid-Atlantic Ocean'),
        Unit(UnitTypes.TROOP, 'Paris'),
        Unit(UnitTypes.TROOP, 'Marseilles'),
    }

    helper = AdjustmentHelper(
        [
            PlayerHelper('France', [
                AdjustmentCommandHelper(AdjustmentCommandType.DISBAND,
                                        UnitTypes.FLEET, 'Mid-Atlantic Ocean'),
                AdjustmentCommandHelper(AdjustmentCommandType.DISBAND,
                                        UnitTypes.TROOP, 'Paris'),
                AdjustmentCommandHelper(AdjustmentCommandType.DISBAND,
                                        UnitTypes.TROOP, 'Marseilles'),
            ]),
        ],
        player_units=player_units,
    )

    with pytest.raises(AssertionError):
        helper.resolve__validated()
def test_j_3b__civil_disorder_two_armies_with_different_distance__not_validated(
):
    # Russia has lost a territory to Germany and a territory to Turkey, all other units stay put
    player_units = vanilla_dip.generate_starting_player_units()
    player_units['Russia'] = {
        Unit(UnitTypes.FLEET, 'St. Petersburg South Coast'),
        Unit(UnitTypes.TROOP, 'Prussia'),
        Unit(UnitTypes.TROOP, 'Ukraine'),
        Unit(UnitTypes.FLEET, 'Black Sea'),
    }
    player_units['Germany'] = {
        Unit(UnitTypes.FLEET, 'Kiel Coast'),
        Unit(UnitTypes.TROOP, 'Warsaw'),
        Unit(UnitTypes.TROOP, 'Munich'),
    }
    player_units['Turkey'] = {
        Unit(UnitTypes.FLEET, 'Sevastopol Coast'),
        Unit(UnitTypes.TROOP, 'Smyrna'),
        Unit(UnitTypes.TROOP, 'Constantinople'),
    }

    helper = AdjustmentHelper(
        [],
        player_units=player_units,
    )

    # Rather than using "distance", our Civil Disobedience rules will pick in alphabetical order
    results = helper.resolve()
    expected_results = deepcopy(player_units)
    expected_results['Russia'] = {
        Unit(UnitTypes.FLEET, 'St. Petersburg South Coast'),
        Unit(UnitTypes.TROOP, 'Ukraine'),
    }
    assert results == expected_results
def test_j_3a__civil_disorder_two_armies_with_different_distance__validated():
    # Russia has lost a territory to Germany and a territory to Turkey, all other units stay put
    player_units = vanilla_dip.generate_starting_player_units()
    player_units['Russia'] = {
        Unit(UnitTypes.FLEET, 'St. Petersburg South Coast'),
        Unit(UnitTypes.TROOP, 'Prussia'),
        Unit(UnitTypes.TROOP, 'Ukraine'),
        Unit(UnitTypes.FLEET, 'Black Sea'),
    }
    player_units['Germany'] = {
        Unit(UnitTypes.FLEET, 'Kiel Coast'),
        Unit(UnitTypes.TROOP, 'Warsaw'),
        Unit(UnitTypes.TROOP, 'Munich'),
    }
    player_units['Turkey'] = {
        Unit(UnitTypes.FLEET, 'Sevastopol Coast'),
        Unit(UnitTypes.TROOP, 'Smyrna'),
        Unit(UnitTypes.TROOP, 'Constantinople'),
    }

    helper = AdjustmentHelper(
        [],
        player_units=player_units,
    )

    with pytest.raises(AssertionError):
        helper.resolve__validated()
def test_j_2a__removing_the_same_unit_twice__validated():
    # France has lost one territory to England and one to Germany, all other players have stayed still
    player_units = vanilla_dip.generate_starting_player_units()
    player_units['England'] = {
        Unit(UnitTypes.FLEET, 'English Channel'),
        Unit(UnitTypes.TROOP, 'Brest'),
        Unit(UnitTypes.TROOP, 'Edinburgh'),
    }
    player_units['Germany'] = {
        Unit(UnitTypes.FLEET, 'Kiel Coast'),
        Unit(UnitTypes.TROOP, 'Marseilles'),
        Unit(UnitTypes.TROOP, 'Berlin'),
    }
    player_units['France'] = {
        Unit(UnitTypes.FLEET, 'Mid-Atlantic Ocean'),
        Unit(UnitTypes.TROOP, 'Paris'),
        Unit(UnitTypes.TROOP, 'Gascony'),
    }

    helper = AdjustmentHelper(
        [
            PlayerHelper('France', [
                AdjustmentCommandHelper(AdjustmentCommandType.DISBAND,
                                        UnitTypes.TROOP, 'Paris'),
                AdjustmentCommandHelper(AdjustmentCommandType.DISBAND,
                                        UnitTypes.TROOP, 'Paris'),
            ]),
        ],
        player_units=player_units,
    )

    with pytest.raises(AssertionError):
        helper.resolve__validated()
예제 #8
0
def test_i_1b__too_many_build_orders():
    """
    This test has been modified from the DATC -- it includes a build from a non-home territory, which
    fails for a completely separate reason, before we even reach order resolution.
    """

    # Germany has captured one new territory, all other players have stayed still
    player_units = vanilla_dip.generate_starting_player_units()
    player_units['Germany'] = {
        Unit(UnitTypes.FLEET, 'Holland Coast'),
        Unit(UnitTypes.TROOP, 'Prussia'),
        Unit(UnitTypes.TROOP, 'Tyrolia'),
    }

    helper = AdjustmentHelper(
        [
            PlayerHelper('Germany', [
                AdjustmentCommandHelper(AdjustmentCommandType.CREATE,
                                        UnitTypes.TROOP, 'Berlin'),
                AdjustmentCommandHelper(AdjustmentCommandType.CREATE,
                                        UnitTypes.TROOP, 'Kiel'),
                AdjustmentCommandHelper(AdjustmentCommandType.CREATE,
                                        UnitTypes.TROOP, 'Munich'),
            ]),
        ],
        player_units=player_units,
    )

    # prioritize first-issued command
    results = helper.resolve()
    expected_results = vanilla_dip.generate_starting_player_units()
    expected_results['Germany'] = {
        Unit(UnitTypes.FLEET, 'Holland Coast'),
        Unit(UnitTypes.TROOP, 'Prussia'),
        Unit(UnitTypes.TROOP, 'Tyrolia'),
        Unit(UnitTypes.TROOP, 'Berlin'),
    }
    assert results == expected_results
예제 #9
0
def test_i_3__supply_center_must_be_empty_for_building():
    # Germany has captured one new territory, all other players have stayed still
    player_units = vanilla_dip.generate_starting_player_units()
    player_units['Germany'] = {
        Unit(UnitTypes.FLEET, 'Holland Coast'),
        Unit(UnitTypes.TROOP, 'Berlin'),
        Unit(UnitTypes.TROOP, 'Tyrolia'),
    }

    with pytest.raises(AssertionError):
        AdjustmentHelper(
            [
                PlayerHelper('Germany', [
                    AdjustmentCommandHelper(AdjustmentCommandType.CREATE,
                                            UnitTypes.TROOP, 'Berlin'),
                ]),
            ],
            player_units=player_units,
        )
예제 #10
0
def test_i_2__fleets_cannot_be_built_in_land_areas():
    # Russia has captured one new territory, all other players have stayed still
    player_units = vanilla_dip.generate_starting_player_units()
    player_units['Russia'] = {
        Unit(UnitTypes.FLEET, 'Sweden Coast'),
        Unit(UnitTypes.TROOP, 'Prussia'),
        Unit(UnitTypes.TROOP, 'Galicia'),
        Unit(UnitTypes.FLEET, 'Black Sea'),
    }

    with pytest.raises(AssertionError):
        AdjustmentHelper(
            [
                PlayerHelper('Russia', [
                    AdjustmentCommandHelper(AdjustmentCommandType.CREATE,
                                            UnitTypes.FLEET, 'Moscow'),
                ]),
            ],
            player_units=player_units,
        )
예제 #11
0
    def __init__(
            self,
            player_helpers,
            player_units=vanilla_dip.generate_starting_player_units(),
            owned_territories=vanilla_dip.generate_home_territories(),
            home_territories=vanilla_dip.generate_home_territories(),
            supply_map=vanilla_dip.generate_supply_center_map(),
    ):
        self.ownership_map = OwnershipMap(supply_map, owned_territories,
                                          home_territories)
        self.player_units = player_units
        self.ownership_map, self.adjustment_counts = calculate_adjustments(
            self.ownership_map, self.player_units)

        self.players = {
            player_helper.name: Player(
                player_helper.name, self.ownership_map.supply_map.game_map,
                _get_starting_configuration(player_units[player_helper.name]))
            for player_helper in player_helpers
        }
        self.commands = self._build_commands(player_helpers)
def test_j_2b__removing_the_same_unit_twice__not_validated():
    # France has lost one territory to England and one to Germany, all other players have stayed still
    player_units = vanilla_dip.generate_starting_player_units()
    player_units['England'] = {
        Unit(UnitTypes.FLEET, 'English Channel'),
        Unit(UnitTypes.TROOP, 'Brest'),
        Unit(UnitTypes.TROOP, 'Edinburgh'),
    }
    player_units['Germany'] = {
        Unit(UnitTypes.FLEET, 'Kiel Coast'),
        Unit(UnitTypes.TROOP, 'Marseilles'),
        Unit(UnitTypes.TROOP, 'Berlin'),
    }
    player_units['France'] = {
        Unit(UnitTypes.FLEET, 'Mid-Atlantic Ocean'),
        Unit(UnitTypes.TROOP, 'Paris'),
        Unit(UnitTypes.TROOP, 'Gascony'),
    }

    helper = AdjustmentHelper(
        [
            PlayerHelper('France', [
                AdjustmentCommandHelper(AdjustmentCommandType.DISBAND,
                                        UnitTypes.TROOP, 'Paris'),
                AdjustmentCommandHelper(AdjustmentCommandType.DISBAND,
                                        UnitTypes.TROOP, 'Paris'),
            ]),
        ],
        player_units=player_units,
    )

    # Rather than using "distance", our Civil Disobedience rules will pick in alphabetical order
    results = helper.resolve()
    expected_results = deepcopy(player_units)
    expected_results['France'] = {
        Unit(UnitTypes.FLEET, 'Mid-Atlantic Ocean'),
    }
    assert results == expected_results
예제 #13
0
def test_i_4__both_coasts_must_be_empty_for_building():
    # Russia has captured one new territory, all other players have stayed still
    player_units = vanilla_dip.generate_starting_player_units()
    player_units['Russia'] = {
        Unit(UnitTypes.FLEET, 'St. Petersburg South Coast'),
        Unit(UnitTypes.TROOP, 'Prussia'),
        Unit(UnitTypes.TROOP, 'Galicia'),
        Unit(UnitTypes.FLEET, 'Rumania Coast'),
    }

    with pytest.raises(AssertionError):
        AdjustmentHelper(
            [
                PlayerHelper('Russia', [
                    AdjustmentCommandHelper(
                        AdjustmentCommandType.CREATE,
                        UnitTypes.FLEET,
                        'St. Petersburg North Coast',
                    ),
                ]),
            ],
            player_units=player_units,
        )