def test_empty_locked(self): """Available cards found when no cards locked """ self.locked_cards = [] self.expected.update({'b': 2, 'd': 1}) available = util.available_card_groups(self.cards, self.locked_cards) self.assertEqual(available, self.expected)
def make_offers(self): """Makes open offers. """ groups = util.available_card_groups(self.cards, self.locked_cards) for count in [4,3,2,1]: if count in groups.values(): self.notify(gameengine.Message.OFFER, count=count)
def make_offers(self): """Makes open offers. """ groups = util.available_card_groups(self.cards, self.locked_cards) for count in [4, 3, 2, 1]: if count in groups.values(): self.notify(gameengine.Message.OFFER, count=count)
def attempt_response(self, offer): """If cards are available, issues a binding offer to match the offer. """ # because I haven't syncronized access to self.cards and self.locked_cards # this will sometimes get a KeyError accessing data that has been deleted # by the other thread - ok to just ignore & move on try: groups = util.available_card_groups(self.cards, self.locked_cards) cards = self.get_match(groups, offer.count) except KeyError: return None if cards: self.notify(gameengine.Message.BINDING_OFFER, cards=cards, target_uid=offer.uid) self.locked_cards.extend(cards) self.outgoing_offers.append((time.time(), cards, offer.uid)) return True
def test_mixed_locked(self): """Available cards found when not locked in complete sets""" self.locked_cards.append('a') self.expected.update({'a': 2}) available = util.available_card_groups(self.cards, self.locked_cards) self.assertEqual(available, self.expected)
def test_available(self): """Available cards are found & counted correctly """ available = util.available_card_groups(self.cards, self.locked_cards) self.assertEqual(available, self.expected)