コード例 #1
0
ファイル: test_c.py プロジェクト: zingbretsen/diplomacy
    def test_disrupted_three_army_circular_movement(self):
        """
        When one of the units bounces, the whole circular movement will hold.

        Turkey:
        F Ankara - Constantinople
        A Constantinople - Smyrna
        A Smyrna - Ankara
        A Bulgaria - Constantinople

        Every unit will keep its place.
        """
        pieces = [
            Fleet(0, Nations.TURKEY, self.territories.ANKARA),
            Army(0, Nations.TURKEY, self.territories.BULGARIA),
            Army(0, Nations.TURKEY, self.territories.CONSTANTINOPLE),
            Army(0, Nations.TURKEY, self.territories.SMYRNA)
        ]
        orders = [
            Move(0, Nations.TURKEY, self.territories.ANKARA,
                 self.territories.CONSTANTINOPLE),
            Move(0, Nations.TURKEY, self.territories.CONSTANTINOPLE,
                 self.territories.SMYRNA),
            Move(0, Nations.TURKEY, self.territories.SMYRNA,
                 self.territories.ANKARA),
            Move(0, Nations.TURKEY, self.territories.BULGARIA,
                 self.territories.CONSTANTINOPLE),
        ]

        self.state.register(*pieces, *orders)
        self.state.post_register_updates()
        process(self.state)

        self.assertEqual(orders[0].outcome, Outcomes.FAILS)
        self.assertEqual(orders[1].outcome, Outcomes.FAILS)
        self.assertEqual(orders[2].outcome, Outcomes.FAILS)
        self.assertEqual(orders[3].outcome, Outcomes.FAILS)
コード例 #2
0
    def test_army_being_convoyed_can_bounce_as_normal(self):
        """
        Armies being convoyed bounce on other units just as armies that are not
        being convoyed.

        England:
        F English Channel Convoys A London - Brest
        A London - Brest

        France:
        A Paris - Brest

        The English army in London bounces on the French army in Paris. Both
        units do not move.
        """
        Fleet(self.state, 0, Nations.ENGLAND,
              self.territories.ENGLISH_CHANNEL),
        Army(self.state, 0, Nations.ENGLAND, self.territories.LONDON),
        Army(self.state, 0, Nations.FRANCE, self.territories.PARIS),
        orders = [
            Convoy(self.state, 0, Nations.ENGLAND,
                   self.territories.ENGLISH_CHANNEL, self.territories.LONDON,
                   self.territories.BREST),
            Move(self.state,
                 0,
                 Nations.ENGLAND,
                 self.territories.LONDON,
                 self.territories.BREST,
                 via_convoy=True),
            Move(self.state, 0, Nations.FRANCE, self.territories.PARIS,
                 self.territories.BREST),
        ]
        process(self.state)

        self.assertEqual(orders[1].path_decision(), Outcomes.PATH)
        self.assertEqual(orders[1].outcome, Outcomes.FAILS)
        self.assertEqual(orders[2].outcome, Outcomes.FAILS)
コード例 #3
0
    def test_attacked_convoy_is_not_disrupted(self):
        """
        A convoy can only be disrupted by dislodging the fleets. Attacking is
        not sufficient.

        England:
        F North Sea Convoys A London - Holland
        A London - Holland

        Germany:
        F Skagerrak - North Sea

        The army in London will successfully convoy and end in Holland.
        """
        pieces = [
            Fleet(0, Nations.ENGLAND, self.territories.NORTH_SEA),
            Army(0, Nations.ENGLAND, self.territories.LONDON),
            Fleet(0, Nations.GERMANY, self.territories.SKAGERRAK)
        ]
        orders = [
            Convoy(0, Nations.ENGLAND, self.territories.NORTH_SEA,
                   self.territories.LONDON, self.territories.HOLLAND),
            Move(0,
                 Nations.ENGLAND,
                 self.territories.LONDON,
                 self.territories.HOLLAND,
                 via_convoy=True),
            Move(0, Nations.GERMANY, self.territories.SKAGERRAK,
                 self.territories.NORTH_SEA),
        ]
        self.state.register(*pieces, *orders)
        self.state.post_register_updates()
        process(self.state)

        self.assertEqual(orders[1].path_decision(), Outcomes.PATH)
        self.assertEqual(orders[1].outcome, Outcomes.SUCCEEDS)
        self.assertEqual(orders[2].outcome, Outcomes.FAILS)
コード例 #4
0
ファイル: test_e.py プロジェクト: zingbretsen/diplomacy
    def test_disloged_unit_has_not_effect_on_attackers_area(self):
        """
        An army can follow.

        Germany:
        A Berlin - Prussia
        F Kiel - Berlin
        A Silesia Supports A Berlin - Prussia

        Russia:
        A Prussia - Berlin

        The fleet in Kiel will move to Berlin.
        """
        pieces = [
            Army(0, Nations.GERMANY, self.territories.BERLIN),
            Fleet(0, Nations.GERMANY, self.territories.KIEL),
            Army(0, Nations.GERMANY, self.territories.SILESIA),
            Army(0, Nations.RUSSIA, self.territories.PRUSSIA),
        ]
        orders = [
            Move(0, Nations.GERMANY, self.territories.BERLIN,
                 self.territories.PRUSSIA),
            Move(0, Nations.GERMANY, self.territories.KIEL,
                 self.territories.BERLIN),
            Support(0, Nations.GERMANY, self.territories.SILESIA,
                    self.territories.BERLIN, self.territories.PRUSSIA),
            Move(0, Nations.RUSSIA, self.territories.PRUSSIA,
                 self.territories.BERLIN),
        ]
        self.state.register(*pieces, *orders)
        self.state.post_register_updates()
        process(self.state)

        self.assertTrue(orders[0].outcome, Outcomes.SUCCEEDS)
        self.assertTrue(orders[1].outcome, Outcomes.SUCCEEDS)
        self.assertTrue(orders[2].outcome, Outcomes.SUCCEEDS)
コード例 #5
0
ファイル: test_a.py プロジェクト: zingbretsen/diplomacy
    def test_bounce_of_three_units(self):
        """
        If three units move to the same place, the adjudicator should not
        bounce the first two units and then let the third unit go to the now
        open place.

        Austria:
        A Vienna - Tyrolia

        Germany:
        A Munich - Tyrolia

        Italy:
        A Venice - Tyrolia

        The three units bounce.
        """
        pieces = [
            Army(0, Nations.AUSTRIA, self.territories.VIENNA),
            Army(0, Nations.ITALY, self.territories.VENICE),
            Army(0, Nations.GERMANY, self.territories.MUNICH)
        ]

        army_vienna_move = Move(0, Nations.AUSTRIA, self.territories.VIENNA, self.territories.TYROLIA)
        army_venice_move = Move(0, Nations.ITALY, self.territories.VENICE, self.territories.TYROLIA)
        army_munich_move = Move(0, Nations.GERMANY, self.territories.MUNICH, self.territories.TYROLIA)

        self.state.register(*pieces, army_venice_move, army_vienna_move, army_munich_move)
        process(self.state)

        self.assertTrue(army_venice_move.legal)
        self.assertTrue(army_vienna_move.legal)
        self.assertTrue(army_munich_move.legal)

        self.assertEqual(army_vienna_move.outcome, Outcomes.FAILS)
        self.assertEqual(army_venice_move.outcome, Outcomes.FAILS)
        self.assertEqual(army_munich_move.outcome, Outcomes.FAILS)
コード例 #6
0
    def test_three_army_circular_movement_with_support(self):
        """
        Three units can change place, even when one gets support.

        Turkey:
        F Ankara - Constantinople
        A Constantinople - Smyrna
        A Smyrna - Ankara
        A Bulgaria Supports F Ankara - Constantinople

        Of course the three units will move, but knowing how programs are
        written, this can confuse the adjudicator.
        """
        pieces = [
            Fleet(Nations.TURKEY, self.territories.ANKARA),
            Army(Nations.TURKEY, self.territories.BULGARIA),
            Army(Nations.TURKEY, self.territories.CONSTANTINOPLE),
            Army(Nations.TURKEY, self.territories.SMYRNA)
        ]
        orders = [
            Move(Nations.TURKEY, self.territories.ANKARA,
                 self.territories.CONSTANTINOPLE),
            Move(Nations.TURKEY, self.territories.CONSTANTINOPLE,
                 self.territories.SMYRNA),
            Move(Nations.TURKEY, self.territories.SMYRNA,
                 self.territories.ANKARA),
            Support(Nations.TURKEY, self.territories.BULGARIA,
                    self.territories.ANKARA, self.territories.CONSTANTINOPLE),
        ]
        self.state.register(*pieces, *orders)
        self.state.post_register_updates()
        process(self.state)

        self.assertEqual(orders[0].move_decision, Outcomes.MOVES)
        self.assertEqual(orders[1].move_decision, Outcomes.MOVES)
        self.assertEqual(orders[2].move_decision, Outcomes.MOVES)
        self.assertEqual(orders[3].support_decision, Outcomes.GIVEN)
コード例 #7
0
    def test_five_army_circular_movement(self):

        Fleet(self.state, 0, Nations.TURKEY, self.territories.ANKARA),
        Army(self.state, 0, Nations.TURKEY, self.territories.CONSTANTINOPLE),
        Army(self.state, 0, Nations.TURKEY, self.territories.SMYRNA),
        Army(self.state, 0, Nations.TURKEY, self.territories.ARMENIA),
        Army(self.state, 0, Nations.TURKEY, self.territories.SYRIA),

        orders = [
            Move(self.state, 0, Nations.TURKEY, self.territories.ANKARA,
                 self.territories.CONSTANTINOPLE),
            Move(self.state, 0, Nations.TURKEY,
                 self.territories.CONSTANTINOPLE, self.territories.SMYRNA),
            Move(self.state, 0, Nations.TURKEY, self.territories.SMYRNA,
                 self.territories.SYRIA),
            Move(self.state, 0, Nations.TURKEY, self.territories.SYRIA,
                 self.territories.ARMENIA),
            Move(self.state, 0, Nations.TURKEY, self.territories.ARMENIA,
                 self.territories.ANKARA),
        ]
        result = find_circular_movements(orders)

        self.assertEqual(len(result), 1)
        self.assertTrue(all([o in result[0] for o in orders]))
コード例 #8
0
ファイル: test_g.py プロジェクト: johnpooch/diplomacy
    def test_kidnapping_an_army(self):
        """
        Germany promised England to support to dislodge the Russian fleet in
        Sweden and it promised Russia to support to dislodge the English army
        in Norway. Instead, the joking German orders a convoy.

        England:
        A Norway - Sweden

        Russia:
        F Sweden - Norway

        Germany:
        F Skagerrak Convoys A Norway - Sweden
        See issue 4.A.3.

        When the 1982/2000 rulebook is used (which I prefer), England has no
        intent to swap and it is just a head to head battle were both units
        will fail to move. When explicit adjacent convoying is used (DPTG), the
        English move is not a convoy and again it just a head to head battle
        were both units will fail to move. In all other interpretations, the
        army in Norway will be convoyed and swap its place with the fleet in
        Sweden.
        """
        Army(self.state, 0, Nations.ENGLAND, self.territories.NORWAY),
        Fleet(self.state, 0, Nations.RUSSIA, self.territories.SKAGERRAK),
        Army(self.state, 0, Nations.RUSSIA, self.territories.SWEDEN),
        orders = [
            Move(self.state, 0, Nations.ENGLAND, self.territories.NORWAY, self.territories.SWEDEN),
            Convoy(self.state, 0, Nations.RUSSIA, self.territories.SKAGERRAK, self.territories.NORWAY, self.territories.SWEDEN),
            Move(self.state, 0, Nations.RUSSIA, self.territories.SWEDEN, self.territories.NORWAY),
        ]
        process(self.state)

        self.assertEqual(orders[0].outcome, Outcomes.FAILS)
        self.assertEqual(orders[2].outcome, Outcomes.FAILS)
コード例 #9
0
    def test_moving_with_unspecified_coast_when_coast_necessary(self):
        """
        Coast is significant in this case:

        France:
        F Portugal - Spain

        Some adjudicators take a default coast (see issue 4.B.1).

        I prefer that the move fails.
        """
        Fleet(self.state, 0, Nations.FRANCE, self.territories.PORTUGAL)
        Move(self.state, 0, Nations.FRANCE, self.territories.PORTUGAL,
             self.territories.SPAIN)

        with self.assertRaises(ValueError):
            process(self.state)
コード例 #10
0
    def test_move_army_to_sea(self):
        """
        Check if an army could not be moved to open sea.

        England:
        A Liverpool - Irish Sea

        Order should fail.
        """
        army = Army(Nations.ENGLAND, self.territories.LIVERPOOL)
        order = Move(Nations.ENGLAND, self.territories.LIVERPOOL,
                     self.territories.IRISH_SEA)

        self.state.register(army, order)
        process(self.state)

        self.assertEqual(order.legal_decision, Outcomes.ILLEGAL)
        self.assertEqual(order.illegal_message, illegal_messages.M005)
コード例 #11
0
    def test_moving_to_an_area_that_is_not_a_neighbour(self):
        """
        Check if an illegal move (without convoy) will fail.

        England:
        F North Sea - Picardy

        Order should fail.
        """
        fleet = Fleet(Nations.ENGLAND, self.territories.NORTH_SEA)
        order = Move(Nations.ENGLAND, self.territories.NORTH_SEA,
                     self.territories.PICARDY)

        self.state.register(fleet, order)
        process(self.state)

        self.assertEqual(order.legal_decision, Outcomes.ILLEGAL)
        self.assertEqual(order.illegal_message, illegal_messages.M004)
コード例 #12
0
    def test_move_fleet_to_land(self):
        """
        Check whether a fleet can not move to land.

        Germany:
        F Kiel - Munich

        Order should fail.
        """
        fleet = Fleet(Nations.GERMANY, self.territories.KIEL)
        order = Move(Nations.GERMANY, self.territories.KIEL,
                     self.territories.MUNICH)

        self.state.register(fleet, order)
        process(self.state)

        self.assertEqual(order.legal_decision, Outcomes.ILLEGAL)
        self.assertEqual(order.illegal_message, illegal_messages.M006)
コード例 #13
0
    def test_support_from_unreachable_coast_not_allowed(self):
        """
        A fleet can not give support to an area that can not be reached from
        the current coast of the fleet.

        France:
        F Marseilles - Gulf of Lyon
        F Spain(nc) Supports F Marseilles - Gulf of Lyon

        Italy:
        F Gulf of Lyon Hold

        The Gulf of Lyon can not be reached from the North Coast of Spain.
        Therefore, the support of Spain is invalid and the fleet in the Gulf of
        Lyon is not dislodged.
        """
        pieces = [
            Fleet(self.state, 0, Nations.FRANCE, self.territories.MARSEILLES),
            Fleet(self.state,
                  0,
                  Nations.FRANCE,
                  self.territories.SPAIN,
                  named_coast=self.named_coasts.SPAIN_NC),
            Fleet(self.state, 0, Nations.ITALY, self.territories.GULF_OF_LYON)
        ]

        fleet_marseilles_move = Move(self.state, 0, Nations.FRANCE,
                                     self.territories.MARSEILLES,
                                     self.territories.GULF_OF_LYON)
        fleet_spain_nc_support = Support(self.state, 0, Nations.FRANCE,
                                         self.territories.SPAIN,
                                         self.territories.MARSEILLES,
                                         self.territories.GULF_OF_LYON)
        Hold(self.state, 0, Nations.ITALY, self.territories.GULF_OF_LYON)

        process(self.state)

        self.assertTrue(fleet_spain_nc_support.illegal)
        self.assertEqual(fleet_spain_nc_support.illegal_code, '010')
        self.assertEqual(fleet_spain_nc_support.illegal_verbose,
                         'Piece cannot reach that territory.')
        self.assertEqual(fleet_marseilles_move.outcome, Outcomes.FAILS)
        self.assertEqual(pieces[2].dislodged_decision, Outcomes.SUSTAINS)
コード例 #14
0
    def test_ordering_a_unit_of_another_country(self):
        """
        Check whether someone can not order a unit that does not belong to them.

        England has a fleet in London.

        Germany:
        F London - North Sea

        Order should fail.
        """
        fleet = Fleet(Nations.ENGLAND, self.territories.LONDON)
        order = Move(Nations.GERMANY, self.territories.LONDON,
                     self.territories.NORTH_SEA)

        self.state.register(fleet, order)
        process(self.state)

        self.assertEqual(order.legal_decision, Outcomes.ILLEGAL)
        self.assertEqual(order.illegal_message, illegal_messages.A001)
コード例 #15
0
    def test_move_to_own_sector(self):
        """
        Moving to the same sector is an illegal move (2000 rulebook, page 4,
        "An Army can be ordered to move into an adjacent inland or coastal
        province.").

        Germany:
        F Kiel - Kiel

        Program should not crash.
        """
        army = Army(Nations.GERMANY, self.territories.KIEL)
        order = Move(Nations.GERMANY, self.territories.KIEL,
                     self.territories.KIEL)

        self.state.register(army, order)
        process(self.state)

        self.assertEqual(order.legal_decision, Outcomes.ILLEGAL)
        self.assertEqual(order.illegal_message, illegal_messages.M002)
コード例 #16
0
    def test_fleet_must_follow_coast_if_not_on_sea(self):
        """
        If two places are adjacent, that does not mean that a fleet can move
        between those two places. An implementation that only holds one list of
        adjacent places for each place, is incorrect.

        Italy:
        F Rome - Venice

        Move fails. An army can go from Rome to Venice, but a fleet can not.
        """
        fleet = Fleet(Nations.ITALY, self.territories.ROME,
                      self.territories.VENICE)
        order = Move(Nations.ITALY, self.territories.ROME,
                     self.territories.VENICE)

        self.state.register(order, fleet)
        process(self.state)

        self.assertEqual(order.legal_decision, Outcomes.ILLEGAL)
        self.assertEqual(order.illegal_message, illegal_messages.M007)
コード例 #17
0
    def test_army_movement_with_coastal_specification(self):
        """
        For armies the coasts are irrelevant:

        France:
        A Gascony - Spain(nc)

        If only perfect orders are accepted, then the move will fail. But it is
        also possible that coasts are ignored in this case and a move will be
        attempted (see issue 4.B.6).

        I prefer that a move will be attempted.
        """
        Army(self.state, 0, Nations.FRANCE, self.territories.GASCONY)
        move = Move(self.state, 0, Nations.FRANCE, self.territories.GASCONY,
                    self.territories.SPAIN, self.named_coasts.SPAIN_NC)

        process(self.state)

        self.assertEqual(move.outcome, Outcomes.SUCCEEDS)
        self.assertTrue(move.legal)
コード例 #18
0
    def test_moving_with_wrong_coast_when_coast_is_not_necessary(self):
        """
        If only one coast is possible, but the wrong coast can be specified.

        France:
        F Gascony - Spain(sc)

        If the rules are played very clemently, a move will be attempted to the
        north coast of Spain. However, since this order is very clear and
        precise, it is more common that the move fails (see issue 4.B.3).

        I prefer that the move fails.
        """
        fleet = Fleet(Nations.FRANCE, self.territories.GASCONY)
        order = Move(Nations.FRANCE, self.territories.GASCONY, self.territories.SPAIN, self.named_coasts.SPAIN_SC)

        self.state.register(fleet, order)
        process(self.state)

        self.assertEqual(order.legal_decision, Outcomes.ILLEGAL)
        self.assertEqual(order.illegal_message, illegal_messages.M007)
コード例 #19
0
ファイル: test_a.py プロジェクト: johnpooch/diplomacy
    def test_move_army_to_sea(self):
        """
        Check if an army could not be moved to open sea.

        England:
        A Liverpool - Irish Sea

        Order should fail.
        """
        Army(self.state, 0, Nations.ENGLAND, self.territories.LIVERPOOL)
        order = Move(self.state, 0, Nations.ENGLAND, self.territories.LIVERPOOL, self.territories.IRISH_SEA)

        process(self.state)

        self.assertTrue(order.illegal)
        self.assertEqual(order.outcome, Outcomes.FAILS)
        self.assertEqual(order.illegal_code, '005')
        self.assertEqual(
            order.illegal_verbose,
            'Army cannot enter a sea territory'
        )
コード例 #20
0
    def test_coast_cannot_be_ordered_to_change(self):
        """
        The coast can not change by just ordering the other coast.

        France has a fleet on the north coast of Spain and orders:

        France:
        F Spain(sc) - Gulf of Lyon

        The move fails.
        """
        # Not really relevant because can't specify source coast
        fleet = Fleet(Nations.FRANCE, self.territories.SPAIN, self.named_coasts.SPAIN_NC)
        move = Move(Nations.FRANCE, self.territories.SPAIN, self.territories.SPAIN, self.named_coasts.SPAIN_SC)

        self.state.register(fleet, move)
        self.state.post_register_updates()
        process(self.state)

        self.assertEqual(move.legal_decision, Outcomes.ILLEGAL)
        self.assertEqual(move.illegal_message, illegal_messages.M002)
コード例 #21
0
ファイル: test_a.py プロジェクト: johnpooch/diplomacy
    def test_moving_to_an_area_that_is_not_a_neighbour(self):
        """
        Check if an illegal move (without convoy) will fail.

        England:
        F North Sea - Picardy

        Order should fail.
        """
        Fleet(self.state, 0, Nations.ENGLAND, self.territories.NORTH_SEA)
        order = Move(self.state, 0, Nations.ENGLAND, self.territories.NORTH_SEA, self.territories.PICARDY)

        process(self.state)

        self.assertTrue(order.illegal)
        self.assertEqual(order.outcome, Outcomes.FAILS)
        self.assertEqual(order.illegal_code, '004')
        self.assertEqual(
            order.illegal_verbose,
            'Fleet cannot reach non-adjacent territory.'
        )
コード例 #22
0
    def test_no_convoy_in_coastal_area(self):
        """
        A fleet in a coastal area may not convoy.

        Turkey:
        A Greece - Sevastopol
        F Aegean Sea Convoys A Greece - Sevastopol
        F Constantinople Convoys A Greece - Sevastopol
        F Black Sea Convoys A Greece - Sevastopol

        The convoy in Constantinople is not possible. So, the army in Greece
        will not move to Sevastopol.
        """
        pieces = [
            Army(0, Nations.TURKEY, self.territories.GREECE),
            Fleet(0, Nations.TURKEY, self.territories.AEGEAN_SEA),
            Fleet(0, Nations.TURKEY, self.territories.CONSTANTINOPLE),
            Fleet(0, Nations.TURKEY, self.territories.BLACK_SEA),
        ]
        orders = [
            Move(0,
                 Nations.TURKEY,
                 self.territories.GREECE,
                 self.territories.SEVASTAPOL,
                 via_convoy=True),
            Convoy(0, Nations.TURKEY, self.territories.AEGEAN_SEA,
                   self.territories.GREECE, self.territories.SEVASTAPOL),
            Convoy(0, Nations.TURKEY, self.territories.CONSTANTINOPLE,
                   self.territories.GREECE, self.territories.SEVASTAPOL),
            Convoy(0, Nations.TURKEY, self.territories.BLACK_SEA,
                   self.territories.GREECE, self.territories.SEVASTAPOL),
        ]
        self.state.register(*pieces, *orders)
        self.state.post_register_updates()
        process(self.state)

        self.assertEqual(orders[0].outcome, Outcomes.FAILS)
        self.assertTrue(orders[0].legal)
        self.assertTrue(orders[2].illegal)
コード例 #23
0
    def test_moving_with_unspecified_coast_when_coast_unnecessary(self):
        """
        There is only one coast possible in this case:

        France:
        F Gascony - Spain

        Since the North Coast is the only coast that can be reached, it seems
        logical that the a move is attempted to the north coast of Spain. Some
        adjudicators require that a coast is also specified in this case and
        will decide that the move fails or take a default coast (see issue
        4.B.2).

        I prefer that an attempt is made to the only possible coast, the north
        coast of Spain.
        """
        fleet = Fleet(Nations.FRANCE, self.territories.GASCONY)
        order = Move(Nations.FRANCE, self.territories.GASCONY, self.territories.SPAIN)
        self.state.register(fleet, order)

        with self.assertRaises(ValueError):
            process(self.state)
コード例 #24
0
    def test_army_movement_with_coastal_specification(self):
        """
        For armies the coasts are irrelevant:

        France:
        A Gascony - Spain(nc)

        If only perfect orders are accepted, then the move will fail. But it is
        also possible that coasts are ignored in this case and a move will be
        attempted (see issue 4.B.6).

        I prefer that a move will be attempted.
        """
        army = Army(Nations.FRANCE, self.territories.GASCONY)
        move = Move(Nations.FRANCE, self.territories.GASCONY, self.territories.SPAIN, self.named_coasts.SPAIN_NC)

        self.state.register(army, move)
        self.state.post_register_updates()
        process(self.state)

        self.assertEqual(move.move_decision, Outcomes.MOVES)
        self.assertEqual(move.legal_decision, Outcomes.LEGAL)
コード例 #25
0
ファイル: test_a.py プロジェクト: johnpooch/diplomacy
    def test_move_to_own_sector(self):
        """
        Moving to the same sector is an illegal move (2000 rulebook, page 4,
        "An Army can be ordered to move into an adjacent inland or coastal
        province.").

        Germany:
        F Kiel - Kiel

        Program should not crash.
        """
        Army(self.state, 0, Nations.GERMANY, self.territories.KIEL)
        order = Move(self.state, 0, Nations.GERMANY, self.territories.KIEL, self.territories.KIEL)

        process(self.state)

        self.assertTrue(order.illegal)
        self.assertEqual(order.illegal_code, '002')
        self.assertEqual(
            order.illegal_verbose,
            'Source and target cannot be the same territory.'
        )
コード例 #26
0
ファイル: test_a.py プロジェクト: johnpooch/diplomacy
    def test_fleet_must_follow_coast_if_not_on_sea(self):
        """
        If two places are adjacent, that does not mean that a fleet can move
        between those two places. An implementation that only holds one list of
        adjacent places for each place, is incorrect.

        Italy:
        F Rome - Venice

        Move fails. An army can go from Rome to Venice, but a fleet can not.
        """
        Fleet(self.state, 0, Nations.ITALY, self.territories.ROME)
        order = Move(self.state, 0, Nations.ITALY, self.territories.ROME, self.territories.VENICE)

        process(self.state)

        self.assertTrue(order.illegal)
        self.assertEqual(order.illegal_code, '007')
        self.assertEqual(
            order.illegal_verbose,
            'Fleet cannot reach coastal territory without shared coastline.'
        )
コード例 #27
0
    def test_support_to_hold_yourself_not_possible(self):
        """
        An army can not get an additional hold power by supporting itself.

        Italy:
        A Venice - Trieste
        A Tyrolia Supports A Venice - Trieste

        Austria:
        F Trieste Supports F Trieste

        The fleet in Trieste should be dislodged.
        """
        pieces = [
            Army(Nations.ITALY, self.territories.VENICE),
            Army(Nations.ITALY, self.territories.TYROLIA),
            Fleet(Nations.AUSTRIA, self.territories.TRIESTE)
        ]

        # TODO finish
        army_venice_move = Move(Nations.ITALY, self.territories.VENICE,
                                self.territories.TRIESTE)
        army_tyrolia_support = Support(Nations.ITALY, self.territories.TYROLIA,
                                       self.territories.VENICE,
                                       self.territories.TRIESTE)
        fleet_trieste_support = Support(Nations.AUSTRIA,
                                        self.territories.TRIESTE,
                                        self.territories.TRIESTE,
                                        self.territories.TRIESTE)

        self.state.register(*pieces, army_venice_move, army_tyrolia_support,
                            fleet_trieste_support)
        process(self.state)

        self.assertEqual(fleet_trieste_support.legal_decision,
                         Outcomes.ILLEGAL)
        self.assertEqual(fleet_trieste_support.illegal_message,
                         illegal_messages.S001)
コード例 #28
0
ファイル: test_a.py プロジェクト: zingbretsen/diplomacy
    def test_ordering_a_unit_of_another_country(self):
        """
        Check whether someone can not order a unit that does not belong to them.

        England has a fleet in London.

        Germany:
        F London - North Sea

        Order should fail.
        """
        fleet = Fleet(0, Nations.ENGLAND, self.territories.LONDON)
        order = Move(0, Nations.GERMANY, self.territories.LONDON, self.territories.NORTH_SEA)

        self.state.register(fleet, order)
        process(self.state)

        self.assertTrue(order.illegal)
        self.assertEqual(order.illegal_code, '001')
        self.assertEqual(
            order.illegal_verbose,
            'Cannot order a piece belonging to another nation.'
        )
コード例 #29
0
    def test_moving_with_wrong_coast_when_coast_is_not_necessary(self):
        """
        If only one coast is possible, but the wrong coast can be specified.

        France:
        F Gascony - Spain(sc)

        If the rules are played very clemently, a move will be attempted to the
        north coast of Spain. However, since this order is very clear and
        precise, it is more common that the move fails (see issue 4.B.3).

        I prefer that the move fails.
        """
        Fleet(self.state, 0, Nations.FRANCE, self.territories.GASCONY)
        order = Move(self.state, 0, Nations.FRANCE, self.territories.GASCONY,
                     self.territories.SPAIN, self.named_coasts.SPAIN_SC)

        process(self.state)

        self.assertTrue(order.illegal)
        self.assertEqual(
            order.illegal_verbose,
            'Fleet cannot reach coastal territory without shared coastline.')
コード例 #30
0
    def test_support_on_unreachable_destination_not_possible(self):
        """
        The destination of the move that is supported must be reachable by the
        supporting unit.

        Austria:
        A Venice Hold

        Italy:
        F Rome Supports A Apulia - Venice
        A Apulia - Venice

        The support of Rome is illegal, because Venice can not be reached from
        Rome by a fleet. Venice is not dislodged.
        """
        pieces = [
            Army(Nations.AUSTRIA, self.territories.VENICE),
            Fleet(Nations.ITALY, self.territories.ROME),
            Army(Nations.ITALY, self.territories.APULIA)
        ]

        # TODO finish
        army_austria_hold = Hold(Nations.AUSTRIA, self.territories.VENICE)
        fleet_rome_support = Support(Nations.ITALY, self.territories.ROME,
                                     self.territories.APULIA,
                                     self.territories.VENICE)
        army_apulia_move = Move(Nations.ITALY, self.territories.APULIA,
                                self.territories.VENICE)

        self.state.register(*pieces, army_austria_hold, fleet_rome_support,
                            army_apulia_move)
        self.state.post_register_updates()
        process(self.state)

        self.assertEqual(fleet_rome_support.legal_decision, Outcomes.ILLEGAL)
        self.assertEqual(fleet_rome_support.illegal_message,
                         illegal_messages.S002)