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_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_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_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_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, }, }
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_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_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_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_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')
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_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])
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'
def test_move_coast_to_coast(): game_map = generate_map() starting_configuration = [ { 'territory_name': 'Spain North Coast', 'unit_type': UnitTypes.FLEET }, ] player = Player("France", game_map, starting_configuration) command = MoveCommand(player, player.units[0], 'Portugal Coast') assert command.unit.position == 'Spain North Coast' assert command.destination == 'Portugal Coast'
def test_move_sea_to_sea(): game_map = generate_map() starting_configuration = [ { 'territory_name': 'North Sea', 'unit_type': UnitTypes.FLEET }, ] player = Player("England", game_map, starting_configuration) command = MoveCommand(player, player.units[0], 'Norwegian Sea') assert command.unit.position == 'North Sea' assert command.destination == 'Norwegian Sea'
def test_move_land_to_land(): game_map = generate_map() starting_configuration = [ { 'territory_name': 'Paris', 'unit_type': UnitTypes.TROOP }, ] player = Player("France", game_map, starting_configuration) command = MoveCommand(player, player.units[0], 'Brest') assert command.unit.position == 'Paris' assert command.destination == 'Brest'
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')
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], }
def test__move_command(): game_map = generate_map() starting_configuration = [ { 'territory_name': 'Smyrna', 'unit_type': UnitTypes.TROOP }, ] player = Player("Turkey", game_map, starting_configuration) command = MoveCommand(player, player.units[0], 'Ankara') command_map = CommandMap(game_map, [command]) assert command_map._home_map == {'Smyrna': command} assert command_map._attacker_map == {'Ankara': [command]} assert command_map._convoy_attacker_map == dict() assert command_map._transport_map == dict() assert command_map._support_map == dict()
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_b_1__portugal_to_spain_mainland_disallowed(): """ FRANCE: F Portugal Coast -> Spain 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) with pytest.raises(AssertionError): MoveCommand(france, france.units[0], 'Spain')
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_11__coast_can_not_be_ordered_to_change(): """ FRANCE: F Spain North Coast -> Gulf of Lyon Adapted from original test. Original was trying to say that entering an incorrect coast doesn't let you get away with anything. This system does not allow such a command, so this is just asserting that fact. """ game_map = generate_map() france_starting_configuration = [ { 'territory_name': 'Spain North Coast', 'unit_type': UnitTypes.FLEET }, ] france = Player("France", game_map, france_starting_configuration) with pytest.raises(AssertionError): MoveCommand(france, france.units[0], 'Gulf of Lyon')
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_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_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, }, }