Esempio n. 1
0
File: game.py Progetto: yli96/rlcard
    def init_game(self):
        ''' Initialilze the game of Limit Texas Hold'em

        This version supports two-player limit texas hold'em

        Returns:
            (tuple): Tuple containing:

                (dict): The first state of the game
                (int): Current player's id
        '''

        # Initilize a dealer that can deal cards
        self.dealer = Dealer()

        # Initilize two players to play the game
        self.players = [Player(i) for i in range(self.num_players)]

        # Initialize a judger class which will decide who wins in the end
        self.judger = Judger()

        # Deal cards to each  player to prepare for the first round
        for i in range(2 * self.num_players):
            self.players[i % self.num_players].hand.append(
                self.dealer.deal_card())

        # Initilize public cards
        self.public_cards = []

        # Randomly choose a big blind and a small blind
        b = random.randint(0, self.num_players - 1)
        s = (b + 1) % self.num_players
        self.players[b].in_chips = self.big_blind
        self.players[s].in_chips = self.small_blind

        # The player next to the samll blind plays the first
        self.button = (s + 1) % self.num_players

        # Initilize a bidding round, in the first round, the big blind and the small blind needs to
        # be passed to the round for processing.
        self.round = Round(raise_amount=self.raise_amount,
                           allowed_raise_num=self.allowed_raise_num,
                           num_players=self.num_players)

        self.round.start_new_round(button=self.button,
                                   raised=[p.in_chips for p in self.players])

        # Count the round. There are 4 rounds in each game.
        self.round_counter = 0

        # Save the hisory for stepping back to the last state.
        self.history = []

        state = self.get_state(self.button)

        return state, self.button
Esempio n. 2
0
        if self.raised[self.button] == max(self.raised):
            full_actions.remove('call')

        return full_actions

    def is_over(self):
        ''' Check whether the round is over

        Returns:
            (boolean): True if the current round is over
        '''

        if self.not_raise_num >= self.num_players:
            return True
        return False


if __name__ == '__main__':
    players = [Player(0), Player(1)]
    button = 0
    r = LimitholdemRound(button, 2, 4)
    r.start_new_round(button=button, raised=[1, 2])
    print(r.raised, r.have_raised, r.not_raise_num)

    while not r.is_over():
        legal_actions = r.get_legal_actions()
        action = random.choice(legal_actions)
        print(button, action, legal_actions)
        button = r.proceed_round(players[button], action)
        print(r.raised, r.have_raised, r.not_raise_num)
Esempio n. 3
0
 def test_get_player_id(self):
     player = Player(3, np.random.RandomState())
     self.assertEqual(player.get_player_id(), 3)
Esempio n. 4
0
 def test_get_player_id(self):
     player = Player(3)
     self.assertEqual(player.get_player_id(), 3)