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,
        },
    }
Esempio n. 2
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()
Esempio n. 3
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')
Esempio n. 4
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')
Esempio n. 5
0
def test_convoy_move_success():
    game_map = generate_map()
    starting_configuration = [
        {
            'territory_name': 'Constantinople',
            'unit_type': UnitTypes.TROOP
        },
    ]
    player = Player("France", game_map, starting_configuration)

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

    assert command.unit.position == 'Constantinople'
    assert command.destination == 'Tunis'
Esempio n. 6
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))
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')
def test_a_7__fleet_cannot_be_convoyed():
    """
    ENGLAND: F Convoy London Coast -> Belgium Coast
             F North Sea Transport London Coast -> Belgium Coast
    """
    game_map = generate_map()
    starting_configuration = [
        {
            'territory_name': 'London Coast',
            'unit_type': UnitTypes.FLEET
        },
        {
            'territory_name': 'North Sea',
            'unit_type': UnitTypes.FLEET
        },
    ]
    player = Player("England", game_map, starting_configuration)

    with pytest.raises(AssertionError):
        ConvoyMoveCommand(player, player.units[0], 'Belgium Coast')
    with pytest.raises(AssertionError):
        ConvoyTransportCommand(player, player.units[1], player.units[0],
                               'Belgium Coast')
def test_a_5__check_convoy_to_same_territory_fails():
    """
    ENGLAND: A Convoy Yorkshire -> Yorkshire
             F North Sea Transport Yorkshire -> Yorkshire
    """
    # Modified from original check: we treat both commands as illegal, so no resolution check needed.
    game_map = generate_map()
    starting_configuration = [
        {
            'territory_name': 'Yorkshire',
            'unit_type': UnitTypes.TROOP
        },
        {
            'territory_name': 'North Sea',
            'unit_type': UnitTypes.FLEET
        },
    ]
    player = Player("England", game_map, starting_configuration)

    with pytest.raises(AssertionError):
        ConvoyMoveCommand(player, player.units[0], 'Yorkshire')
    with pytest.raises(AssertionError):
        ConvoyTransportCommand(player, player.units[1], player.units[0],
                               'Yorkshire')
Esempio n. 10
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]],
    }
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,
        },
    }