def pokereval_results(num_cards=7, print_to_screen=False): pe = pokereval.PokerEval() to_str = lambda c: c.__str__() for i in xrange(number_of_runs): cards = random.sample(deck, num_cards) hand = cards[0:2] # hand = [Card(14,1), Card(14,2)] board = cards[2:num_cards] he_result = HandEvaluator.evaluate_hand(hand, board) pe_result = _pokereval_evaluate_hand_bm(hand, board, 1000) pe_win_pct = pe_result['eval'][0]['winhi'] / float( pe_result['info'][0]) pe_ev = pe_result['eval'][0]['ev']
def compute_equity(pockets, dead=[], board=[], iterations=None): """ Compute hands equity. """ pe = pokereval.PokerEval() players_ev = [0] * len(pockets) games = 0 pockets = [hands_from_range(p) for p in pockets] hands_variants = 1 for p in pockets: hands_variants *= len(p) for pck in itertools.product(*pockets): lpck = [] # F for x in pck: # I lpck += x # X lpck += filter (lambda c: c != '__', board) if len(lpck) != len(set(lpck)): # M continue # E if iterations: # FIXME iterations/hands_variants can't be less than 1 result = pe.poker_eval(game='holdem', pockets=list(pck), dead=dead, board=board, iterations=int(iterations/hands_variants)) else: result = pe.poker_eval(game='holdem', pockets=list(pck), dead=dead, board=board) for player, player_result in enumerate(result['eval']): players_ev[player] += player_result['ev'] * result['info'][0] games += result['info'][0] players_ev_sum = sum(players_ev) equity = [] for pe in players_ev: equity.append(100.0 * pe / players_ev_sum) print 'Games:', games return equity
import pokereval eval = pokereval.PokerEval() def load(): f = open('data/poker.txt', 'r') lines = f.readlines() f.close() del f return lines def getHands(line): line = line.split(' ') line = [t.strip() for t in line] return line[:5], line[5:] def convertHand(cards): return [eval.string2card(c) for c in cards] cnt = 0 lines = load() for line in lines: a, b = getHands(line) a = convertHand(a) b = convertHand(b) if eval.evaln(a) > eval.evaln(b): cnt += 1
board = '2d 2h 3c * *' pocket = ['Kh 9h * *', 'As * * *'] iterations = 1e7 n_jobs = 1 t0 = time.time() ev = rayeval.eval_mc('omaha', board, pocket, iterations, n_jobs) elapsed = time.time() - t0 print '[%s]' % 'omaha', pocket[:1], 'vs', pocket[ 1:], 'on board [%s]' % board, (': EV = %.4f%% (%.2gM iterations).' % (100. * ev[0], iterations / 1e6)) print 'Elapsed: %.2f seconds (%.2fM iterations / sec).\n' % ( elapsed, iterations / elapsed / 1e6) import pokereval t0 = time.time() board_pe = ['__' if b == '*' else b for b in board.split(' ')] pocket_pe = [['__' if c == '*' else c for c in p.split(' ')] for p in pocket] res = pokereval.PokerEval().poker_eval(game='omaha', board=board_pe, pockets=pocket_pe, iterations=int(iterations)) elapsed = time.time() - t0 print '[%s]' % 'pokereval', pocket[:1], 'vs', pocket[ 1:], 'on board [%s]' % board, ( ': EV = %.4f%% (%.2gM iterations).' % (res['eval'][0]['ev'] / 10., iterations / 1e6)) print 'Elapsed: %.2f seconds (%.2fM iterations / sec).' % ( elapsed, iterations / elapsed / 1e6)
equity_result = getEquityVsHand(hand1, [i, j], board) hand2_string = ''.join(pe.card2string([i, j])) result_list.append([hand2_string, equity_result]) return result_list run_min_raise_shove = 0 if run_min_raise_shove: S = 20 pe = pokereval.PokerEval() board = ['__', '__', '__', '__', '__'] preFlopEquity = EquityArray(board=pe.string2card(board)) point0 = DecesionPoint("SB", 0.5, 1.0) point1 = DecesionPoint("Leaf", 0.5, 1.0, preFlopEquity, parentAction="fold") point2 = DecesionPoint("BB", 2.0, 1.0, preFlopEquity, parentAction="bet") point3 = DecesionPoint("Leaf", 2.0, 1.0,
def __init__(self, invested_players, pots, board): self.players = invested_players self.pots = pots self.board = board self.pokereval = pokereval.PokerEval() self.rankings = {}