How to use the rlcard.games.limitholdem.game.LimitholdemGame function in rlcard

To help you get started, we’ve selected a few rlcard examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github datamllab / rlcard / tests / games / test_limitholdem_game.py View on Github external
def test_step(self):
        game = Game()

        # test raise
        game.init_game()
        init_raised = game.round.have_raised
        game.step('raise')
        step_raised = game.round.have_raised
        self.assertEqual(init_raised+1, step_raised)

        # test call
        game.init_game()
        init_not_raise_num = game.round.not_raise_num
        game.step('call')
        step_not_raise_num = game.round.not_raise_num
        self.assertEqual(init_not_raise_num+1, step_not_raise_num)

        # test fold
github datamllab / rlcard / tests / games / test_limitholdem_game.py View on Github external
def test_get_action_num(self):
        game = Game()
        action_num = game.get_action_num()
        self.assertEqual(action_num, 4)
github datamllab / rlcard / tests / games / test_limitholdem_game.py View on Github external
def test_init_game(self):
        game = Game()
        state, player_id = game.init_game()
        test_id = game.get_player_id()
        self.assertEqual(test_id, player_id)
        self.assertIn('call', state['legal_actions'])
        self.assertIn('raise', state['legal_actions'])
        self.assertIn('fold', state['legal_actions'])
github datamllab / rlcard / tests / games / test_limitholdem_game.py View on Github external
def test_step_back(self):
        game = Game(allow_step_back=True)
        game.init_game()
        self.assertEqual(game.step_back(), False)
        index = 0
        previous = None
        while not game.is_over():
            index += 1
            legal_actions = game.get_legal_actions()
            if index == 2:
                result = game.step_back()
                now = game.get_player_id()
                if result:
                    self.assertEqual(previous, now)
                else:
                    self.assertEqual(len(game.history), 0)
                break
            previous = game.get_player_id()
github datamllab / rlcard / tests / games / test_limitholdem_game.py View on Github external
def test_payoffs(self):
        game = Game()
        np.random.seed(0)
        for _ in range(5):
            game.init_game()
            while not game.is_over():
                legal_actions = game.get_legal_actions()
                action = np.random.choice(legal_actions)
                game.step(action)
            payoffs = game.get_payoffs()
            total = 0
            for payoff in payoffs:
                total += payoff
            self.assertEqual(total, 0)
github datamllab / rlcard / tests / games / test_limitholdem_game.py View on Github external
def test_get_player_num(self):
        game = Game()
        player_num = game.get_player_num()
        self.assertEqual(player_num, 2)
github datamllab / rlcard / rlcard / games / limitholdem / game.py View on Github external
payoffs = self.judger.judge_game(self.players, hands)
        return payoffs

    def get_legal_actions(self):
        ''' Return the legal actions for current player

        Returns:
            (list): A list of legal actions
        '''

        return self.round.get_legal_actions()

# Test the game

if __name__ == "__main__":
    game = LimitholdemGame()
    while True:
        print('New Game')
        state, button = game.init_game()
        print(button, state)
        i = 1
        while not game.is_over():
            i += 1
            legal_actions = game.get_legal_actions()
            if i == 3:
                print('Step back')
                print(game.step_back())
                button = game.get_player_id()
                print(button)
                legal_actions = game.get_legal_actions()

            action = random.choice(legal_actions)
github datamllab / rlcard / rlcard / games / leducholdem / game.py View on Github external
import numpy as np
from copy import copy

from rlcard.games.leducholdem.dealer import LeducholdemDealer as Dealer
from rlcard.games.leducholdem.player import LeducholdemPlayer as Player
from rlcard.games.leducholdem.judger import LeducholdemJudger as Judger
from rlcard.games.leducholdem.round import LeducholdemRound as Round

from rlcard.games.limitholdem.game import LimitholdemGame

class LeducholdemGame(LimitholdemGame):

    def __init__(self, allow_step_back=False):
        ''' Initialize the class leducholdem Game
        '''
        self.allow_step_back = allow_step_back
        # Some configarations of the game
        # These arguments are fixed in Leduc Hold'em Game

        # Raise amount and allowed times
        self.raise_amount = 2
        self.allowed_raise_num = 2

        self.num_players = 2

    def init_game(self):
        ''' Initialilze the game of Limit Texas Hold'em
github datamllab / rlcard / rlcard / games / nolimitholdem / game.py View on Github external
import numpy as np
from copy import deepcopy
from rlcard.games.limitholdem.game import LimitholdemGame

from rlcard.games.nolimitholdem.dealer import NolimitholdemDealer as Dealer
from rlcard.games.nolimitholdem.player import NolimitholdemPlayer as Player
from rlcard.games.nolimitholdem.judger import NolimitholdemJudger as Judger
from rlcard.games.nolimitholdem.round import NolimitholdemRound as Round

class NolimitholdemGame(LimitholdemGame):

    def __init__(self, allow_step_back=False):
        ''' Initialize the class nolimitholdem Game
        '''
        self.allow_step_back = allow_step_back

        # small blind and big blind
        self.small_blind = 1
        self.big_blind = 2 * self.small_blind

        # config players
        self.num_players = 2
        self.init_chips = 100

    def init_game(self):
        ''' Initialilze the game of Limit Texas Hold'em
github datamllab / rlcard / rlcard / envs / limitholdem.py View on Github external
def __init__(self, allow_step_back=False):
        ''' Initialize the Limitholdem environment
        '''
        super().__init__(Game(allow_step_back), allow_step_back)
        self.actions = ['call', 'raise', 'fold', 'check']
        self.state_shape=[72]

        with open(os.path.join(rlcard.__path__[0], 'games/limitholdem/card2index.json'), 'r') as file:
            self.card2index = json.load(file)