コード例 #1
0
ファイル: joker.py プロジェクト: lunatunez/pycards
def pick_joker(cards):
    """ Picks the best card for the joker to represent for a group of cards.  """
    # If the Joker is in the pile of cards, remove it for analysis.
    if card.JOKER1 in cards:
        cards.remove(card.JOKER1)
    if card.JOKER2 in cards:
        cards.remove(card.JOKER2)

    if len(cards) > 4:
        raise ValueError('Hand is too large to analyze for joker. Must be 1-4 without joker.')

    d = deck.Deck()
    d.unhide()
    bestvalue = 0
    bestcard = None

    for c in d.cards:
        testhand = cards[:]
        testhand.append(c)
        test_val = evaluator.get_value(testhand)

        if test_val > bestvalue:
            bestvalue = test_val
            bestcard = c
    return bestcard
コード例 #2
0
ファイル: test_tools.py プロジェクト: lunatunez/pycards
 def test_gettype_royalflush_returnsROYALFLUSH(self):
     h = tools.make('royalflush')
     h = tools.make('royalflush')
     val = ev.get_value(h)
     expected = 'ROYAL FLUSH'
     result = ev.get_type(val)
     self.assertEqual(expected, result)
コード例 #3
0
ファイル: test_evaluator.py プロジェクト: lunatunez/pycards
 def test_findbesthand_straight_returnsSTRAIGHT(self):
     cards = tools.convert_to_cards(['Ac', 'As', '2c', '3s', '4h', '5s', '5h'])
     besthand = evaluator.find_best_hand(cards)
     val = evaluator.get_value(besthand)
     expected = 'STRAIGHT'
     result = evaluator.get_type(val)
     self.assertEqual(expected, result)
コード例 #4
0
ファイル: test_evaluator.py プロジェクト: lunatunez/pycards
 def test_findbesthand_flush_returnsFLUSH(self):
     cards = tools.convert_to_cards(['8s', '9s', 'Tc', 'Js', 'Qs', 'Ks', 'Ac'])
     besthand = evaluator.find_best_hand(cards)
     val = evaluator.get_value(besthand)
     expected = 'FLUSH'
     result = evaluator.get_type(val)
     self.assertEqual(expected, result)
コード例 #5
0
ファイル: test_evaluator.py プロジェクト: lunatunez/pycards
 def test_findbesthand_quads_returnsQUADS(self):
     cards = tools.convert_to_cards(['Kc', 'Kd', 'Ks', 'Ac', 'Kd', 'Ah', 'As'])
     besthand = evaluator.find_best_hand(cards)
     val = evaluator.get_value(besthand)
     expected = 'QUADS'
     result = evaluator.get_type(val)
     self.assertEqual(expected, result)
コード例 #6
0
ファイル: test_evaluator.py プロジェクト: lunatunez/pycards
 def test_findbesthand_straightflush_returnsSTRAIGHTFLUSH(self):
     cards = tools.convert_to_cards(['4s', '5s', '6s', '7s', '8s', 'Ks', 'As'])
     besthand = evaluator.find_best_hand(cards)
     val = evaluator.get_value(besthand)
     expected = 'STRAIGHT FLUSH'
     result = evaluator.get_type(val)
     self.assertEqual(expected, result)
コード例 #7
0
ファイル: test_evaluator.py プロジェクト: lunatunez/pycards
 def test_findbesthand_fullhouse_returnsFULLHOUSE(self):
     cards = tools.convert_to_cards(['7c', '7s', 'Ks', 'Kc', 'Ah', 'Ac', 'As'])
     besthand = evaluator.find_best_hand(cards)
     val = evaluator.get_value(besthand)
     expected = 'FULL HOUSE'
     result = evaluator.get_type(val)
     self.assertEqual(expected, result)
コード例 #8
0
ファイル: test_evaluator.py プロジェクト: lunatunez/pycards
 def test_findbesthand_pair_returnsPAIR(self):
     cards = tools.convert_to_cards(['2c', '3c', '5s', '7s', 'Kc', 'Ac', 'As'])
     besthand = evaluator.find_best_hand(cards)
     val = evaluator.get_value(besthand)
     expected = 'PAIR'
     result = evaluator.get_type(val)
     self.assertEqual(expected, result)
コード例 #9
0
ファイル: test_pots.py プロジェクト: lunatunez/pycards
    def test_besthandval_6players_straight(self):
        # Note hand values reversed so that 0 has the lowest hand, 1 has better,  etc.
        self.setup_allins(6)
        tools.deal_ranked_hands(self.t, _rev=True)
        players = self.t.get_players(hascards=True)

        expected = evaluator.get_value(tools.make('straight_high'))
        result = pots.best_hand_val(players)
        self.assertEqual(expected, result)
コード例 #10
0
ファイル: poker.py プロジェクト: lunatunez/pycards
    def highhand(self):
        """ Finds which player has the highest showing hand and return their seat
            index.  For stud games, after the first street, the high hand on
            board initiates the action (a tie is broken by position, with the
            player who received cards first acting first).
        """
        _logger.debug('Determining which player has the highest exposed hand.')
        seat, highvalue = None, 0
        ties = []

        for s in self.table.get_players(hascards=True):
            h = s.hand.get_upcards()
            value = evaluator.get_value(h)

            if value > highvalue:
                highvalue, seat = value, s
                ties = [seat]  # Reset any lower ties.
                _logger.debug('Current high hand value: {}.'.format(highvalue))
                _logger.debug('Seat with current highest hand: {}.'.format(seat.NUM))
            elif value == highvalue:
                _logger.debug('Seat {} tied for current high value.'.format(s.NUM))
                ties.append(s)

                # Is this needed?
                if seat not in ties:
                    ties.append(seat)

        # Return the seat index of the first-to-act.
        if len(ties) > 1:
            _logger.debug('There was a tie for high hand, breaking tie with seat position')
            s = None
            # Process ties, get the player who was dealt first.
            for s in self.table.get_players(hascards=True):
                if s in ties:
                    _logger.debug('Seat {} was dealt first, returning its index.'.format(s.NUM))
                    return s.NUM
        else:
            _logger.debug('Seat {} has high hand, returning its index.'.format(s.NUM))
            return seat.NUM
コード例 #11
0
ファイル: test_tools.py プロジェクト: lunatunez/pycards
 def test_get_description_royalflush_returnsAHigh(self):
     h = tools.make('royalflush')
     val = ev.get_value(h)
     expected = 'A High'
     result = ev.get_description(val, h)
     self.assertEqual(expected, result)
コード例 #12
0
ファイル: test_tools.py プロジェクト: lunatunez/pycards
 def test_getvalue_royalflush_returns100000000000(self):
     #  h = royalflush()
     h = tools.make('royalflush')
     expected = 100000000000
     result = ev.get_value(h)
     self.assertEqual(expected, result)
コード例 #13
0
ファイル: test_tools.py プロジェクト: lunatunez/pycards
 def test_gettype_tripslow_returnsTRIPS(self):
     h = tools.make('trips_low')
     val = ev.get_value(h)
     expected = 'TRIPS'
     result = ev.get_type(val)
     self.assertEqual(expected, result)
コード例 #14
0
ファイル: test_tools.py プロジェクト: lunatunez/pycards
 def test_getvalue_wheeldraw_returns1413040302(self):
     h = tools.make('wheeldraw')
     expected = 1413040302
     result = ev.get_value(h)
     self.assertEqual(expected, result)
コード例 #15
0
ファイル: test_tools.py プロジェクト: lunatunez/pycards
 def test_gettype_wheeldraw_returnsHIGHCARD(self):
     h = tools.make('wheeldraw')
     val = ev.get_value(h)
     expected = 'HIGH CARD'
     result = ev.get_type(val)
     self.assertEqual(expected, result)
コード例 #16
0
ファイル: test_tools.py プロジェクト: lunatunez/pycards
 def test_get_description_straightflushhigh_returnKHigh(self):
     h = tools.make('straightflush_high')
     val = ev.get_value(h)
     expected = 'K High'
     result = ev.get_description(val, h)
     self.assertEqual(expected, result)
コード例 #17
0
ファイル: test_tools.py プロジェクト: lunatunez/pycards
 def test_getvalue_twopairlow_returns30302040000(self):
     h = tools.make('twopair_low')
     expected = 30302040000
     result = ev.get_value(h)
     self.assertEqual(expected, result)
コード例 #18
0
ファイル: test_tools.py プロジェクト: lunatunez/pycards
 def test_getvalue_flushdraw_returns1009070302(self):
     h = tools.make('flushdrawB')
     expected = 1009070302
     result = ev.get_value(h)
     self.assertEqual(expected, result)
コード例 #19
0
ファイル: test_tools.py プロジェクト: lunatunez/pycards
 def test_getvalue_OESD_returns1110090802(self):
     h = tools.make('OESD')
     expected = 1110090802
     result = ev.get_value(h)
     self.assertEqual(expected, result)
コード例 #20
0
ファイル: test_tools.py プロジェクト: lunatunez/pycards
 def test_getvalue_twopairhigh_returns31413120000(self):
     h = tools.make('twopair_high')
     expected = 31413120000
     result = ev.get_value(h)
     self.assertEqual(expected, result)
コード例 #21
0
ファイル: test_tools.py プロジェクト: lunatunez/pycards
 def test_get_description_pairlow_returns2s(self):
     h = tools.make('pair_low')
     val = ev.get_value(h)
     expected = '2\'s'
     result = ev.get_description(val, h)
     self.assertEqual(expected, result)
コード例 #22
0
ファイル: test_tools.py プロジェクト: lunatunez/pycards
 def test_getvalue_pairlow_returns20205040300(self):
     h = tools.make('pair_low')
     expected = 20205040300
     result = ev.get_value(h)
     self.assertEqual(expected, result)
コード例 #23
0
ファイル: test_tools.py プロジェクト: lunatunez/pycards
 def test_get_description_pairhigh_returnsAs(self):
     h = tools.make('pair_high')
     val = ev.get_value(h)
     expected = 'A\'s'
     result = ev.get_description(val, h)
     self.assertEqual(expected, result)
コード例 #24
0
ファイル: test_tools.py プロジェクト: lunatunez/pycards
 def test_getvalue_pairhigh_returns21413121100(self):
     h = tools.make('pair_high')
     expected = 21413121100
     result = ev.get_value(h)
     self.assertEqual(expected, result)
コード例 #25
0
ファイル: test_tools.py プロジェクト: lunatunez/pycards
 def test_getvalue_straightflushhigh_returns90900000000(self):
     h = tools.make('straightflush_high')
     expected = 91300000000
     result = ev.get_value(h)
     self.assertEqual(expected, result)
コード例 #26
0
ファイル: test_tools.py プロジェクト: lunatunez/pycards
 def test_gettype_OESD_returns(self):
     h = tools.make('OESD')
     val = ev.get_value(h)
     expected = 'HIGH CARD'
     result = ev.get_type(val)
     self.assertEqual(expected, result)
コード例 #27
0
ファイル: test_tools.py プロジェクト: lunatunez/pycards
 def test_gettype_straightflushhigh_returnsSTRAIGHTFLUSH(self):
     h = tools.make('straightflush_high')
     val = ev.get_value(h)
     expected = 'STRAIGHT FLUSH'
     result = ev.get_type(val)
     self.assertEqual(expected, result)
コード例 #28
0
ファイル: test_tools.py プロジェクト: lunatunez/pycards
 def test_getvalue_GSSD_returns1413111002(self):
     h = tools.make('GSSD')
     expected = 1413111002
     result = ev.get_value(h)
     self.assertEqual(expected, result)
コード例 #29
0
ファイル: test_tools.py プロジェクト: lunatunez/pycards
 def test_gettype_pairlow_returnsPAIR(self):
     h = tools.make('pair_low')
     val = ev.get_value(h)
     expected = 'PAIR'
     result = ev.get_type(val)
     self.assertEqual(expected, result)
コード例 #30
0
ファイル: test_tools.py プロジェクト: lunatunez/pycards
 def test_gettype_twopairhigh_returnsTWOPAIR(self):
     h = tools.make('twopair_high')
     val = ev.get_value(h)
     expected = 'TWO PAIR'
     result = ev.get_type(val)
     self.assertEqual(expected, result)