Exemple #1
0
    def test_complete_building(self):
        """ Complete a building by adding a material.
        """
        statue, temple, fountain, stairway = cm.get_cards(
            ['Statue', 'Temple', 'Fountain', 'Stairway'])
        self.p1.hand.set_content([statue])

        self.p1.buildings = [
            Building(temple, 'Marble', materials=[fountain, stairway])
        ]

        a = message.GameAction(message.CRAFTSMAN, temple, statue, None)
        self.game.handle(a)

        self.assertNotIn(statue, self.p1.hand)
        self.assertIn('Marble', self.p1.influence)
        self.assertTrue(
            self.game._player_has_active_building(self.p1, 'Temple'))

        # The completed building keeps its site. A copy is added to influence.
        self.assertEqual(
            self.p1.buildings[0],
            Building(temple,
                     'Marble',
                     materials=[fountain, stairway, statue],
                     complete=True))
Exemple #2
0
    def test_shrine_and_temple_hand_limit(self):
        d = self.deck

        self.p1.hand.set_content([])
        self.p1.buildings.append(Building(d.shrine, 'Brick', complete=True))
        self.p1.buildings.append(Building(d.temple, 'Marble', complete=True))

        a = message.GameAction(message.THINKERTYPE, False)
        self.game.handle(a)

        self.assertEqual(len(self.p1.hand), 11)
Exemple #3
0
    def test_fountain_add(self):
        """Test using a fountain to look at the top card and then add it as
        a material to a building, completing it.
        """
        bath, atrium, foundry = cm.get_cards(['Bath', 'Atrium', 'Foundry'])
        self.game.library.cards.insert(0, bath)

        self.p1.buildings.append(Building(atrium, 'Brick',
                                          materials=[foundry]))

        a = message.GameAction(message.USEFOUNTAIN, True)
        self.game.handle(a)

        self.assertEqual(self.p1.fountain_card, bath)
        self.assertEqual(self.game.expected_action, message.FOUNTAIN)

        a = message.GameAction(message.FOUNTAIN, atrium, bath, None)
        self.game.handle(a)

        self.assertNotIn(bath, self.p1.hand)
        self.assertIsNone(self.p1.fountain_card)

        self.assertTrue(
            self.game._player_has_active_building(self.p1, 'Atrium'))

        self.assertEqual(self.game.expected_action, message.THINKERORLEAD)
Exemple #4
0
    def test_start_and_add(self):
        """Start a building and add a material.
        """
        wall, tower = cm.get_cards(['Wall', 'Tower'])
        self.p1.stockpile.set_content([wall])
        self.p1.hand.set_content([tower])

        a = message.GameAction(message.ARCHITECT, tower, None, 'Concrete')
        self.game.handle(a)

        self.assertEqual(self.p1.buildings[0], Building(tower, 'Concrete'))

        a = message.GameAction(message.ARCHITECT, tower, wall, None)
        self.game.handle(a)

        self.assertEqual(self.p1.buildings[0],
                         Building(tower, 'Concrete', materials=[wall]))
Exemple #5
0
    def test_add_to_empty_building(self):
        """ Add a valid material to a building with no materials.
        """
        atrium, foundry = cm.get_cards(['Atrium', 'Foundry'])
        self.p1.hand.set_content([atrium])

        self.p1.buildings = [Building(foundry, 'Brick')]

        a = message.GameAction(message.CRAFTSMAN, foundry, atrium, None)
        self.game.handle(a)

        self.assertNotIn(atrium, self.p1.hand)

        self.assertEqual(self.p1.buildings[0],
                         Building(foundry, 'Brick', materials=[atrium]))

        self.assertFalse(
            self.game._player_has_active_building(self.p1, 'Foundry'))
Exemple #6
0
def decode_building(obj):
    building_dict = copy.deepcopy(obj)

    building_dict['materials'] = decode_zone(building_dict['materials'],
                                             'materials')
    building_dict['stairway_materials'] = decode_zone(
        building_dict['stairway_materials'], 'stairway_materials')
    building_dict['foundation'] = Card(building_dict['foundation'])

    return Building(**building_dict)
Exemple #7
0
    def test_follower_client(self):
        """ Add materials with subsequent architect client, even after thinking.
        """
        tower, wall, storeroom = cm.get_cards(['Tower', 'Wall', 'Storeroom'])
        self.p2.stockpile.set_content([wall, storeroom])
        self.p2.buildings = [Building(tower, 'Concrete')]

        # Skip p1 architects
        a = message.GameAction(message.ARCHITECT, None, None, None)
        self.game.handle(a)
        self.game.handle(a)

        a = message.GameAction(message.ARCHITECT, tower, wall, None)
        self.game.handle(a)

        self.assertEqual(self.p2.buildings[0],
                         Building(tower, 'Concrete', materials=[wall]))

        self.assertEqual(self.game.expected_action, message.THINKERORLEAD)
        self.assertEqual(self.game.leader_index, 1)
Exemple #8
0
    def test_add_to_nonempty_building(self):
        """ Add a valid material to a building with one material, but this
        does not complete it.
        """
        statue, temple, fountain, stairway = cm.get_cards(
            ['Statue', 'Temple', 'Fountain', 'Stairway'])
        self.p1.hand.set_content([statue])

        self.p1.buildings = [Building(temple, 'Marble', materials=[fountain])]

        a = message.GameAction(message.CRAFTSMAN, temple, statue, None)
        self.game.handle(a)

        self.assertNotIn(statue, self.p1.hand)

        self.assertEqual(
            self.p1.buildings[0],
            Building(temple, 'Marble', materials=[fountain, statue]))

        self.assertFalse(
            self.game._player_has_active_building(self.p1, 'Temple'))
Exemple #9
0
    def test_add_to_nonempty_building(self):
        """ Add a valid material to a building with one material, but this
        does not complete it.
        """
        statue = cm.get_card('Statue')
        temple = cm.get_card('Temple')
        stairway = cm.get_card('Stairway')
        self.p1.stockpile.set_content([statue])
        self.p1.buildings = [Building(temple, 'Marble', materials=[stairway])]

        a = message.GameAction(message.ARCHITECT, temple, statue, None)
        self.game.handle(a)

        self.assertNotIn(statue, self.p1.stockpile)

        self.assertEqual(
            self.p1.buildings[0],
            Building(temple, 'Marble', materials=[stairway, statue]))

        self.assertFalse(
            self.game._player_has_active_building(self.p1, 'Temple'))
Exemple #10
0
    def test_add_to_empty_building(self):
        """ Add a valid material to a building with no materials.
        """
        atrium = cm.get_card('Atrium')
        foundry = cm.get_card('Foundry')
        self.p1.stockpile.set_content([atrium])
        self.p1.buildings = [Building(foundry, 'Brick')]

        a = message.GameAction(message.ARCHITECT, foundry, atrium, None)
        self.game.handle(a)

        self.assertNotIn('Atrium', self.p1.stockpile)

        self.assertEqual(
            self.p1.buildings[0].materials,
            Building(foundry, 'Brick', materials=[atrium]).materials)
        self.assertEqual(self.p1.buildings[0],
                         Building(foundry, 'Brick', materials=[atrium]))

        self.assertFalse(
            self.game._player_has_active_building(self.p1, 'Foundry'))
Exemple #11
0
    def test_start_two_buildings(self):
        """Start two buildings.
        """
        tower, bridge = cm.get_cards(['Tower', 'Bridge'])
        self.p1.hand.set_content([tower, bridge])

        a = message.GameAction(message.ARCHITECT, tower, None, 'Concrete')
        self.game.handle(a)

        self.assertEqual(self.p1.buildings[0], Building(tower, 'Concrete'))
        self.assertEqual(self.game.expected_action, message.ARCHITECT)

        a = message.GameAction(message.ARCHITECT, bridge, None, 'Concrete')
        self.game.handle(a)

        self.assertEqual(self.p1.buildings[1], Building(bridge, 'Concrete'))

        self.assertEqual(len(self.p1.hand), 0)
        self.assertNotIn('Concrete', self.game.in_town_sites)

        self.assertEqual(self.game.active_player, self.p2)
Exemple #12
0
    def test_think_past_higher_hand_limit(self):
        d = self.deck

        self.p1.hand.set_content([
            d.road, d.road, d.road, d.road, d.road, d.road, d.wall, d.wall,
            d.wall
        ])

        self.p1.buildings.append(Building(d.temple, 'Marble', complete=True))

        a = message.GameAction(message.THINKERTYPE, False)
        self.game.handle(a)

        self.assertEqual(len(self.p1.hand), 10)
Exemple #13
0
    def test_add_two_materials(self):
        """ Add materials with subsequent architect actions.
        """
        wall, storeroom = cm.get_cards(['Wall', 'Storeroom'])
        tower = cm.get_card('Tower')
        self.p1.stockpile.set_content([wall, storeroom])
        self.p1.buildings = [Building(tower, 'Concrete')]

        a = message.GameAction(message.ARCHITECT, tower, wall, None)
        self.game.handle(a)

        self.assertEqual(self.p1.buildings[0],
                         Building(tower, 'Concrete', materials=[wall]))

        a = message.GameAction(message.ARCHITECT, tower, storeroom, None)
        self.game.handle(a)

        self.assertEqual(
            self.p1.buildings[0],
            Building(tower,
                     'Concrete',
                     materials=[wall, storeroom],
                     complete=True))
Exemple #14
0
    def test_start_in_town(self):
        """ Start an in-town building.
        """
        latrine = cm.get_card('Latrine')
        self.p1.hand.set_content([latrine])

        a = message.GameAction(message.CRAFTSMAN, latrine, None, 'Rubble')
        self.game.handle(a)

        self.assertNotIn(latrine, self.p1.hand)

        self.assertEqual(self.p1.buildings[0], Building(latrine, 'Rubble'))

        self.assertFalse(
            self.game._player_has_active_building(self.p1, 'Latrine'))
Exemple #15
0
    def test_complete_building(self):
        """ Complete a building.
        """
        statue, temple, fountain, stairway = cm.get_cards(
            ['Statue', 'Temple', 'Fountain', 'Stairway'])
        self.p1.stockpile.set_content([statue])
        self.p1.buildings = [
            Building(temple, 'Marble', materials=[fountain, stairway])
        ]

        a = message.GameAction(message.ARCHITECT, temple, statue, None)
        self.game.handle(a)

        self.assertNotIn(statue, self.p1.stockpile)
        self.assertIn('Marble', self.p1.influence)
        self.assertTrue(
            self.game._player_has_active_building(self.p1, 'Temple'))

        self.assertEqual(
            self.p1.buildings[0],
            Building(temple,
                     'Marble',
                     materials=[fountain, stairway, statue],
                     complete=True))
Exemple #16
0
    def test_petition_with_circus_and_three_cards(self):
        """Tests petition with 3 orders cards despiting having a Circus.
        """
        circus, dock = cm.get_cards(['Circus', 'Dock'])
        self.p1.buildings = [
            Building(circus, 'Wood', materials=[dock], complete=True)
        ]

        cards = cm.get_cards(['Road'] * 3)
        self.p1.hand.set_content(cards)

        a = message.GameAction(message.LEADROLE, 'Craftsman', 1, *cards)
        self.game.handle(a)

        self.assertEqual(self.game.role_led, 'Craftsman')
        self.assertEqual(self.p1.n_camp_actions, 1)
        self.assertTrue(self.p1.camp.contains(cards))
        self.assertNotIn('Road', self.p1.hand)
        self.assertEqual(self.game.expected_action, message.FOLLOWROLE)
Exemple #17
0
    def test_start_out_of_town(self):
        """ Start a building out of town.
        """
        bridge = cm.get_card('Bridge')
        self.p1.hand.set_content([bridge])

        # Empty the in-town sites
        self.game.in_town_sites = ['Rubble']

        self.game.oot_allowed = True

        a = message.GameAction(message.ARCHITECT, bridge, None, 'Concrete')
        self.game.handle(a)

        self.assertEqual(self.p1.buildings[0], Building(bridge, 'Concrete'))
        self.assertEqual(3, self.game.out_of_town_sites.count('Concrete'))

        self.assertNotIn(bridge, self.p1.hand)
        self.assertEqual(self.game.expected_action, message.ARCHITECT)
        self.assertEqual(self.game.active_player, self.p2)
Exemple #18
0
    def test_legionary_hits_all_with_bridge(self):
        d = self.deck
        self.p1.buildings.append(Building(d.bridge, 'Concrete', complete=True))

        a = message.GameAction(message.LEGIONARY, d.dock0, d.road0)
        self.game.handle(a)

        a = message.GameAction(message.TAKEPOOLCARDS)
        self.game.handle(a)

        self.assertEqual(self.game.expected_action, message.GIVECARDS)
        self.assertEqual(self.game.active_player, self.game.players[1])

        a = message.GameAction(message.GIVECARDS, d.road1, d.dock1, d.insula1)
        self.game.handle(a)

        self.assertEqual(self.game.expected_action, message.GIVECARDS)
        self.assertEqual(self.game.active_player, self.game.players[2])

        a = message.GameAction(message.GIVECARDS, d.road2, d.dock2, d.insula2)
        self.game.handle(a)

        self.assertEqual(self.game.expected_action, message.GIVECARDS)
        self.assertEqual(self.game.active_player, self.game.players[3])

        a = message.GameAction(message.GIVECARDS, d.road3, d.dock3, d.insula3)
        self.game.handle(a)

        self.assertEqual(self.game.expected_action, message.GIVECARDS)
        self.assertEqual(self.game.active_player, self.game.players[4])

        a = message.GameAction(message.GIVECARDS, d.road4, d.dock4, d.insula4)
        self.game.handle(a)

        self.assertEqual(self.game.expected_action, message.THINKERORLEAD)
        self.assertEqual(self.game.active_player, self.game.players[1])
Exemple #19
0
def n_player_lead(n,
                  role,
                  clientele=[],
                  buildings=[],
                  deck=None,
                  follow=False):
    """N player game, advanced to the point where
    p1 has led the specified role with a Jack and p2 through p<n> think.

    Use follow=True to have the other players follow the action.

    Optionally allowed to specify clients and buildings for each player. The
    clientele argument is an iterable of iterables, where the primary index is
    the players in order 1, 2, 3... and each element is a list of clients that player
    should have. Likewise with the buildings argument. The buildings should be
    just the name of the foundations and will be completed without any material
    cards. For example:

        # Leg. and arch. client for p1, craftsman for p2.
        clientele = (['Bath', 'Storeroom'], ['Dock'])
        
        # Complete Fountain for p2.
        buildings = ([], ['Fountain'])

        game = n_player_lead(2, 'Craftsman', clientele, buildings)

    Adding clientele must be done before resolving the lead role action so they
    are counted. Adding buildings usually can be done in the individual test
    cases if they add static effects (eg. Archway), but the Fountain or Circus
    Maximus need to be done before the lead role action. This is also more
    convenient if you just want a static building ability active.

    Optionally takes a TestDeck object so the foundations can be taken from
    the deck. The building names can also use the TestDeck format, eg.
    "shrine2" to get a specific card as the foundation.
    """
    #print clientele, buildings, role
    g = simple_n_player(n)
    p1 = g.players[0]
    others = g.players[1:]

    if deck is None:
        d = TestDeck()
    else:
        d = deck

    for p, p_clientele, p_buildings in \
            izip_longest(g.players, clientele, buildings, fillvalue=[]):

        p.clientele.set_content(
            [getattr(d, c.replace(' ', '')) for c in p_clientele])

        for b in p_buildings:
            foundation = getattr(d, b)
            b = Building(foundation, foundation.material, [], None, True)
            p.buildings.append(b)

    # Indicate that p1 will lead
    a = message.GameAction(message.THINKERORLEAD, False)
    g.handle(a)

    p1.hand.set_content([d.jack0])

    a = message.GameAction(message.LEADROLE, role, 1, d.jack0)
    g.handle(a)

    # other players think for a Jack
    for i, p in enumerate(others):
        if follow:
            jack = getattr(d, 'jack' + str(i + 1))
            p.hand.set_content([jack])
            a = message.GameAction(message.FOLLOWROLE, 1, jack)
            g.handle(a)

        else:
            a = message.GameAction(message.FOLLOWROLE, 0)
            g.handle(a)
            a = message.GameAction(message.THINKERTYPE, True)
            g.handle(a)

    return g