Ejemplo n.º 1
0
 def test_legal_action_provide(self):
     self.INFO.street = GameInfo.PREFLOP
     self.INFO.sb_pos = 0
     d = Dealer()
     pot = Pot()
     pot.add(5); pot.add(10)  #
     players = [MockLegalActPlayer(1,"sb",100),MockLegalActPlayer(2,"bb",10)]
     players[0].set_ans(["FOLD:0","CALL:5","RAISE:15:15"])   # choose call
     players[1].set_ans(["FOLD:0","CALL:0", "RAISE:15:15"])
     d.ask_action(players, pot, [], [], range(2),self.INFO)
Ejemplo n.º 2
0
 def test_correct_action(self):
     d = Dealer()
     player = BasePlayer(1,'a',100)
     pot = Pot()
     pot.add(5)  # sb
     pot.add(10)  # bb
     eq_('FOLD:0',d.correct_action(player, 'FOLD:10', pot, 10, 5))
     eq_('CALL:5',d.correct_action(player, 'CALL:5', pot, 10, 5))
     eq_('RAISE:15',d.correct_action(player, 'RAISE:15', pot, 10, 5))
     eq_('FOLD:0',d.correct_action(player, 'CALL:15', pot, 10, 5))
     eq_('FOLD:0',d.correct_action(player, 'RAISE:120', pot, 10, 0))
     pot.add(15)  # sb
     eq_('RAISE:20', d.correct_action(player, 'RAISE:20', pot, 20, 10))
     pot.add(20)  # bb
     eq_('CALL:10', d.correct_action(player, 'CALL:10',pot, 30, 20))
Ejemplo n.º 3
0
 def test_correct_raise_up(self):
     """
     Regression test for raise amount back to $10 after $40
     """
     self.INFO.street = GameInfo.PREFLOP
     self.INFO.sb_pos = 0
     pot = Pot()
     pot.add(5);pot.add(10)
     d = Dealer()
     p1 = MockPlayer(1,"a",1000)
     p2 = MockPlayer(2,"b",1000)
     p3 = MockPlayer(3,"c",1000)
     players = [p1,p2,p3]
     p1.set_action(["RAISE:20","RAISE:35","RAISE:50"])
     p2.set_action(["RAISE:25","RAISE:40","FOLD:0"])
     p3.set_action(["RAISE:15","RAISE:30","RAISE:45","FOLD:0"])
     p1.D = True;p2.D = True;p3.D = True;
     d.ask_action(players, pot, [], [], [2,0,1],self.INFO)
     eq_(1000-105,p1.stack)
     eq_(1000-65,p2.stack)
     eq_(1000-15-30-45,p3.stack)
Ejemplo n.º 4
0
 def test_legal_action(self):
     d = Dealer()
     player = BasePlayer(1,'a',100)
     pot = Pot()
     pot.add(5) # sb bet
     pot.add(10) # bb bet
     acts = d.get_legal_action(player, pot, 10, 5)
     ok_("FOLD:0" in acts)
     ok_("CALL:5" in acts)
     ok_("RAISE:15:15" in acts)
     pot.add(15) # sb bet
     acts = d.get_legal_action(player, pot, 20, 10)
     ok_("FOLD:0" in acts)
     ok_("CALL:10" in acts)
     ok_("RAISE:20:20" in acts)
     pot.add(20) # bb bet
     acts = d.get_legal_action(player, pot, 30, 20)
     ok_("FOLD:0" in acts)
     ok_("CALL:10" in acts)
     ok_("RAISE:25:25" in acts)
Ejemplo n.º 5
0
    def __init__(self):
        self.AUTO = True
        self.players = None
        self.sb_chip = None
        self.sb_pos = None
        self.round_count = 0
        self.retire = []  # who lost all money
        self.deactive = []  # who foled the round
        self.allin = []  # who did all-in in the round

        self.D = Dealer()
        self.E = HandEvaluator()
        self.deck = Deck()
        self.board = Board()
        self.pot = Pot()
Ejemplo n.º 6
0
class Table(object):

    def __init__(self):
        self.AUTO = True
        self.players = None
        self.sb_chip = None
        self.sb_pos = None
        self.round_count = 0
        self.retire = []  # who lost all money
        self.deactive = []  # who foled the round
        self.allin = []  # who did all-in in the round

        self.D = Dealer()
        self.E = HandEvaluator()
        self.deck = Deck()
        self.board = Board()
        self.pot = Pot()

    # You need to call this method before start the game.
    def setup(self, players, sb_chip):
        random.shuffle(players)
        self.players = players
        self.sb_pos = len(players)-1   # for init_round
        self.sb_chip = sb_chip
    
    # You need to call this method every time new round starts
    def init_round(self):
        self.round_count += 1
        self.board.reset()
        self.pot.reset()
        self.deck.shuffle(True)
        self.D.deal_card(self.deck, self.players, self.retire)
        self.sb_pos = (self.sb_pos+1)%len(self.players)
        self.allin = []
        self.deactive = []
        self.deactive += self.retire
        info = GameInfo(GameInfo.NEWGAME, self.sb_pos, self.players,\
                self.pot, self.board, self.deactive, [])

        # send new game information to all players
        for player in self.players:
            player.action(info)

    # public method to start the poker game
    def start_game(self, n):
        # Play round n times
        for i in range(n):
            # if one player beats the others then finish the game.
            if len(self.retire)+1 == len(self.players): break
            if not self.AUTO and i != 0: subprocess.call('clear')
            self.init_round()
            ui.round_info(self.round_count, n, self.players, self.sb_pos)
            if not self.AUTO:
                raw_input('> Type any button to start the round...')
            self.play_round()
    
    # play one round
    def play_round(self):
        # start street
        self.preflop()
        if len(self.deactive)+1 != len(self.players): self.street(GameInfo.FLOP)
        if len(self.deactive)+1 != len(self.players): self.street(GameInfo.TURN)
        if len(self.deactive)+1 != len(self.players): self.street(GameInfo.RIVER)
        self.showoff()

        if not self.AUTO:
            print '\n> Enter any input to start next round ...\n'
            raw_input()

    def preflop(self):
        """ Preflop task
            1. collect blind
            2. change order of player (big blind is last player in pre-flop)
            3. ask action to players
        """
        self.D.collect_blind(self.pot, self.players, self.sb_pos, self.sb_chip)
        n = len(self.players)
        order = [(self.sb_pos+2+i)%n for i in range(n)]
        info = GameInfo(GameInfo.PREFLOP, self.sb_pos, self.players, self.pot, self.board, self.deactive, [])
        self.D.ask_action(self.players, self.pot, self.deactive, self.allin, order, info)

    def street(self, street):
        """ FLOP, TURN, RIVER task is almost the same
            1. reset bet (again starts from CHECK:0,FOLD,RAISE:10)
            2. add cards on board
            3. change order of player to sb -> bb -> ...
            4. ask action
        """
        self.pot.reset_bet()
        if street == GameInfo.FLOP:  # draw 3 cards in FLOP
            self.board.addCards(self.deck.drawCards(3))
        else:
            self.board.addCard(self.deck.drawCard())
        if not self.AUTO: self.board.display()

        # the case when left player is allin and call or
        #   the case when all player allin
        if len(self.deactive)+len(self.allin)+1 == len(self.players) or \
                len(self.deactive)+len(self.allin) == len(self.players):
            return

        # ask action to player
        n = len(self.players)
        order = [(self.sb_pos+i)%n for i in range(n)]
        info = GameInfo(street, self.sb_pos, self.players, self.pot, self.board, self.deactive, [])
        self.D.ask_action(self.players, self.pot, self.deactive, self.allin, order, info)

    def showoff(self):
        winner, result = self.D.check_winner(self.players, self.deactive, self.board)
        self.D.money_to_winner(self.pot, self.players, winner, self.allin, self.retire)
        ui.round_result(self.round_count, winner, result)
Ejemplo n.º 7
0
 def test_min_raise(self):
     p = Pot()
     p.add(5) # sb
     p.add(10) # bb
     eq_(15, p.get_min_raise())
     p.add(15) # raise 15
     eq_(20 ,p.get_min_raise())
     p.add(15) # call 15
     eq_(20,p.get_min_raise())
     p.reset_bet()
     eq_(10, p.get_min_raise())