Esempio n. 1
0
File: basic.py Progetto: roblacy/pit
    def get_action(self, cycle):
        """Returns action for this cycle

        1. randomly do nothing just to mix it up
        2. update internal game state
        3. if winning hand, ring the bell
        4. try to respond to an open offer
        5. make a new offer
        """
        if random.randrange(0,5) == 4:
            return None

        self.cycle = cycle
        self.offers = self._active_offers(self.offers)
        self._group_cards()

        if util.is_winning_hand(self.hand):
            return gameengine.BellRing(self)

        random.shuffle(self.offers)
        for offer in self.offers:
            cards = self._get_response(offer)
            if cards:
                self.offers.remove(offer)
                return gameengine.Response(offer, self, cards)

        return self._make_offer()
Esempio n. 2
0
File: basic.py Progetto: roblacy/pit
    def get_action(self, cycle):
        """Returns action for this cycle

        1. randomly do nothing just to mix it up
        2. update internal game state
        3. if winning hand, ring the bell
        4. try to respond to an open offer
        5. make a new offer
        """
        if random.randrange(0, 5) == 4:
            return None

        self.cycle = cycle
        self.offers = self._active_offers(self.offers)
        self._group_cards()

        if util.is_winning_hand(self.hand):
            return gameengine.BellRing(self)

        random.shuffle(self.offers)
        for offer in self.offers:
            cards = self._get_response(offer)
            if cards:
                self.offers.remove(offer)
                return gameengine.Response(offer, self, cards)

        return self._make_offer()
Esempio n. 3
0
    def ring_bell(self, bell_ring):
        """Ring the closing bell"""
        for player in self.players:
            player.closing_bell(bell_ring.player)

        if util.is_winning_hand(self.player_info[bell_ring.player]['cards']):
            self.in_play = False
            for player in self.players:
                player.closing_bell_confirmed(bell_ring.player)
Esempio n. 4
0
File: basic.py Progetto: roblacy/pit
 def make_plays(self):
     """Main game play method makes & responds to offers, etc.
     """
     if not self.already_rang and util.is_winning_hand(self.cards):
         self.notify(gameengine.Message.RING_BELL)
         self.already_rang = True
         return
     self.clear_outgoing_offers()
     self.check_offers()
     self.make_offers()
Esempio n. 5
0
File: basic.py Progetto: roblacy/pit
 def make_plays(self):
     """Main game play method makes & responds to offers, etc.
     """
     if not self.already_rang and util.is_winning_hand(self.cards):
         self.notify(gameengine.Message.RING_BELL)
         self.already_rang = True
         return
     self.clear_outgoing_offers()
     self.check_offers()
     self.make_offers()
Esempio n. 6
0
 def test_extra_bull_wild_extra(self):
     """The bull can act as a wild card in an extra-card hand"""
     cards = ['a'] * (config.COMMODITIES_PER_HAND - 1)
     cards.extend([config.BULL, 'b'])
     self.assertTrue(util.is_winning_hand(cards))
Esempio n. 7
0
 def test_extra_bull_wild(self):
     """The bull can act as a wild card"""
     cards = ['a'] * (config.COMMODITIES_PER_HAND - 1)
     cards.append(config.BULL)
     self.assertTrue(util.is_winning_hand(cards))
Esempio n. 8
0
 def process_bell_ring(self, message):
     """Broadcasts when a player rings the bell, checks if round over.
     """
     data = self.player_data[message.uid]
     if util.is_winning_hand(data['cards']):
         self.round_winner = message.uid
Esempio n. 9
0
 def test_extra_bear_not_ok(self):
     """Winning hand with one extra card not winning if card is the bear"""
     cards = ['a'] * config.COMMODITIES_PER_HAND
     cards.append(config.BEAR)
     self.assertFalse(util.is_winning_hand(cards))
Esempio n. 10
0
 def test_mixed_hand(self):
     """A hand of mixed commodities is not a winning hand"""
     cards = ['a'] * (config.COMMODITIES_PER_HAND - 3)
     cards.extend(['b', 'b', 'c'])
     self.assertFalse(util.is_winning_hand(cards))
Esempio n. 11
0
 def test_mixed_hand(self):
     """A hand of mixed commodities is not a winning hand"""
     cards = ['a'] * (config.COMMODITIES_PER_HAND - 3)
     cards.extend(['b', 'b', 'c'])
     self.assertFalse(util.is_winning_hand(cards))
Esempio n. 12
0
 def test_simple_winning_hand(self):
     """A hand of all one commodity is a winning hand"""
     cards = ['a'] * config.COMMODITIES_PER_HAND
     self.assertTrue(util.is_winning_hand(cards))
Esempio n. 13
0
 def test_extra_bull_wild_extra_bear(self):
     """The bear again blocks this from being a winning hand"""
     cards = ['a'] * (config.COMMODITIES_PER_HAND - 1)
     cards.extend([config.BULL, config.BEAR])
     self.assertFalse(util.is_winning_hand(cards))
Esempio n. 14
0
 def test_extra_bull_wild_extra(self):
     """The bull can act as a wild card in an extra-card hand"""
     cards = ['a'] * (config.COMMODITIES_PER_HAND - 1)
     cards.extend([config.BULL, 'b'])
     self.assertTrue(util.is_winning_hand(cards))
Esempio n. 15
0
 def test_extra_bull_wild_extra_bear(self):
     """The bear again blocks this from being a winning hand"""
     cards = ['a'] * (config.COMMODITIES_PER_HAND - 1)
     cards.extend([config.BULL, config.BEAR])
     self.assertFalse(util.is_winning_hand(cards))
Esempio n. 16
0
 def test_simple_winning_hand(self):
     """A hand of all one commodity is a winning hand"""
     cards = ['a'] * config.COMMODITIES_PER_HAND
     self.assertTrue(util.is_winning_hand(cards))
Esempio n. 17
0
 def test_extra_card_ok(self):
     """A winning hand with one extra card is still a winning hand"""
     cards = ['a'] * config.COMMODITIES_PER_HAND
     cards.append('b')
     self.assertTrue(util.is_winning_hand(cards))
Esempio n. 18
0
 def test_extra_card_ok(self):
     """A winning hand with one extra card is still a winning hand"""
     cards = ['a'] * config.COMMODITIES_PER_HAND
     cards.append('b')
     self.assertTrue(util.is_winning_hand(cards))
Esempio n. 19
0
 def test_extra_bear_not_ok(self):
     """Winning hand with one extra card not winning if card is the bear"""
     cards = ['a'] * config.COMMODITIES_PER_HAND
     cards.append(config.BEAR)
     self.assertFalse(util.is_winning_hand(cards))
Esempio n. 20
0
 def process_bell_ring(self, message):
     """Broadcasts when a player rings the bell, checks if round over.
     """
     data = self.player_data[message.uid]
     if util.is_winning_hand(data['cards']):
         self.round_winner = message.uid
Esempio n. 21
0
 def test_extra_bull_wild(self):
     """The bull can act as a wild card"""
     cards = ['a'] * (config.COMMODITIES_PER_HAND - 1)
     cards.append(config.BULL)
     self.assertTrue(util.is_winning_hand(cards))