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, }, }
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 }, }
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_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 }, }
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, } }
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()
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_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_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)
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)
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_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_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, } }
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')
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')
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')]
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_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')
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')
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')
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')
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_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_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_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_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_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_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_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')