Exemple #1
0
def minigame(player1, player2, deck, stacksize):
    player1.stack = stacksize
    player2.stack = stacksize
    street = 0
    bigblind = 2
    smallblind = 1
    pot = bigblind + smallblind
    player1.stack -= smallblind
    player2.stack -= bigblind
    player1.bettotal = smallblind
    player2.bettotal = bigblind
    player1.allin = False
    player2.allin = False
    #each sub list in action has 3 attributes. Action, Betsize(if any), ratio to pot(if any)
    #seed the blinds into action list
    action = [['SB', 1, 0], ['BB', 2, 0]]
    board = pe.Board('', '')
    newdeck = deck[:]
    if street == 0:
        (outcome, action, board, pot, newdeck,
         street) = preflop(player1, player2, street, newdeck, pot, board,
                           action, smallblind, bigblind)
        if action[-1][0] == 'F':
            return outcome, action, pot
        street = street + 1
    while street < 4:
        #reset total investments per street pre player
        print "street", street
        player1.bettotal = 0
        player2.bettotal = 0
        #outcome and action are doing double duty here, could get rid of outcome and change the result evaluator
        (outcome, action, board, pot, newdeck,
         street) = postflop(player1, player2, street, newdeck, pot, board,
                            action, smallblind, bigblind)
        if action[-1][0] == 'F':
            break
        street = street + 1
        print "action", action
        print "stacks,pot", player1.stack, player2.stack, pot
    if street == 4 and action[-1][0] == 'C' or action[-2][0] == 'X' and action[
            -1][0] == 'X':
        print "showdown!"
        #board = randomboard(deck)
        #newboard = pe.Board("", "")
        #newboard.machinehand = board
        print "player1", player1.hand.machinehand, "player2", player2.hand.machinehand, "board", board.machinehand
        board.machinehand.sort(reverse=True)
        return pe.main(player1.hand, player2.hand, board), action, pot
    else:
        print "hand over"
        return outcome, action, pot
Exemple #2
0
def makehand(players,deck):
    newdeck = deck[:]
    players = []
    for i in xrange(0,len(players)):
        players[i].hand = pe.Hand('', None, [],[])
        (player[i].hand.cards, newdeck) = randomhand(player[i], newdeck)
        player1.hand.machinehand = player1.hand.cards
    return players
Exemple #3
0
def depthmontecarlo(herohand,villainrange,board,deck):
    #first we determine how many random cards we need to make
    street = len(board)
    if street == 0:
        #preflop
        #randomly remove 5 cards
    if street == 3:
        #flop
    if street == 4:
        #turn


    for i in xrange(0,len(usedcards)):
        if usedcards[i] in newdeck:
            newdeck.remove(usedcards[i])
    #print "usedcards", usedcards
    #print "deck", newdeck
    #hand1 win, hand2 win, tie, total sims
    results = [0,0,0,0]
    #call the main function
    board = randomboard(newdeck)
    newboard = pe.Board("", "")
    newboard.machinehand = board
    for i in xrange(0,1000):
        #shuffle deck
        board = randomboard(newdeck)
        newboard.machinehand = board
        outcome = pe.main(hand1,hand2,newboard)
        results[3] += 1
        #print "board", board
        #print "outcome", outcome
        if outcome[0] == "Tie!":
            results[2] += 1
        elif outcome[0] == "hand1":
            results[0] += 1
        else:
            results[1] += 1
    #count wins and divide by total sims
    percentage1 = results[0]*100 / results[3]
    percentage2 = results[1]*100 / results[3]
    print "percentage",percentage1,percentage2
    #now need to subtract winning stack from pot and record the amount
    return "results", results, "stacks", player1.stack, player2.stack
Exemple #4
0
def montecarlo(hand1,hand2,deck):
    #initialize hands with machine readable hands
    hand1.machinehand = pe.cardconversion(hand1.cards)
    hand2.machinehand = pe.cardconversion(hand2.cards)
    player1 = hand1
    player2 = hand2
    #combine the hands into one list
    usedcards = player1.machinehand + player2.machinehand
    #initialize deck, subtract hands from deck.
    newdeck = deck
    for i in xrange(0,len(usedcards)):
        if usedcards[i] in newdeck:
            newdeck.remove(usedcards[i])
    #print "usedcards", usedcards
    #print "deck", newdeck
    #hand1 win, hand2 win, tie, total sims
    results = [0,0,0,0]
    #call the main function
    board = randomboard(newdeck)
    newboard = pe.Board("", "")
    newboard.machinehand = board
    for i in xrange(0,1000):
        #shuffle deck
        board = randomboard(newdeck)
        newboard.machinehand = board
        outcome = pe.main(hand1,hand2,newboard)
        results[3] += 1
        #print "board", board
        #print "outcome", outcome
        if outcome[0] == "Tie!":
            results[2] += 1
        elif outcome[0] == "hand1":
            results[0] += 1
        else:
            results[1] += 1
    #count wins and divide by total sims
    percentage1 = results[0]*100 / results[3]
    percentage2 = results[1]*100 / results[3]
    print "percentage",percentage1,percentage2
    #now need to subtract winning stack from pot and record the amount
    return "results", results, "stacks", player1.stack, player2.stack
Exemple #5
0
def outcome(hand1,hand2,deck):
    results = [0,0,0,0]
    board = cl.Board("", "")
    board.machinehand = randomboard(deck)
    winner = pe.main(hand1,hand2,board)
    print winner
    if winner[0] == "Tie!":
        return 0.5
    elif winner[0] == "hand1":
        return 1
    else:
        return 0
Exemple #6
0
def main(deck, stacksize):
    #setting position 0 = btn, 1 = bb
    player1 = Player(None, '', 'U', 0, 0, False)
    player2 = Player(None, '', 'U', 1, 0, False)
    player1.hand = pe.Hand('', None, [], [])
    player2.hand = pe.Hand('', None, [], [])
    #player1 wins, player2 wins, tie, total games.
    results = [0, 0, 0, 0]
    #player1 winnings, player2 winnings.
    #Pot - bettotal = winnings on that street
    #pot + stack - initial stack = total winnings
    winnings = [0, 0]
    for i in xrange(0, 1000):
        newdeck = deck[:]
        (player1.hand.cards, newdeck) = randomhand(player1, newdeck)
        (player2.hand.cards, newdeck) = randomhand(player2, newdeck)
        player1.hand.machinehand = copy.deepcopy(player1.hand.cards)
        player2.hand.machinehand = copy.deepcopy(player2.hand.cards)
        print 'init hands', player1.hand.machinehand, player2.hand.machinehand
        outcome, action, pot = minigame(player1, player2, newdeck, stacksize)
        print "outcome", outcome
        results[3] += 1
        if outcome == "Tie!":
            results[2] += 1
        elif outcome == "hand1":
            results[0] += 1
            print "stuff1", (player1.stack, pot)
            amnt = player1.stack + pot
            loss = player2.stack - stacksize
            winnings[0] += (amnt - stacksize)
            winnings[1] += (loss)
        else:
            results[1] += 1
            print "stuff2", (player2.stack, pot)
            amnt = player2.stack + pot
            loss = player1.stack - stacksize
            winnings[1] += (amnt - stacksize)
            winnings[0] += (loss)
    return results, outcome, action, "pot", pot, "winnings", winnings