Example #1
0
    def create_side_pots(self):
        reprocess_pots = True

        # gotta be a better way to do this but
        # I am getting tired of writing this bot
        while reprocess_pots:
            lowest_all_in_player = None
            for pot in self.pots:
                if pot.locked:
                    continue

                lowest_all_in_player = PotManager.get_lowest_all_in_player(pot)
                break

            if lowest_all_in_player:
                amount = lowest_all_in_player.bet * len(pot.players)
                total = pot.amount
                difference = total - amount
                new_players = list(pot.players)
                new_players.remove(lowest_all_in_player)

                pot.locked = True
                pot.amount = amount

                side_pot = Pot('Side Pot {}'.format(len(self.pots)),
                               difference, new_players)
                self.pots.append(side_pot)
            else:
                reprocess_pots = False
Example #2
0
def create_initial_pot(table):
    amount = 0
    side_pots_tmp = []
    if table.ante > 0:
        for player in table.player_order:
            if player.stack > table.ante:
                amount += table.ante
                player.stack -= table.ante
                player.equity += table.ante
            else:
                player.equity = player.stack
                amount += player.stack
                side_pots_tmp.append(player.stack)
                player.stack = 0
            if player.equity > (table.bb_amount + table.ante):
                amount += (player.equity - (table.bb_amount + table.ante))
                player.equity = table.bb_amount + table.ante

    # instantiate pot object
    players = table.player_order[:]
    pot = Pot(players, amount)

    # append side pots to Pot obj in case of all-in players
    if side_pots_tmp:
        for p in side_pots_tmp:
            pot.side_pots.append(p)

    # Add the initial pot to the table
    table.pots.append(pot)
Example #3
0
    def __init__(self,
                 starting_stack,
                 blind_structure,
                 hands_per_level,
                 logging_level=logging.INFO):
        logging.basicConfig(stream=sys.stderr, level=logging_level)
        self.starting_stack = starting_stack
        self.blind_structure = blind_structure
        self.hands_per_level = hands_per_level

        self.players = [
            mcplayer("Alice", self.starting_stack),
            randomplayer("Bob", self.starting_stack),
            randomplayer("Chris", self.starting_stack)
        ]

        self.pm = PlayerManager(self.players)

        self.pot = Pot()
        self.deck = Deck()
        self.board = []

        self.blind_level = 1  #Uses 1 indexing not 0 indexing
        self.BIG_BLIND = self.blind_structure[self.blind_level - 1]
        self.SMALL_BLIND = self.blind_structure[self.blind_level - 1] // 2

        self.num_hands = 0
        self.game_state = {}

        self.players_in_hand = 0
Example #4
0
    def POST(self):
        i = web.input()
        potstr = i.pot
        handstr = i.hand
        my_pot = Pot(set(potstr.split()))
        my_hand = Hand(set(handstr.split()))

        # my_pot = Pot(set(["AC", "2C", "2S", "KS"]))
        # my_hand = Hand(set(["3C", "KH"]))
        allotherhand = allCardsExceptHand(my_pot, my_hand)
        mybesthand = getBestFromPotAndHand(my_pot, my_hand)

        results = [mybesthand]
        for alist in allotherhand:
            besthand = getBestFromPotAndHandList(my_pot, alist)
            results.append(besthand)

        sortResults = pokerrank(results)
        finalResults = []
        for ahand in sortResults:
            finalResults.append(ahand)
            if (set(ahand.split()) == set(mybesthand.split())):
                break

        return render.calc(finalResults)
Example #5
0
def test_pot():
    #This class is hard it should test sooo many situations I'll list some
    #write tests for them as I go

    #1 player wins
    #1 player wins but one player that contributing to pot Folded
    #2 way split with 3 players
    #2 way split with 2 players
    #player is all in from posting small blind -wins/loses
    #player is all in from posting big blind -wins/loses
    #everyone folds PREFLOP
    #the winning player doesn't cover everyone
    #situation with 3 side pots. IE the player with the most chips has the worst hand, player with least chips has best hand. and etc for middle hand

    print("TESTING POT CLASS")
    stack = 100
    bet = 10
    p1 = Player("0", stack)
    p2 = Player("1", stack)
    p3 = Player("2", stack)

    players = [p1, p2, p3]

    print("testing 3 way split")
    pot = Pot()

    deck = Deck()
    deck.shuffle()

    board = []
    hand = deck.draw(2)
    board.append(deck.draw(5))

    #Note all 3 players are given the same hand which is not realistic but shouldn't matter
    p1.deal_new_hand(hand, 1)
    p2.deal_new_hand(hand, 1)
    p3.deal_new_hand(hand, 1)

    pot.add_to_pot(p1, bet)
    pot.add_to_pot(p2, bet)
    pot.add_to_pot(p3, bet)

    assert(p1.get_stack() == stack - bet)
    assert(p2.get_stack() == stack - bet)
    assert(p3.get_stack() == stack - bet)

    assert(pot.get_pot_size() == 3*bet)

    pot.payout(players, board)

    print(f"p1 stack: {p1.get_stack()}")

    assert(p1.get_stack() == stack)
    assert(p2.get_stack() == stack)
    assert(p3.get_stack() == stack)

    assert(pot.get_pot_size() == 0)

    print("Pot class: 8/8 tests passed")
Example #6
0
 def __init__(self, chairCount):
     players = []
     pot = Pot()
     seats = []
     dealOrder = []
     button = 1
     muck = collections.deque()
     for i in range(chairCount):
         seats.append('open')
Example #7
0
def evaluate_pot(table):
    # Todo:  Need more complete unit test coverage of this function
    """ Evaluates pot on table and creates side pots if necessary """
    pot = table.pots[-1]
    if pot.side_pots:
        # import pdb
        # pdb.set_trace()
        pot.side_pots = sorted(pot.side_pots)
        while pot.side_pots:
            amount = pot.side_pots.pop(0)

            x = 0
            new_players = []
            for player in pot.players:
                player.equity -= amount
                x += 1
                new_players.append(player)

            for player in pot.players:
                if player.stack == 0 and player.equity == 0:
                    pot.players.remove(player)
            for p in pot.side_pots:
                ind = pot.side_pots.index(p)
                pot.side_pots[ind] -= amount

            amount = amount * x
            amount += pot.amount
            pot.amount = 0
            new_pot = Pot(new_players, amount)
            table.pots.insert(0, new_pot)

            if len(pot.players) == 1:
                pot.side_pots = []

    for player in pot.players:
        pot.amount += player.equity
        player.equity = 0

    if len(pot.players) == 1:
        # Give last guy in pot money
        pot.players[0].stack += pot.amount
        table.pots.pop()

        if not table.pots:

            # Start new hand
            new_hand(table)
        else:
            while len(table.community_cards) < 5:
                deal(table)
            analyze(table)
    else:
        if len(table.community_cards) < 5:
            deal(table)
        else:
            analyze(table)
Example #8
0
 def __init__(self, game, button):
     self.game = game
     # make a copy of the deck for this round and shuffle it
     self.deck = copy.copy(game.deck)
     self.deck.shuffle()
     self.players = copy.copy(game.active_players)
     self.active_players = copy.copy(self.players)
     self.button = button
     self.pot = Pot()
     self.all_in = []
Example #9
0
    def test_discharge(self, mock_sleep):
        pot = Pot(5, 6)
        mock_gpio.IN = 'in'
        mock_gpio.OUT = 'out'

        pot.discharge()

        mock_gpio.setup.assert_has_calls([call(5, 'in'), call(6, 'out')])
        mock_gpio.output.assert_called_once_with(6, False)
        mock_sleep.assert_called_once_with(0.005)
Example #10
0
 def __init__(self, game, button, evaluator):
     self.game = game
     self.ranks = [
         "", "", "2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K",
         "A"
     ]
     # make a copy of the deck for this round and shuffle it
     self.deck = copy.copy(game.deck)
     self.deck.shuffle()
     self.players = copy.copy(game.active_players)
     self.active_players = copy.copy(self.players)
     self.button = button
     self.pot = Pot()
     self.all_in = []
     self.evaluator = evaluator
Example #11
0
class Board:
    """Mancala board.
    
    Board layout with pot indexs'.
    ______________________________________
    | [13] (12)(11)(10)( 9)( 8)( 7) [  ] |
    | [  ] ( 0)( 1)( 2)( 3)( 4)( 5) [ 6] |
    ______________________________________

    """
    pots = [Pot(i) for i in range(14)]

    @property
    def state(self):
        return [pot.count for pot in self.pots]
Example #12
0
 def __init__(self, deck, players, blindtimer, rules, bigblindonly=False):
     self.__deck = deck
     self.__players = players
     self.__blinds = blindtimer.getblinds()
     self.__blindtimer = blindtimer
     self.__pots = [Pot(players, 0)]
     self.__community = Community()
     self.__rules = rules
     self.__bigblindonly = bigblindonly
     self.__currentplayer = None
     self.__nextplayeractions = ()
     self.__firsttoact = None
     self.__lasttoact = None
     self.__winners = []
     self.__round = self.NOT_SET
Example #13
0
    def post_small_blind(self, player):
        if player.money < 1:
            return False

        pot = Pot('Main Pot', player, 1)
        player.money -= 1
        player.bet = 1
        player.action = "SMALL BLIND"

        self.pots.append(pot)
        self.chat.message('<@{}> posts small blind $1'.format(player.slack_id))
        self.current_bet = 1
        self.big_blind = None
        self.small_blind = player

        return True
Example #14
0
    def __updatepot(self):
        # No pots? What are you doing here?
        if len(self.__pots) == 0:
            return

        players = self.__pots[-1].getplayers()[:]

        # Find everyone who's all in
        allins = []
        for player in players:
            if player.isallin():
                allins.append((player.gettotalbet(), player.name(), player))
        allins.sort(key=lambda player: player[0])

        # Remove the biggest all-in as they're still in
        if len(allins) > 1 and allins[-1][0] > allins[-2][0]:
            allins[-1][2].reducebet(allins[-1][0] - allins[-2][0])
            allins[-1][2].notallin()
            self.__pots[-1].subtractvalue(allins[-1][0] - allins[-2][0])
            del (allins[-1])

        # fill the current pot and create a new side pot/pots
        last_allin = 0
        allin_count = 0
        for allin in allins:
            allin_count = allin_count + 1
            if allin[0] > last_allin:  # not already processed this all in bet
                for player in players:
                    if allin[0] > player.gettotalbet():
                        self.__pots[-1].addvalue(player.gettotalbet())
                        player.addedtopot(player.gettotalbet())
                    else:
                        self.__pots[-1].addvalue(allin[0])
                        player.addedtopot(allin[0])
            last_allin = allin[0]
            players.remove(allin[2])
            self.__pots.append(Pot(players, 0))

        # fill the main pot or side pot for remaining players
        for player in players:
            if player.gettotalbet() == 0:
                continue
            self.__pots[-1].addvalue(player.gettotalbet())
            player.addedtopot(player.gettotalbet())
Example #15
0
    def setUp(self):
        self.player1 = Player("player1", 100)
        self.player2 = Player("player2", 100)
        self.player3 = Player("player3", 100)
        self.player4 = Player("player4", 100)
        self.player5 = Player("player5", 100)
        self.player6 = Player("player6", 100)

        self.table = Table(6, 1, 2, [50, 100])

        self.table.join(1, self.player1, 100)
        self.table.join(2, self.player2, 100)
        self.table.join(3, self.player3, 100)
        self.table.join(4, self.player4, 100)
        self.table.join(5, self.player5, 100)
        self.table.join(6, self.player6, 100)

        # Set player order; happy path
        for k, v in self.table.seats.items():
            self.table.player_order.append(v)

        pot = Pot(self.table.player_order, 0)

        self.table.pots.append(pot)
Example #16
0
from sets import Set
from card import Card 
from hand import Hand 
from pot import Pot 
import itertools
def findsubsets(S,m):
    return set(itertools.combinations(S, m))

class Utils(object):

    def __init__(self, info):
        self.info = info 

    @staticmethod
    def getAllCombi(hand, pot):
        for card in hand.cards:
            print card 
        for card in pot.cards:
            print card 



if __name__ == "__main__":
    my_pot = Pot(set([Card("A", "C"),Card("2", "C"),Card("2", "S"), Card("K", "S")]))
    my_hand = Hand(set([Card("3", "C"), Card("K", "H")]))



    Utils.getAllCombi(my_hand, my_pot) 
Example #17
0
    def setUp(self):

        self.player1 = Player("player1", 100)
        self.player2 = Player("player2", 100)
        self.player3 = Player("player3", 100)
        self.player4 = Player("player4", 100)
        self.player5 = Player("player5", 100)
        self.player6 = Player("player6", 100)
        self.player7 = Player("player7", 100)
        self.player8 = Player("player8", 100)
        self.player9 = Player("player9", 100)

        self.table = Table(9, 1, 2, [50, 100])

        self.table.join(1, self.player1, 100)
        self.table.join(2, self.player2, 100)
        self.table.join(3, self.player3, 100)
        self.table.join(4, self.player4, 100)
        self.table.join(5, self.player5, 100)
        self.table.join(6, self.player6, 100)
        self.table.join(7, self.player7, 100)
        self.table.join(8, self.player8, 100)
        self.table.join(9, self.player9, 100)

        cards = [
            13, 'h', 14, 'h', 5, 'h', 5, 's', 5, 'h', 10, 'c', 3, 'h', 4, 'h',
            13, 's', 14, 's', 14, 's', 5, 's', 12, 's', 11, 's', 14, 's', 2,
            'd', 4, 'h', 2, 'h'
        ]

        # Set player order; happy path
        for k, v in self.table.seats.items():
            self.table.player_order.append(v)

        x = 0
        for player in self.table.player_order:
            value = cards[x]
            x += 1
            suit = cards[x]
            x += 1
            card0 = Card("name", value, suit)
            value = cards[x]
            x += 1
            suit = cards[x]
            x += 1
            card1 = Card("name", value, suit)
            player.hole_cards.append(card0)
            player.hole_cards.append(card1)

        table_cards = [12, 'h', 11, 'h', 10, 'h', 5, 'c', 5, 'd']
        x = 0
        while len(self.table.community_cards) != 5:
            value = table_cards[x]
            x += 1
            suit = table_cards[x]
            x += 1
            card = Card("name", value, suit)
            self.table.community_cards.append(card)
        pot = Pot(self.table.player_order, 100)

        self.table.pots.append(pot)
Example #18
0
                cardstr += card.__str__() + " "
            cardstr = cardstr[0:-1]
            allhands.append(cardstr)

        besthand = poker(allhands)
        return besthand
        #print besthand
    else:
        return "2S 3C 7D 5C 6H"
        #print "invalid hand " + str(handlist)


if __name__ == "__main__":
    potstr = sys.argv[1]
    handstr = sys.argv[2]
    my_pot = Pot(set(potstr.split()))
    my_hand = Hand(set(handstr.split()))

    # my_pot = Pot(set(["AC", "2C", "2S", "KS"]))
    # my_hand = Hand(set(["3C", "KH"]))
    allotherhand = allCardsExceptHand(my_hand)

    mybesthand = getBestFromPotAndHand(my_pot, my_hand)

    results = []
    for alist in allotherhand:
        besthand = getBestFromPotAndHandList(my_pot, alist)
        results.append(besthand)

    sortResults = pokerrank(results)
    counter = 0
Example #19
0
from flask import Flask

from pot import Pot


app = Flask(__name__)
pot = Pot('teapot')


@app.route('/teapot', methods=['GET'])
def get():
    return pot.get()


@app.route('/teapot', methods=['BREW', 'POST'])
def brew():
    return pot.brew()


@app.route('/teapot', methods=['WHEN'])
def when():
    return pot.when()


if __name__ == '__main__':
    app.run(port=8081)
Example #20
0
'''
@brief: brewd is a flask-based xHTCPCP daemon and server, written in python3

@author: Bader Zaidan 
@version: 0.01
'''

from flask import Flask, redirect  #, url_for
from pot import Pot

app = Flask(__name__)

covfefe = Pot("covfefe")


@app.route("/")
def reroute():
    #test redirect
    return redirect("pot", code=302)
    #   return "Home"


@app.route("/pot", methods=["GET"])
def get():
    return covfefe.get()


@app.route("/pot", methods=["HEAD"])
def head():
    return covfefe.head()