Exemplo n.º 1
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()
Exemplo n.º 2
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,
        }
    }
Exemplo n.º 3
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)
Exemplo n.º 4
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)
Exemplo n.º 5
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)
Exemplo n.º 6
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)
Exemplo n.º 7
0
def test_a_6__check_player_cannot_command_other_players_units():
    """
    (all troops belong to England)
    GERMANY: F London Coast -> North Sea
             A Liverpool Hold
             A Wales Support Liverpool Hold
             A Convoy Wales -> Picardy
             F English Channel Transport Wales -> Picardy
    """
    # Extended from original check: various command types added, since all should fail
    game_map = generate_map()
    starting_configuration = [
        {
            'territory_name': 'London Coast',
            'unit_type': UnitTypes.FLEET
        },
        {
            'territory_name': 'Liverpool',
            'unit_type': UnitTypes.TROOP
        },
        {
            'territory_name': 'Wales',
            'unit_type': UnitTypes.TROOP
        },
        {
            'territory_name': 'English Channel',
            'unit_type': UnitTypes.FLEET
        },
    ]
    england = Player("England", game_map, starting_configuration)
    germany = Player("Germany", game_map, [])

    with pytest.raises(AssertionError):
        MoveCommand(germany, england.units[0], 'North Sea')
    with pytest.raises(AssertionError):
        HoldCommand(germany, england.units[1])
    with pytest.raises(AssertionError):
        SupportCommand(germany, england.units[2], england.units[1],
                       'Liverpool')
    with pytest.raises(AssertionError):
        ConvoyMoveCommand(germany, england.units[2], 'Picardy')
    with pytest.raises(AssertionError):
        ConvoyTransportCommand(germany, england.units[3], england.units[2],
                               'Picardy')
Exemplo n.º 8
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')
Exemplo n.º 9
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')
Exemplo n.º 10
0
def test_b_4__support_to_unreachable_coast_allowed():
    """
    FRANCE: F Gascony Coast -> Spain North Coast
            F Marseilles Coast Support F Gascony Coast -> Spain North Coast
    ITALY:  F Western Mediterranean Sea -> Spain South Coast
    """
    game_map = generate_map()
    france_starting_configuration = [
        {
            'territory_name': 'Gascony Coast',
            'unit_type': UnitTypes.FLEET
        },
        {
            'territory_name': 'Marseilles Coast',
            'unit_type': UnitTypes.FLEET
        },
    ]
    france = Player("France", game_map, france_starting_configuration)

    italy_starting_configuration = [
        {
            'territory_name': 'Western Mediterranean Sea',
            'unit_type': UnitTypes.FLEET
        },
    ]
    italy = Player("Italy", game_map, italy_starting_configuration)

    commands = [
        MoveCommand(france, france.units[0], 'Spain North Coast'),
        SupportCommand(france, france.units[1], france.units[0],
                       'Spain North Coast'),
        MoveCommand(italy, italy.units[0], 'Spain South Coast'),
    ]
    result = resolve_turn(game_map, commands)
    assert result == {
        'France': {
            Unit(UnitTypes.FLEET, 'Spain North Coast'): None,
            Unit(UnitTypes.FLEET, 'Marseilles Coast'): None,
        },
        'Italy': {
            Unit(UnitTypes.FLEET, 'Western Mediterranean Sea'): None,
        }
    }
Exemplo n.º 11
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')
Exemplo n.º 12
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')
Exemplo n.º 13
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')
Exemplo n.º 14
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')]
Exemplo n.º 15
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')]
Exemplo n.º 16
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')
Exemplo n.º 17
0
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')
Exemplo n.º 18
0
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')
Exemplo n.º 19
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')
Exemplo n.º 20
0
def test_convoy_transport_success():
    game_map = generate_map()
    starting_configuration = [
        {'territory_name': 'Tyrrhenian Sea', 'unit_type': UnitTypes.FLEET},
        {'territory_name': 'Constantinople', 'unit_type': UnitTypes.TROOP},
    ]
    player = Player("Turkey", game_map, starting_configuration)

    command = ConvoyTransportCommand(player, player.units[0], player.units[1], 'Tunis')

    assert command.unit.position == 'Tyrrhenian Sea'
    assert command.transported_unit.position == 'Constantinople'
    assert command.destination == 'Tunis'
Exemplo n.º 21
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'
Exemplo n.º 22
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'
Exemplo n.º 23
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'
Exemplo n.º 24
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'
Exemplo n.º 25
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'
Exemplo n.º 26
0
def test_a_1__check_move_to_non_neighboring_territory_fails():
    """ ENGLAND: F North Sea -> Picardy """
    game_map = generate_map()
    starting_configuration = [
        {
            'territory_name': 'North Sea',
            'unit_type': UnitTypes.FLEET
        },
    ]
    player = Player("England", game_map, starting_configuration)

    with pytest.raises(AssertionError):
        MoveCommand(player, player.units[0], 'Picardy Coast')
Exemplo n.º 27
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')
Exemplo n.º 28
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')
Exemplo n.º 29
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')
Exemplo n.º 30
0
def test_a_4__check_move_to_same_territory():
    """ GERMANY: F Kiel Coast -> Kiel Coast """
    # We treat this as identical to a Hold command
    game_map = generate_map()
    starting_configuration = [
        {
            'territory_name': 'Kiel Coast',
            'unit_type': UnitTypes.FLEET
        },
    ]
    player = Player("Germany", game_map, starting_configuration)

    move = MoveCommand(player, player.units[0], 'Kiel Coast')
    assert move == HoldCommand(player, player.units[0])