Hey all, so I wrote some simple python code to do this.
it's quick and dirty, takes about 1s to run 10,000 All-in heads up simulations and return the % that hand1 wins. This simple method misses draws but is still accurate enough for my applications.
If I (or anyone here) can speed this up substantially, in the future, maybe we will compute all of the hand v hand equities accurately and post here in a python friendly format.
All the public data I can find on the internet are about Heads up all v a random hand, whereas we're looking for all of the data hand v hand.
Code:
# Estimate Equities Headsup All in Texas Holdem
# Python3
import treys # https://github.com/ihendley/treys
from treys import Deck, Card, Evaluator
from random import shuffle
from multiprocessing import Pool # to speed up calculations
# Set some params for the equity calculation later
POOL_SIZE = 4
NUM_SIMULATIONS = 10000
# We need only one instance of the Evaluator
# use the Evaluator to check the winner once the board has been dealt
evaluator = Evaluator()
def _deal_random_board_evaluate(hands):
'''
Given two Texas Holdem Starting hands, run out one five card board and check the winner
:param hands: string like 'Ah2dKdKc'
:returns: True if player1_hand wins else False
'''
# instantiate a new deck and shuffle it
deck = Deck().GetFullDeck()
shuffle(deck)
# create the players' hands and pop them from the deck
# so that they do not conflict with the board
# eg assert len(deck) == 48
player1_hand= [deck.pop(deck.index(Card.new(hands[:2]))), deck.pop(deck.index(Card.new(hands[2:4])))]
player2_hand= [deck.pop(deck.index(Card.new(hands[4:6]))), deck.pop(deck.index(Card.new(hands[6:])))]
board = deck[:5]
# returns TRUE if player1_hand is the winning poker hand
# in treys, the lower the number the better the hand
return evaluator.evaluate(board, player1_hand) < evaluator.evaluate(board, player2_hand)
def estimate_equity(hands,num_simulations=NUM_SIMULATIONS, pool_size=POOL_SIZE):
''' Estimate the Heads up All in Equity of a given Texas Holdem Starting Hand against one other hand
:param hands: string of the two starting hands with no spaces, eg 'AhAdKcKd'
:param num_simulations: integer, the number of simulations to run, one simulation deals one 5 card board and checks the winner
:param pool_size: integer the number of processes to start via multiprocessing
:returns: float the equity estimate
'''
pool = Pool(pool_size)
results = pool.map(_deal_random_board_evaluate, [hands]*num_simulations)
return sum(results)/num_simulations
eg if you save the code in a file run_simulator.py
>> from run_simulator import estimate_equity
>> estimate_equity('AdAhKcKd')
>> # 0.8199
---- okay, there is something wrong with how I'm multithreading here.... will update with fix lol
Last edited by PajamaBottoms; 05-27-2019 at 06:55 PM.