def test_c_7__disrupted_unit_swap():
    """
    ENGLAND: A London -> Belgium (Convoy)
             F North Sea Transports London -> Belgium

    FRANCE:  A Belgium -> London (Convoy)
             F English Channel Transports Belgium -> London
             A Burgandy -> Belgium
    """
    game_map = generate_map()

    england_starting_configuration = [
        {
            'territory_name': 'London',
            'unit_type': UnitTypes.TROOP
        },
        {
            'territory_name': 'North Sea',
            'unit_type': UnitTypes.FLEET
        },
    ]
    england = Player("England", game_map, england_starting_configuration)

    france_starting_configuration = [
        {
            'territory_name': 'Belgium',
            'unit_type': UnitTypes.TROOP
        },
        {
            'territory_name': 'English Channel',
            'unit_type': UnitTypes.FLEET
        },
        {
            'territory_name': 'Burgundy',
            'unit_type': UnitTypes.TROOP
        },
    ]
    france = Player("France", game_map, france_starting_configuration)

    commands = [
        ConvoyMoveCommand(england, england.units[0], 'Belgium'),
        ConvoyTransportCommand(england, england.units[1], england.units[0],
                               'Belgium'),
        ConvoyMoveCommand(france, france.units[0], 'London'),
        ConvoyTransportCommand(france, france.units[1], france.units[0],
                               'London'),
        MoveCommand(france, france.units[2], 'Belgium'),
    ]
    result = resolve_turn(game_map, commands)
    assert result == {
        'England': {
            Unit(UnitTypes.TROOP, 'London'): None,
            Unit(UnitTypes.FLEET, 'North Sea'): None,
        },
        'France': {
            Unit(UnitTypes.TROOP, 'Belgium'): None,
            Unit(UnitTypes.FLEET, 'English Channel'): None,
            Unit(UnitTypes.TROOP, 'Burgundy'): None,
        },
    }
Beispiel #2
0
def test_player_with_no_starting_position():
    game_map = generate_map()
    starting_configuration = []
    player = Player("test player", game_map, starting_configuration)

    assert player.starting_territories == set()
    assert player.units == []
Beispiel #3
0
def test_b_1__portugal_to_north_spain_coast():
    """
    FRANCE: F Portugal Coast -> Spain North Coast

    Adapted from original test. Original made assertions about ambiguous
    coast orders, which are not possible in this system.
    """
    game_map = generate_map()
    france_starting_configuration = [
        {
            'territory_name': 'Portugal Coast',
            'unit_type': UnitTypes.FLEET
        },
    ]
    france = Player("France", game_map, france_starting_configuration)

    commands = [
        MoveCommand(france, france.units[0], 'Spain North Coast'),
    ]
    result = resolve_turn(game_map, commands)
    assert result == {
        'France': {
            Unit(UnitTypes.FLEET, 'Spain North Coast'): None
        },
    }
Beispiel #4
0
def test_b_13__coastal_crawl_not_allowed():
    """
    TURKEY: F Bulgaria South Coast -> Constantinople
            F Constantinople -> Bulgaria North Coast
    """
    game_map = generate_map()
    turkey_starting_configuration = [
        {
            'territory_name': 'Bulgaria South Coast',
            'unit_type': UnitTypes.FLEET
        },
        {
            'territory_name': 'Constantinople Coast',
            'unit_type': UnitTypes.FLEET
        },
    ]
    turkey = Player("Turkey", game_map, turkey_starting_configuration)

    commands = [
        MoveCommand(turkey, turkey.units[0], 'Constantinople Coast'),
        MoveCommand(turkey, turkey.units[1], 'Bulgaria North Coast'),
    ]
    result = resolve_turn(game_map, commands)
    assert result == {
        'Turkey': {
            Unit(UnitTypes.FLEET, 'Bulgaria South Coast'): None,
            Unit(UnitTypes.FLEET, 'Constantinople Coast'): None,
        }
    }
Beispiel #5
0
def test__convoy_transport_command():
    game_map = generate_map()
    starting_configuration = [
        {
            'territory_name': 'Ankara',
            'unit_type': UnitTypes.TROOP
        },
        {
            'territory_name': 'Black Sea',
            'unit_type': UnitTypes.FLEET
        },
    ]
    player = Player("Turkey", game_map, starting_configuration)
    move_command = ConvoyMoveCommand(player, player.units[0], 'Sevastopol')
    transport_command = ConvoyTransportCommand(player, player.units[1],
                                               player.units[0], 'Sevastopol')
    command_map = CommandMap(game_map, [move_command, transport_command])

    assert command_map._home_map == {
        'Ankara': move_command,
        'Black Sea': transport_command
    }
    assert command_map._attacker_map == dict()
    assert command_map._convoy_attacker_map == {'Sevastopol': [move_command]}
    assert command_map._transport_map == {
        ('Ankara', 'Sevastopol'): [transport_command]
    }
    assert command_map._support_map == dict()
Beispiel #6
0
def test_player_multiple_starting_territories():
    game_map = generate_map()
    starting_configuration = [
        {
            'territory_name': 'St. Petersburg North Coast',
            'unit_type': UnitTypes.FLEET
        },
        {
            'territory_name': 'Warsaw',
            'unit_type': UnitTypes.TROOP
        },
        {
            'territory_name': 'Moscow',
            'unit_type': UnitTypes.TROOP
        },
        {
            'territory_name': 'Sevastopol Coast',
            'unit_type': UnitTypes.FLEET
        },
    ]

    player = Player("test player", game_map, starting_configuration)
    assert player.starting_territories == {
        'St. Petersburg', 'Warsaw', 'Moscow', 'Sevastopol'
    }
    assert player.units == [
        Unit(UnitTypes.FLEET, 'St. Petersburg North Coast'),
        Unit(UnitTypes.TROOP, 'Warsaw'),
        Unit(UnitTypes.TROOP, 'Moscow'),
        Unit(UnitTypes.FLEET, 'Sevastopol Coast'),
    ]
def test_a_11__simple_bounce():
    """
    AUSTRIA: A Vienna -> Tyrolia
    ITALY:   A Venice -> Tyrolia
    """
    game_map = generate_map()
    austria_starting_configuration = [
        {
            'territory_name': 'Vienna',
            'unit_type': UnitTypes.TROOP
        },
    ]
    austria = Player("Austria", game_map, austria_starting_configuration)

    italy_starting_configuration = [
        {
            'territory_name': 'Venice',
            'unit_type': UnitTypes.TROOP
        },
    ]
    italy = Player("Italy", game_map, italy_starting_configuration)

    commands = [
        MoveCommand(austria, austria.units[0], 'Tyrolia'),
        MoveCommand(italy, italy.units[0], 'Tyrolia'),
    ]
    result = resolve_turn(game_map, commands)
    assert result == {
        'Austria': {
            Unit(UnitTypes.TROOP, 'Vienna'): None
        },
        'Italy': {
            Unit(UnitTypes.TROOP, 'Venice'): None
        },
    }
Beispiel #8
0
def test_player_invalid_for_invalid_starting_territory():
    game_map = generate_map()
    starting_configuration = [{
        'territory_name': 'Fake Territory',
        'unit_type': None
    }]
    with pytest.raises(AssertionError):
        Player("test player", game_map, starting_configuration)
Beispiel #9
0
def test_player_invalid_for_fleet_on_land():
    game_map = generate_map()
    starting_configuration = [{
        'territory_name': 'Trieste',
        'unit_type': UnitTypes.FLEET
    }]
    with pytest.raises(AssertionError):
        Player("test player", game_map, starting_configuration)
Beispiel #10
0
def test_player_invalid_for_troop_on_coast():
    game_map = generate_map()
    starting_configuration = [{
        'territory_name': 'Liverpool Coast',
        'unit_type': UnitTypes.TROOP
    }]
    with pytest.raises(AssertionError):
        Player("test player", game_map, starting_configuration)
Beispiel #11
0
 def __init__(self, player_helpers, game_map=vanilla_dip.generate_map()):
     self.game_map = game_map
     self.players = {
         player_helper.name:
         Player(player_helper.name, game_map,
                player_helper.get_starting_configuration())
         for player_helper in player_helpers
     }
     self.commands = self._build_commands(player_helpers)
Beispiel #12
0
def test_player_with_coastal_starting_position_labeled_as_parent():
    game_map = generate_map()
    starting_configuration = [{
        'territory_name': 'Sevastopol Coast',
        'unit_type': UnitTypes.FLEET
    }]
    player = Player("test player", game_map, starting_configuration)

    assert player.starting_territories == {'Sevastopol'}
    assert player.units == [Unit(UnitTypes.FLEET, 'Sevastopol Coast')]
Beispiel #13
0
def test_player_with_one_starting_position_with_unit():
    game_map = generate_map()
    starting_configuration = [{
        'territory_name': 'Sevastopol',
        'unit_type': UnitTypes.TROOP
    }]
    player = Player("test player", game_map, starting_configuration)

    assert player.starting_territories == {'Sevastopol'}
    assert player.units == [Unit(UnitTypes.TROOP, 'Sevastopol')]
Beispiel #14
0
def test_support_destination_not_adjacent():
    game_map = generate_map()
    starting_configuration = [
        {'territory_name': 'Trieste', 'unit_type': UnitTypes.TROOP},
        {'territory_name': 'Budapest', 'unit_type': UnitTypes.TROOP},
    ]
    player = Player("Austria", game_map, starting_configuration)

    with pytest.raises(AssertionError):
        SupportCommand(player, player.units[0], player.units[1], 'Galicia')
Beispiel #15
0
def test_convoy_transport_fails_for_troop_transporting():
    game_map = generate_map()
    starting_configuration = [
        {'territory_name': 'Apulia', 'unit_type': UnitTypes.TROOP},
        {'territory_name': 'Rome', 'unit_type': UnitTypes.TROOP},
    ]
    player = Player("Italy", game_map, starting_configuration)

    with pytest.raises(AssertionError):
        ConvoyTransportCommand(player, player.units[0], player.units[1], 'Marseilles')
Beispiel #16
0
def test_convoy_transport_fails_for_landlocked_destination():
    game_map = generate_map()
    starting_configuration = [
        {'territory_name': 'Tyrrhenian Sea', 'unit_type': UnitTypes.FLEET},
        {'territory_name': 'Naples', 'unit_type': UnitTypes.TROOP},
    ]
    player = Player("Italy", game_map, starting_configuration)

    with pytest.raises(AssertionError):
        ConvoyTransportCommand(player, player.units[0], player.units[1], 'Warsaw')
Beispiel #17
0
def test_convoy_transport_fails_for_fleet_moving():
    game_map = generate_map()
    starting_configuration = [
        {'territory_name': 'Spain South Coast', 'unit_type': UnitTypes.FLEET},
        {'territory_name': 'Western Mediterranean Sea', 'unit_type': UnitTypes.FLEET},
    ]
    player = Player("France", game_map, starting_configuration)

    with pytest.raises(AssertionError):
        ConvoyTransportCommand(player, player.units[0], player.units[1], 'Tunis')
Beispiel #18
0
def test_support_landlocked_destination_with_fleet():
    game_map = generate_map()
    starting_configuration = [
        {'territory_name': 'Rumania Coast', 'unit_type': UnitTypes.FLEET},
        {'territory_name': 'Serbia', 'unit_type': UnitTypes.TROOP},
    ]
    player = Player("Turkey", game_map, starting_configuration)

    with pytest.raises(AssertionError):
        SupportCommand(player, player.units[0], player.units[1], 'Budapest')
Beispiel #19
0
def test_move_not_adjacent():
    game_map = generate_map()
    starting_configuration = [
        {
            'territory_name': 'Trieste',
            'unit_type': UnitTypes.TROOP
        },
    ]
    player = Player("Austria", game_map, starting_configuration)

    with pytest.raises(AssertionError):
        MoveCommand(player, player.units[0], 'Sevastopol')
Beispiel #20
0
def test_move_wrong_type():
    game_map = generate_map()
    starting_configuration = [
        {
            'territory_name': 'St. Petersburg North Coast',
            'unit_type': UnitTypes.FLEET
        },
    ]
    player = Player("Russia", game_map, starting_configuration)

    with pytest.raises(AssertionError):
        MoveCommand(player, player.units[0], 'Moscow')
def test_convoy_move_fails_for_fleet():
    game_map = generate_map()
    starting_configuration = [
        {
            'territory_name': 'St. Petersburg North Coast',
            'unit_type': UnitTypes.FLEET
        },
    ]
    player = Player("Russia", game_map, starting_configuration)

    with pytest.raises(AssertionError):
        ConvoyMoveCommand(player, player.units[0], 'Sweden Coast')
def test_convoy_move_fails_for_landlocked_origin():
    game_map = generate_map()
    starting_configuration = [
        {
            'territory_name': 'Silesia',
            'unit_type': UnitTypes.TROOP
        },
    ]
    player = Player("England", game_map, starting_configuration)

    with pytest.raises(AssertionError):
        ConvoyMoveCommand(player, player.units[0], 'London')
Beispiel #23
0
def test_support_troop_on_coast_to_another_coast():
    game_map = generate_map()
    starting_configuration = [
        {'territory_name': 'Norway', 'unit_type': UnitTypes.TROOP},
        {'territory_name': 'Norwegian Sea', 'unit_type': UnitTypes.FLEET},
    ]
    player = Player("Russia", game_map, starting_configuration)

    command = SupportCommand(player, player.units[1], player.units[0], 'Edinburgh')

    assert command.unit.position == 'Norwegian Sea'
    assert command.supported_unit.position == 'Norway'
    assert command.destination == 'Edinburgh'
Beispiel #24
0
def test_support_fleet_to_coast_with_troop():
    game_map = generate_map()
    starting_configuration = [
        {'territory_name': 'Finland', 'unit_type': UnitTypes.TROOP},
        {'territory_name': 'Baltic Sea', 'unit_type': UnitTypes.FLEET},
    ]
    player = Player("France", game_map, starting_configuration)

    command = SupportCommand(player, player.units[0], player.units[1], 'Sweden Coast')

    assert command.unit.position == 'Finland'
    assert command.supported_unit.position == 'Baltic Sea'
    assert command.destination == 'Sweden Coast'
Beispiel #25
0
def test_a_9__fleets_must_follow_coastlines():
    """ ITALY: F Rome Coast -> Venice Coast """
    game_map = generate_map()
    starting_configuration = [
        {
            'territory_name': 'Rome Coast',
            'unit_type': UnitTypes.FLEET
        },
    ]
    player = Player("Italy", game_map, starting_configuration)

    with pytest.raises(AssertionError):
        MoveCommand(player, player.units[0], 'Venice Coast')
Beispiel #26
0
def test_support_troop_to_parent_of_coast_with_fleet():
    game_map = generate_map()
    starting_configuration = [
        {'territory_name': 'Gulf of Lyon', 'unit_type': UnitTypes.FLEET},
        {'territory_name': 'Tuscany', 'unit_type': UnitTypes.TROOP},
    ]
    player = Player("France", game_map, starting_configuration)

    command = SupportCommand(player, player.units[0], player.units[1], 'Piedmont')

    assert command.unit.position == 'Gulf of Lyon'
    assert command.supported_unit.position == 'Tuscany'
    assert command.destination == 'Piedmont'
Beispiel #27
0
def test_support_supported_unit_adjacent():
    game_map = generate_map()
    starting_configuration = [
        {'territory_name': 'Tuscany', 'unit_type': UnitTypes.TROOP},
        {'territory_name': 'Rome', 'unit_type': UnitTypes.TROOP},
    ]
    player = Player("Italy", game_map, starting_configuration)

    command = SupportCommand(player, player.units[0], player.units[1], 'Venice')

    assert command.unit.position == 'Tuscany'
    assert command.supported_unit.position == 'Rome'
    assert command.destination == 'Venice'
Beispiel #28
0
def test_support_supported_unit_not_adjacent():
    game_map = generate_map()
    starting_configuration = [
        {'territory_name': 'Paris', 'unit_type': UnitTypes.TROOP},
        {'territory_name': 'Ruhr', 'unit_type': UnitTypes.TROOP},
    ]
    player = Player("France", game_map, starting_configuration)

    command = SupportCommand(player, player.units[0], player.units[1], 'Burgundy')

    assert command.unit.position == 'Paris'
    assert command.supported_unit.position == 'Ruhr'
    assert command.destination == 'Burgundy'
Beispiel #29
0
def test_a_2__check_army_to_sea_territory_fails():
    """ ENGLAND: A Liverpool -> Irish Sea """
    game_map = generate_map()
    starting_configuration = [
        {
            'territory_name': 'Liverpool',
            'unit_type': UnitTypes.TROOP
        },
    ]
    player = Player("England", game_map, starting_configuration)

    with pytest.raises(AssertionError):
        MoveCommand(player, player.units[0], 'Irish Sea')
Beispiel #30
0
def test_a_3__check_fleet_to_land_territory_fails():
    """ GERMANY: F Kiel Coast -> Munich """
    game_map = generate_map()
    starting_configuration = [
        {
            'territory_name': 'Kiel Coast',
            'unit_type': UnitTypes.FLEET
        },
    ]
    player = Player("Germany", game_map, starting_configuration)

    with pytest.raises(AssertionError):
        MoveCommand(player, player.units[0], 'Munich')