Ejemplo n.º 1
0
def test__support_command():
    game_map = generate_map()
    starting_configuration = [
        {
            'territory_name': 'Smyrna',
            'unit_type': UnitTypes.TROOP
        },
        {
            'territory_name': 'Armenia Coast',
            'unit_type': UnitTypes.FLEET
        },
        {
            'territory_name': 'Serbia',
            'unit_type': UnitTypes.TROOP
        },
        {
            'territory_name': 'Greece',
            'unit_type': UnitTypes.TROOP
        },
    ]
    player = Player("Turkey", game_map, starting_configuration)
    move_command = MoveCommand(player, player.units[0], 'Ankara')
    hold_command = HoldCommand(player, player.units[2])
    support_command_1 = SupportCommand(player, player.units[1],
                                       player.units[0], 'Ankara')
    support_command_2 = SupportCommand(player, player.units[3],
                                       player.units[2], 'Serbia')
    command_map = CommandMap(
        game_map,
        [move_command, support_command_1, hold_command, support_command_2])

    assert command_map._home_map == {
        'Smyrna': move_command,
        'Armenia': support_command_1,
        'Serbia': hold_command,
        'Greece': support_command_2,
    }
    assert command_map._attacker_map == {
        'Ankara': [move_command],
        'Serbia': [hold_command],
    }
    assert command_map._convoy_attacker_map == dict()
    assert command_map._transport_map == dict()
    assert command_map._support_map == {
        ('Smyrna', 'Ankara'): [support_command_1],
        ('Serbia', 'Serbia'): [support_command_2],
    }
Ejemplo n.º 2
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')
Ejemplo n.º 3
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')
Ejemplo n.º 4
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'
Ejemplo n.º 5
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'
Ejemplo n.º 6
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'
Ejemplo n.º 7
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'
Ejemplo n.º 8
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'
Ejemplo n.º 9
0
def test_a_8__check_unit_cannot_support_itself():
    """ FRANCE: F Trieste Coast Support Trieste Coast Hold """
    # Modified from original check: this command is considered illegal, so no resolution check is made
    game_map = generate_map()
    starting_configuration = [
        {
            'territory_name': 'Trieste Coast',
            'unit_type': UnitTypes.FLEET
        },
    ]
    player = Player("France", game_map, starting_configuration)

    with pytest.raises(AssertionError):
        SupportCommand(player, player.units[0], player.units[0], 'Trieste')
Ejemplo n.º 10
0
def test_a_10__support_of_unreachable_destination_fails():
    """ ITALY: F Rome Coast Support Apulia -> Venice """
    game_map = generate_map()
    starting_configuration = [
        {
            'territory_name': 'Rome Coast',
            'unit_type': UnitTypes.FLEET
        },
        {
            'territory_name': 'Apulia',
            'unit_type': UnitTypes.TROOP
        },
    ]
    player = Player("Italy", game_map, starting_configuration)

    with pytest.raises(AssertionError):
        SupportCommand(player, player.units[0], player.units[1], 'Venice')
Ejemplo n.º 11
0
 def _build_command(self, player, command):
     unit = self._find_unit(command.unit)
     if command.command_type == CommandType.MOVE:
         return MoveCommand(player, unit, command.destination)
     if command.command_type == CommandType.SUPPORT:
         supported_unit = self._find_unit(command.source)
         return SupportCommand(player, unit, supported_unit,
                               command.destination)
     if command.command_type == CommandType.CONVOY_MOVE:
         return ConvoyMoveCommand(player, unit, command.destination)
     if command.command_type == CommandType.CONVOY_TRANSPORT:
         transported_unit = self._find_unit(command.source)
         return ConvoyTransportCommand(player, unit, transported_unit,
                                       command.destination)
     if command.command_type == CommandType.HOLD:
         return HoldCommand(player, unit)
     raise ValueError("Invalid command type: {}".format(
         command.command_type))
Ejemplo n.º 12
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')
Ejemplo n.º 13
0
def test_c_2__three_army_circular_movement_with_support():
    """
    TURKEY: F Ankara Coast -> Constantinople Coast
            A Constantinople -> Smyrna
            A Smyrna -> Ankara
            A Bulgaria Support Ankara Coast -> Constantinople Coast
    """
    game_map = generate_map()
    turkey_starting_configuration = [
        {
            'territory_name': 'Ankara Coast',
            'unit_type': UnitTypes.FLEET
        },
        {
            'territory_name': 'Constantinople',
            'unit_type': UnitTypes.TROOP
        },
        {
            'territory_name': 'Smyrna',
            'unit_type': UnitTypes.TROOP
        },
        {
            'territory_name': 'Bulgaria',
            'unit_type': UnitTypes.TROOP
        },
    ]
    turkey = Player("Turkey", game_map, turkey_starting_configuration)

    commands = [
        MoveCommand(turkey, turkey.units[0], 'Constantinople Coast'),
        MoveCommand(turkey, turkey.units[1], 'Smyrna'),
        MoveCommand(turkey, turkey.units[2], 'Ankara'),
        SupportCommand(turkey, turkey.units[3], turkey.units[0],
                       'Constantinople Coast'),
    ]
    result = resolve_turn(game_map, commands)
    assert result == {
        'Turkey': {
            Unit(UnitTypes.FLEET, 'Constantinople Coast'): None,
            Unit(UnitTypes.TROOP, 'Smyrna'): None,
            Unit(UnitTypes.TROOP, 'Ankara'): None,
            Unit(UnitTypes.TROOP, 'Bulgaria'): None,
        },
    }
Ejemplo n.º 14
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,
        }
    }
Ejemplo n.º 15
0
def test_d_22__impossible_fleet_move_cannot_be_supported():
    """
    Adapted from DATC test, because the DATC test requires illegal moves to be
    specified, which this system prevents
    """
    game_map = generate_map()
    germany_starting_configuration = [
        {
            'territory_name': 'Kiel Coast',
            'unit_type': UnitTypes.FLEET
        },
        {
            'territory_name': 'Burgundy',
            'unit_type': UnitTypes.TROOP
        },
    ]
    germany = Player("Germany", game_map, germany_starting_configuration)

    with pytest.raises(AssertionError):
        SupportCommand(germany, germany.units[1], germany.units[0], 'Munich')
Ejemplo n.º 16
0
def test_d_24__impossible_army_move_cannot_be_supported():
    """
    Adapted from DATC test, because the DATC test requires illegal moves to be
    specified, which this system prevents
    """
    game_map = generate_map()
    france_starting_configuration = [
        {
            'territory_name': 'Marseilles',
            'unit_type': UnitTypes.TROOP
        },
        {
            'territory_name': 'Spain South Coast',
            'unit_type': UnitTypes.FLEET
        },
    ]
    france = Player("France", game_map, france_starting_configuration)

    with pytest.raises(AssertionError):
        SupportCommand(france, france.units[1], france.units[0],
                       'Gulf of Lyon')
Ejemplo n.º 17
0
def test_b_5__support_from_unreachable_coast_not_allowed():
    """
    FRANCE: F Marseilles Coast -> Gulf of Lyon
            F Spain North Coast Support F Marseilles Coast -> Gulf of Lyon
    """
    game_map = generate_map()
    france_starting_configuration = [
        {
            'territory_name': 'Marseilles Coast',
            'unit_type': UnitTypes.FLEET
        },
        {
            'territory_name': 'Spain North Coast',
            'unit_type': UnitTypes.FLEET
        },
    ]
    france = Player("France", game_map, france_starting_configuration)

    with pytest.raises(AssertionError):
        SupportCommand(france, france.units[1], france.units[0],
                       'Gulf of Lyon')
Ejemplo n.º 18
0
def test_d_34__support_targetting_own_area_not_allowed():
    """
    Adapted from DATC test, because the DATC test requires illegal moves to be
    specified, which this system prevents
    """
    game_map = generate_map()
    italy_starting_configuration = [
        {
            'territory_name': 'Prussia',
            'unit_type': UnitTypes.TROOP
        },
    ]
    italy = Player("Italy", game_map, italy_starting_configuration)

    russia_starting_configuration = [
        {
            'territory_name': 'Warsaw',
            'unit_type': UnitTypes.TROOP
        },
    ]
    russia = Player("Russia", game_map, russia_starting_configuration)

    with pytest.raises(AssertionError):
        SupportCommand(italy, italy.units[0], russia.units[0], 'Prussia')
Ejemplo n.º 19
0
def test__several_commands():
    game_map = generate_map()
    starting_configuration = [
        {
            'territory_name': 'Ankara',
            'unit_type': UnitTypes.TROOP
        },
        {
            'territory_name': 'Black Sea',
            'unit_type': UnitTypes.FLEET
        },
        {
            'territory_name': 'Budapest',
            'unit_type': UnitTypes.TROOP
        },
        {
            'territory_name': 'Rumania Coast',
            'unit_type': UnitTypes.FLEET
        },
        {
            'territory_name': 'Ukraine',
            'unit_type': UnitTypes.TROOP
        },
        {
            'territory_name': 'Moscow',
            'unit_type': UnitTypes.TROOP
        },
    ]
    player = Player("Turkey", game_map, starting_configuration)

    commands = [
        ConvoyMoveCommand(player, player.units[0], 'Sevastopol'),
        ConvoyTransportCommand(player, player.units[1], player.units[0],
                               'Sevastopol'),
        MoveCommand(player, player.units[2], 'Rumania'),
        MoveCommand(player, player.units[3], 'Sevastopol Coast'),
        SupportCommand(player, player.units[4], player.units[3],
                       'Sevastopol Coast'),
        MoveCommand(player, player.units[5], 'Sevastopol'),
    ]
    command_map = CommandMap(game_map, commands)

    assert command_map._home_map == {
        'Ankara': commands[0],
        'Black Sea': commands[1],
        'Budapest': commands[2],
        'Rumania': commands[3],
        'Ukraine': commands[4],
        'Moscow': commands[5],
    }
    assert command_map._attacker_map == {
        'Rumania': [commands[2]],
        'Sevastopol': [commands[3], commands[5]],
    }
    assert command_map._convoy_attacker_map == {
        'Sevastopol': [commands[0]],
    }
    assert command_map._transport_map == {
        ('Ankara', 'Sevastopol'): [commands[1]],
    }
    assert command_map._support_map == {
        ('Rumania', 'Sevastopol'): [commands[4]],
    }
Ejemplo n.º 20
0
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,
        }
    }
Ejemplo n.º 21
0
def test_c_5__disrupted_circular_movement_due_to_dislodged_convoy():
    """
    AUSTRIA: A Trieste -> Serbia
             A Serbia -> Bulgaria

    TURKEY:  A Bulgaria -> Trieste (Convoy)
             F Aegean Sea Transports Bulgaria -> Trieste
             F Ionian Sea Transports Bulgaria -> Trieste
             F Adriatic Sea Transports Bulgaria -> Trieste

    ITALY:   F Naples Coast -> Ionian Sea
             F Tunis Coast Supports Naples Coast -> Ionian Sea
    """
    game_map = generate_map()

    austria_starting_configuration = [
        {
            'territory_name': 'Trieste',
            'unit_type': UnitTypes.TROOP
        },
        {
            'territory_name': 'Serbia',
            'unit_type': UnitTypes.TROOP
        },
    ]
    austria = Player("Austria", game_map, austria_starting_configuration)

    turkey_starting_configuration = [
        {
            'territory_name': 'Bulgaria',
            'unit_type': UnitTypes.TROOP
        },
        {
            'territory_name': 'Aegean Sea',
            'unit_type': UnitTypes.FLEET
        },
        {
            'territory_name': 'Ionian Sea',
            'unit_type': UnitTypes.FLEET
        },
        {
            'territory_name': 'Adriatic Sea',
            'unit_type': UnitTypes.FLEET
        },
    ]
    turkey = Player("Turkey", game_map, turkey_starting_configuration)

    italy_starting_configuration = [
        {
            'territory_name': 'Naples Coast',
            'unit_type': UnitTypes.FLEET
        },
        {
            'territory_name': 'Tunis Coast',
            'unit_type': UnitTypes.FLEET
        },
    ]
    italy = Player("Italy", game_map, italy_starting_configuration)

    commands = [
        MoveCommand(austria, austria.units[0], 'Serbia'),
        MoveCommand(austria, austria.units[1], 'Bulgaria'),
        ConvoyMoveCommand(turkey, turkey.units[0], 'Trieste'),
        ConvoyTransportCommand(turkey, turkey.units[1], turkey.units[0],
                               'Trieste'),
        ConvoyTransportCommand(turkey, turkey.units[2], turkey.units[0],
                               'Trieste'),
        ConvoyTransportCommand(turkey, turkey.units[3], turkey.units[0],
                               'Trieste'),
        MoveCommand(italy, italy.units[0], 'Ionian Sea'),
        SupportCommand(italy, italy.units[1], italy.units[0], 'Ionian Sea'),
    ]
    result = resolve_turn(game_map, commands)
    assert result == {
        'Austria': {
            Unit(UnitTypes.TROOP, 'Trieste'): None,
            Unit(UnitTypes.TROOP, 'Serbia'): None,
        },
        'Turkey': {
            Unit(UnitTypes.TROOP, 'Bulgaria'): None,
            Unit(UnitTypes.FLEET, 'Aegean Sea'): None,
            Unit(UnitTypes.FLEET, 'Ionian Sea'): {
                'Apulia Coast',
                'Albania Coast',
                'Greece Coast',
                'Eastern Mediterranean Sea',
                'Tyrrhenian Sea',
            },
            Unit(UnitTypes.FLEET, 'Adriatic Sea'): None,
        },
        'Italy': {
            Unit(UnitTypes.FLEET, 'Ionian Sea'): None,
            Unit(UnitTypes.FLEET, 'Tunis Coast'): None,
        },
    }