コード例 #1
0
ファイル: python_test.py プロジェクト: cpnei/HandEvaluator
def benchmark_hpoo():
    playerWins = Array[Double]([1.0]*9)
    opponentWins = Array[Double]([0.0]*9)
    Pocket = "ac as"
    repeat = 100
    
    Board = "4d 5d 6c 7s 8d"
    start_time = time.time()
    for i in range(repeat):
        Hand.HandPlayerOpponentOdds(Pocket, Board, playerWins, opponentWins)
    average = (time.time()-start_time)/float(repeat)
    print("average time (5+2 cards): ", average*1000, "ms")
    
    Board = "4d 5d 6c 7s"
    start_time = time.time()
    for i in range(repeat):
        Hand.HandPlayerOpponentOdds(Pocket, Board, playerWins, opponentWins)
    average = (time.time()-start_time)/float(repeat)
    print("average time (4+2 cards): ", average*1000, "ms")
    
    Board = "4d 5d 6c"
    start_time = time.time()
    for i in range(repeat):
        Hand.HandPlayerOpponentOdds(Pocket, Board, playerWins, opponentWins)
    average = (time.time()-start_time)/float(repeat)
    print("average time (3+2 cards): ", average*1000, "ms")
    
    repeat = 10000
    Board = ""
    start_time = time.time()
    for i in range(repeat):
        Hand.HandPlayerOpponentOdds(Pocket, Board, playerWins, opponentWins)
    average = (time.time()-start_time)/float(repeat)
    print("average time (0+2 cards): ", average*1000, "ms")
コード例 #2
0
def getRate(handPoker, boardPoker, numOpp):
    speed = 0.1
    win = Hand.WinOdds(handPoker, boardPoker, "", numOpp, speed)
    _, ppotv, npotv = Hand.HandPotential(handPoker, boardPoker, Double(0),
                                         Double(0), numOpp, speed)
    hs = Hand.HandStrength(handPoker, boardPoker, numOpp, speed)
    ehs = hs * (1 - npotv) + (1 - hs) * ppotv
    #logging.debug("win:{:.5f},ppotv:{:.5f},npotv:{:.5f},hs:{:.5f},ehs{:.5f}".format(win,ppotv,npotv,hs,ehs))
    return win, ppotv, npotv, hs, ehs
コード例 #3
0
ファイル: python_test.py プロジェクト: cpnei/HandEvaluator
def test_hpoo2():
    playerWins = Array[Double]([1.0]*9)
    opponentWins = Array[Double]([0.0]*9)
    Pocket = "kc ks"
    Board = "8h 6c 4h"

    print("===============================================================================")
    for Pocket in ["kc ks", "7h 9h"]:
        Hand.HandPlayerOpponentOdds(Pocket, Board, playerWins, opponentWins)
        print("Pocket:", Pocket)
        print("Board:", Board)
        #print(list(playerWins))
        print("playerWins:", sum(playerWins))
        print("High Card: %f%%"%      ( playerWins[int(Hand.HandTypes.HighCard)]*100.0))
        print("Pair: %f%%"%           ( playerWins[int(Hand.HandTypes.Pair)]*100.0))
        print("Two Pair: %f%%"%       ( playerWins[int(Hand.HandTypes.TwoPair)]*100.0))
        print("Three of Kind: %f%%"%  ( playerWins[int(Hand.HandTypes.Trips)]*100.0))
        print("Straight: %f%%"%       ( playerWins[int(Hand.HandTypes.Straight)]*100.0))
        print("Flush: %f%%"%          ( playerWins[int(Hand.HandTypes.Flush)]*100.0))
        print("Fullhouse: %f%%"%      ( playerWins[int(Hand.HandTypes.FullHouse)]*100.0))
        print("Four of a Kind: %f%%"% ( playerWins[int(Hand.HandTypes.FourOfAKind)]*100.0))
        print("Straight Flush: %f%%"% ( playerWins[int(Hand.HandTypes.StraightFlush)]*100.0))
        print("\n")
        #print(list(opponentWins))
        print("opponentWins:", sum(opponentWins))
        print("High Card: %f%%"%      ( opponentWins[int(Hand.HandTypes.HighCard)]*100.0))
        print("Pair: %f%%"%           ( opponentWins[int(Hand.HandTypes.Pair)]*100.0))
        print("Two Pair: %f%%"%       ( opponentWins[int(Hand.HandTypes.TwoPair)]*100.0))
        print("Three of Kind: %f%%"%  ( opponentWins[int(Hand.HandTypes.Trips)]*100.0))
        print("Straight: %f%%"%       ( opponentWins[int(Hand.HandTypes.Straight)]*100.0))
        print("Flush: %f%%"%          ( opponentWins[int(Hand.HandTypes.Flush)]*100.0))
        print("Fullhouse: %f%%"%      ( opponentWins[int(Hand.HandTypes.FullHouse)]*100.0))
        print("Four of a Kind: %f%%"% ( opponentWins[int(Hand.HandTypes.FourOfAKind)]*100.0))
        print("Straight Flush: %f%%"% ( opponentWins[int(Hand.HandTypes.StraightFlush)]*100.0))
        print("===============================================================================\n")
コード例 #4
0
ファイル: python_test.py プロジェクト: cpnei/HandEvaluator
def test_HandOdds():
    pockets = Array[String](["ac as", "ad 2c"])
    board = "4d 5d 6c"
    dead = ""
    wins = Array[Int64]([0]*2)
    ties = Array[Int64]([0]*2)
    losses = Array[Int64]([0]*2)
    totalHands = Int64(0)
    
    Hand.HandOdds(pockets, board, dead, wins, ties, losses, totalHands)
    #print(totalHands)
    #print(list(wins))
    #print(list(ties))
    #print(list(losses))
    totalHands = float(wins[0]+ties[0]+losses[0]) # so far there is an issue that totalHands is always returned as zero #float(int(totalHands.ToString()))
    
    print("P1_win:")
    print(wins[0]/totalHands)
    print("P1_ties:")
    print(ties[0]/totalHands)
    print("P1_losses:")
    print(losses[0]/totalHands)
    
    print("P2_win:")
    print(wins[1]/totalHands)
    print("P2_ties:")
    print(ties[1]/totalHands)
    print("P2_losses:")
    print(losses[1]/totalHands)
コード例 #5
0
ファイル: python_test.py プロジェクト: cpnei/HandEvaluator
def test_HandPotential():
    pp = Double(0)
    np = Double(0)
    Pocket = "ac as"
    Board = "4d 5d 6c"
    r = Hand.HandPotential(Pocket, Board, pp, np)
    print("Positive potential", pp)
    print("Negative potential", np)
    print(r)
コード例 #6
0
ファイル: python_test.py プロジェクト: cpnei/HandEvaluator
def test_MCWinRate():
    wr = Double(0)
    
    start_time = time.time()
    Pocket = "ac as"
    Board = "4d 5d 6c"
    for i in [10, 100, 1000, 10000, 100000, 1000000]:
        r = Hand.MCWinRate(Pocket, Board, "", 10, i, wr)
        etime = (time.time()-start_time)
        print(i, r)
        print("elapsed time=", etime)
コード例 #7
0
ファイル: sarsaAgent.py プロジェクト: sypannapis/holdem
    def readState(self, state, playerid):
        self.call_risk = float(state.community_state.to_call) / (
            state.community_state.totalpot + state.community_state.to_call)
        #assert self.call_risk <= 0.5
        pocket = card_list_to_str(state.player_states[playerid].hand)
        board = card_list_to_str(state.community_card)
        self.stack = state.player_states[playerid].stack
        self.call_level = float(state.community_state.to_call) / 20
        if self.call_level < 1:
            self.call_level = 0
        else:
            self.call_level = int(np.log2(self.call_level))

        #self.logger.info("debug:", board, ",", self.lastboard)
        if state.community_state.round != self.round:
            self.round = state.community_state.round
            self.hand_odds = self.calcHandOdds(pocket, board)
            if self.round < 3 and self.round > 0:
                (r, self.ppot,
                 self.npot) = Hand.HandPotential(pocket, board, Double(0),
                                                 Double(0))
            else:
                (self.ppot, self.npot) = (0.0, 0.0)
            self.lastboard = board
            self._roundRaiseCount = 0

        self.n_opponent = 0
        for p in state.player_states:
            if p.playing_hand:
                self.n_opponent += 1
        if state.player_states[playerid].playing_hand:
            # self is not opponent
            self.n_opponent -= 1

        available_actions = [
            action_table.CALL, action_table.RAISE, action_table.FOLD
        ]
        if state.player_states[
                playerid].stack == 0 or self._roundRaiseCount == 4:
            available_actions.remove(action_table.RAISE)
        if state.community_state.to_call <= state.player_states[
                playerid].betting:
            available_actions.remove(action_table.FOLD)
        return available_actions
コード例 #8
0
ファイル: python_test.py プロジェクト: cpnei/HandEvaluator
def CalcWinrate_hpoo(Pocket, Board):
    playerWins = Array[Double]([1.0]*9)
    opponentWins = Array[Double]([0.0]*9)
    Hand.HandPlayerOpponentOdds(Pocket, Board, playerWins, opponentWins)
    return sum(playerWins)
コード例 #9
0
ファイル: python_test.py プロジェクト: cpnei/HandEvaluator
def CalcWinrate_mc(Pocket, Board):
    wr = Double(0)
    r = Hand.MCWinRate(Pocket, Board, "", 10, 1000000, wr)
    return r
コード例 #10
0
 def calcHandOdds(self, pocket, board):
     playerWins = Array[Double]([1.0] * 9)
     opponentWins = Array[Double]([0.0] * 9)
     Hand.HandPlayerOpponentOdds(pocket, board, playerWins, opponentWins)
     return float(sum(playerWins))