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_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 == []
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
        },
    }
Exemplo n.º 4
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_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,
        },
    }
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)
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.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
def test_b_6__support_can_be_cut_from_other_coast():
    """
    ENGLAND: F North Atlantic Ocean -> Mid-Atlantic Ocean
             F Irish Sea Supports North Atlantic Ocean -> Mid-Atlantic Ocean

    FRANCE:  F Mid-Atlantic Ocean Hold
             F Spain North Coast Support Mid-Atlantic Ocean Hold

    ITALY:   F Gulf of Lyon -> Spain South Coast
    """
    game_map = generate_map()
    england_starting_configuration = [
        {'territory_name': 'North Atlantic Ocean', 'unit_type': UnitTypes.FLEET},
        {'territory_name': 'Irish Sea', 'unit_type': UnitTypes.FLEET},
    ]
    england = Player("England", game_map, england_starting_configuration)

    france_starting_configuration = [
        {'territory_name': 'Mid-Atlantic Ocean', 'unit_type': UnitTypes.FLEET},
        {'territory_name': 'Spain North Coast', 'unit_type': UnitTypes.FLEET},
    ]
    france = Player("France", game_map, france_starting_configuration)

    italy_starting_configuration = [
        {'territory_name': 'Gulf of Lyon', 'unit_type': UnitTypes.FLEET},
    ]
    italy = Player("Italy", game_map, italy_starting_configuration)

    commands = [
        MoveCommand(england, england.units[0], 'Mid-Atlantic Ocean'),
        SupportCommand(england, england.units[1], england.units[0], 'Mid-Atlantic Ocean'),

        HoldCommand(france, france.units[0]),
        SupportCommand(france, france.units[1], france.units[0], 'Mid-Atlantic Ocean'),

        MoveCommand(italy, italy.units[0], 'Spain South Coast'),
    ]
    result = resolve_turn(game_map, commands)
    assert result == {
        'England': {
            Unit(UnitTypes.FLEET, 'Mid-Atlantic Ocean'): None,
            Unit(UnitTypes.FLEET, 'Irish Sea'): None,
        },
        'France': {
            Unit(UnitTypes.FLEET, 'Mid-Atlantic Ocean'): {
                'English Channel',
                'Brest Coast',
                'Gascony Coast',
                'Portugal Coast',
                'Western Mediterranean Sea',
                'North Africa Coast',
            },
            Unit(UnitTypes.FLEET, 'Spain North Coast'): None,
        },
        'Italy': {
            Unit(UnitTypes.FLEET, 'Gulf of Lyon'): None,
        }
    }
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.º 13
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')]
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.º 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_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.º 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')
def test_b_12__army_movement_with_coastal_specification():
    """
    FRANCE: A Gascony -> Spain North Coast
    """
    game_map = generate_map()
    france_starting_configuration = [
        {'territory_name': 'Gascony', 'unit_type': UnitTypes.TROOP},
    ]
    france = Player("France", game_map, france_starting_configuration)

    with pytest.raises(AssertionError):
        MoveCommand(france, france.units[0], 'Spain North Coast')
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_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')
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')
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'
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'
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'
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'
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')
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')
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'
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.º 30
0
def test_move_sea_to_coast():
    game_map = generate_map()
    starting_configuration = [
        {
            'territory_name': 'Adriatic Sea',
            'unit_type': UnitTypes.FLEET
        },
    ]
    player = Player("Italy", game_map, starting_configuration)

    command = MoveCommand(player, player.units[0], 'Trieste Coast')

    assert command.unit.position == 'Adriatic Sea'
    assert command.destination == 'Trieste Coast'