コード例 #1
0
def generate_holecard_ranking(nb_entry):
    nb_simulation = 1000
    deck = Deck()
    ranking = []
    for _ in range(nb_entry):
        deck.shuffle()
        hole = deck.draw_cards(2)
        win_rate = estimate_hole_card_win_rate(nb_simulation, 10, hole)
        ranking.append((win_rate, hole))
        deck.restore()
    return sorted(ranking)[::-1]
コード例 #2
0
ファイル: model.py プロジェクト: neo-godlike/pokerbot
    def __init__(self, num_players, num_rounds):
        self.round_count = 0
        self.community_from = 0
        self.cards = []
        for i in range(num_rounds):
            d = Deck()
            d.shuffle()
            cards = {'hole': [], 'community': d.draw_cards(5)}
            for j in range(num_players):
                cards['hole'].append(d.draw_cards(2))

            self.cards.append(cards)
コード例 #3
0
def subtask_hole_community_winrate(q, community_num, nb_sample):
    print "task started"
    nb_simulation = 1000
    deck = Deck()
    res = []
    for i in range(nb_sample):
        deck.shuffle()
        hole = deck.draw_cards(2)
        community = deck.draw_cards(community_num)
        win_rate = estimate_hole_card_win_rate(nb_simulation, 10, hole,
                                               community)
        res.append((win_rate, hole, community))
        deck.restore()
    q.put(res)
    print "task finished"
コード例 #4
0
ファイル: deck_test.py プロジェクト: neo-godlike/pokerbot
class DeckTest(BaseUnitTest):

  def setUp(self):
    self.deck = Deck()

  def test_draw_card(self):
    card = self.deck.draw_card()
    self.eq("SK", str(card))
    self.eq(51, self.deck.size())

  def test_draw_cards(self):
    cards = self.deck.draw_cards(3)
    self.eq("SJ", str(cards[2]))
    self.eq(49, self.deck.size())

  def test_restore(self):
    self.deck.draw_cards(5)
    self.deck.restore()
    self.eq(52, self.deck.size())

  def test_serialization(self):
    self.deck.draw_cards(5)
    self.deck.shuffle()
    serial = self.deck.serialize()
    restored = Deck.deserialize(serial)
    self.eq(self.deck.cheat, restored.cheat)
    self.eq(self.deck.deck, restored.deck)

  def test_cheat_draw(self):
    cards = [Card.from_id(cid) for cid in [12, 15, 17]]
    cheat = Deck(cheat=True, cheat_card_ids=[12, 15, 17])
    self.eq(cheat.draw_cards(3), cards)

  def test_cheat_restore(self):
    cards = [Card.from_id(cid) for cid in [12, 15, 17]]
    cheat = Deck(cheat=True, cheat_card_ids=[12, 15, 17])
    cheat.draw_cards(2)
    cheat.restore()
    self.eq(cheat.draw_cards(3), cards)

  def test_cheat_serialization(self):
    cards = [Card.from_id(cid) for cid in [12, 15, 17]]
    cheat = Deck(cheat=True, cheat_card_ids=[12, 15, 17])
    serial = cheat.serialize()
    restored = Deck.deserialize(serial)
    self.eq(cheat.deck, restored.deck)
    self.eq(cheat.cheat, restored.cheat)
    self.eq(cheat.cheat_card_ids, restored.cheat_card_ids)
コード例 #5
0
 def __setup_deck(self, used_cards):
   deck = Deck()
   deck = self.__extract_used_card(deck, used_cards)
   deck.shuffle()
   return deck
コード例 #6
0
def gen_card_set(community_num):
  deck = Deck()
  deck.shuffle()
  return deck.draw_cards(2), deck.draw_cards(5)[:community_num]