def run(self, tries): """Calculates the win % for each preflop hand, returns the mapping""" cards = c.full_deck() self.wins = {} self.tries = tries for count, two_cards in enumerate(itertools.combinations(cards, 2)): t1 = time.clock() hand = c.Hand(two_cards[0], two_cards[1]) hand_string = hand.simple() if self.wins.get(hand_string) is not None: print "Skipping {}. Already computed its simple representation ({})" \ .format(hand, hand_string) continue simulator = HandSimulator(hand) percent_pots_won = simulator.simulate(tries) self.wins[hand_string] = percent_pots_won print ' {hand} ({s}) won {percent}% in {tries} tries in {t} seconds' \ .format(hand=hand, s=hand_string, tries=tries, percent=percent_pots_won, t=(time.clock() - t1)) # 52 choose 2 == 1326 # We go through everything even though we only calculate 169 hands percent_done = MathUtils.percentage(count, 1326) print ' Finished hand {c} ({p:.2f}%)' \ .format(c=count, p=percent_done) print '-' * 10
def run(self, tries): """Calculates the win % for each preflop hand, returns the mapping""" cards = c.full_deck() self.wins = {} self.tries = tries count = 0 for two_cards in itertools.combinations(cards, 2): t1 = time.clock() hand = c.Hand(two_cards[0], two_cards[1]) simulator = HandSimulator(hand) percent_pots_won = simulator.simulate(tries) self.wins[repr(hand)] = percent_pots_won print ' {hand} won {percent}% in {tries} tries in {t} seconds' \ .format(hand=hand, tries=tries, percent=percent_pots_won, t=(time.clock() - t1)) count += 1 # 52 choose 2 == 1326 percent_done = MathUtils.percentage(count, 1326) print ' Finished hand {c} ({p}%)' \ .format(c=count, p=round(percent_done)) print '-'*10
def test_all_cards_aig(self): """For every card, verify that we can go to/from the aig string""" deck = cards.full_deck() b = CardBuilder() for card in deck: card_string = card.aigames_str() self.assertEqual(card, b.from_2char(card_string))
def run(self, tries): """Calculates the win % for each preflop hand, returns the mapping""" cards = c.full_deck() self.wins = {} self.tries = tries for count, two_cards in enumerate(itertools.combinations(cards, 2)): t1 = time.clock() hand = c.Hand(two_cards[0], two_cards[1]) hand_string = hand.simple() if self.wins.get(hand_string) is not None: print "Skipping {}. Already computed its simple representation ({})" \ .format(hand, hand_string) continue simulator = HandSimulator(hand) percent_pots_won = simulator.simulate(tries) self.wins[hand_string] = percent_pots_won print ' {hand} ({s}) won {percent}% in {tries} tries in {t} seconds' \ .format(hand=hand, s=hand_string, tries=tries, percent=percent_pots_won, t=(time.clock() - t1)) # 52 choose 2 == 1326 # We go through everything even though we only calculate 169 hands percent_done = MathUtils.percentage(count, 1326) print ' Finished hand {c} ({p:.2f}%)' \ .format(c=count, p=percent_done) print '-'*10
def test_eq(self): """Tests the card equals function, and that we can make a full deck""" made_cards = [] for i in range(0, 4): suit = i for j in range(2, 15): card1 = Card(j, suit) card2 = Card(j, suit) made_cards.append(card1) self.assertTrue(card1.is_pair(card2)) self.assertTrue(card1.is_suited(card2)) self.assertEqual(card1, card2) self.assertEqual(len(made_cards), 52) self.assertEqual(made_cards, list(cards.full_deck()))
def deal_hands(self, players): """Deals out hands for players. Returns a map of bots to hands""" hand_size = self.parent.hand_size() hands = {} full_deck = cards.full_deck() hand_cards = random.sample(full_deck, hand_size * len(players)) self.deck = [c for c in full_deck if c not in hand_cards] for bot in players: hand = [] for _ in range(0, hand_size): hand.append(hand_cards.pop()) hands[bot] = hand return hands
def deal_hands(self, num_bots): """Deals out hands for players. Returns the list of hands""" hand_size = self.parent.hand_size() hands = [] full_deck = cards.full_deck() hand_cards = random.sample(full_deck, hand_size * num_bots) self.deck = [c for c in full_deck if not c in hand_cards] for i in range(0, num_bots): hand = [] for j in range(0, hand_size): hand.append(hand_cards.pop()) hands.append(hand) return hands