Esempio n. 1
0
    def send_response(self, response):
        """Issue a response to player who made initial offer.

        The initial player immediately accepts or rejects the response, so by
        the end of this method the response is either rejected or the trade is
        confirmed.

        The response will be also rejected under any of these conditions:
        - same player made both offer and response
        - offer no longer present in game state list of offers
        - player making response no longer has these cards

        This also grabs the response's cards & removes them from the response.
        They are saved so they can be used if the trade ends up executing.
        """
        response.cycle = self.cycle
        response_cards = response.cards
        response.cards = None

        if (response.offer in self.offers and
                response.player != response.offer.player and
                util.has_cards(response_cards, self.player_info[response.player]['cards'], [])):
            confirm_cards = response.offer.player.response_made(response)
            if (confirm_cards and
                  util.has_cards(confirm_cards, self.player_info[response.offer.player]['cards'], [])):
                self.confirm(response, response_cards, confirm_cards)
                return
        # player rejected response or offer was already removed
        response.player.response_rejected(response)
        self.delay_player(response.player, RESPONSE_DURATION)
Esempio n. 2
0
    def process_binding_offer(self, message):
        """Processes a binding offer, locks up cards until traded or withdrawn.

        If rebroadcasting the offer, the specific cards will be removed.
        """
        # only take action if the player has the cards in this offer
        data = self.player_data[message.uid]
        if util.has_cards(message.cards, data['cards'], data['binding_offers']):
            match = self.get_matching_offer(message)
            if match:
                self.execute_trade(message, match)
            else:
                data['binding_offers'].append(message)
                # make a copy of the offer without the specific cards
                binding_offer = copy.copy(message)
                binding_offer.count = len(binding_offer.cards)
                binding_offer.cards = None
                self.broadcast(binding_offer, exclude=[message.uid])
Esempio n. 3
0
    def process_binding_offer(self, message):
        """Processes a binding offer, locks up cards until traded or withdrawn.

        If rebroadcasting the offer, the specific cards will be removed.
        """
        # only take action if the player has the cards in this offer
        data = self.player_data[message.uid]
        if util.has_cards(message.cards, data['cards'],
                          data['binding_offers']):
            match = self.get_matching_offer(message)
            if match:
                self.execute_trade(message, match)
            else:
                data['binding_offers'].append(message)
                # make a copy of the offer without the specific cards
                binding_offer = copy.copy(message)
                binding_offer.count = len(binding_offer.cards)
                binding_offer.cards = None
                self.broadcast(binding_offer, exclude=[message.uid])
Esempio n. 4
0
 def test_cards_not_found(self):
     """has_cards returns False when cards are not in cards at all
     """
     self.assertFalse(
         util.has_cards(['e', 'e', 'e'], self.cards, self.locked_groups))
Esempio n. 5
0
 def test_cards_locked(self):
     """has_cards returns False when cards are locked
     """
     self.assertFalse(
         util.has_cards(['b', 'b'], self.cards, self.locked_groups))
Esempio n. 6
0
 def test_cards_available_none_locked(self):
     """has_cards returns True when cards are available with no locked groups
     """
     self.assertTrue(util.has_cards(['c', 'c'], self.cards, []))
Esempio n. 7
0
 def test_cards_available(self):
     """has_cards returns True when cards are available
     """
     self.assertTrue(
         util.has_cards(['c', 'c'], self.cards, self.locked_groups))
Esempio n. 8
0
 def test_cards_not_found(self):
     """has_cards returns False when cards are not in cards at all
     """
     self.assertFalse(util.has_cards(['e', 'e', 'e'], self.cards, self.locked_groups))
Esempio n. 9
0
 def test_cards_locked(self):
     """has_cards returns False when cards are locked
     """
     self.assertFalse(util.has_cards(['b', 'b'], self.cards, self.locked_groups))
Esempio n. 10
0
 def test_cards_available_none_locked(self):
     """has_cards returns True when cards are available with no locked groups
     """
     self.assertTrue(util.has_cards(['c', 'c'], self.cards, []))
Esempio n. 11
0
 def test_cards_available(self):
     """has_cards returns True when cards are available
     """
     self.assertTrue(util.has_cards(['c', 'c'], self.cards, self.locked_groups))