How to use the rlcard.envs.env.Env 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 / rlcard / envs / texasholdem.py View on Github external
from rlcard.games.texasholdem import *
from rlcard.envs.env import Env
from rlcard.games.texasholdem.game import TexasGame as Game

import random

class TexasEnv(Env):
	"""
	Texasholdem Environment
	"""

	def test(self):
		print('aaa')

	def __init__(self):
		self.game = Game()
		self.player_num = self.game.get_player_num() # get the number of players in the game

	def set_agents(self, agents):
		""" Set the agents that will interact with the environment

		Args:
			agents: list of Agent classes; [agents]
github datamllab / rlcard / rlcard / envs / limitholdem.py View on Github external
import json
import os
import numpy as np

import rlcard
from rlcard.envs.env import Env
from rlcard.games.limitholdem.game import LimitholdemGame as Game

class LimitholdemEnv(Env):
    ''' Limitholdem Environment
    '''

    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)

    def get_legal_actions(self):
        ''' Get all leagal actions
github datamllab / rlcard / rlcard / envs / nolimitholdem.py View on Github external
import json
import os
import numpy as np

import rlcard
from rlcard.envs.env import Env
from rlcard.games.nolimitholdem.game import NolimitholdemGame as Game

class NolimitholdemEnv(Env):
    ''' Limitholdem Environment
    '''

    def __init__(self, allow_step_back=False):
        ''' Initialize the Limitholdem environment
        '''
        super().__init__(Game(allow_step_back), allow_step_back)
        self.actions = ['call', 'fold', 'check']
        self.state_shape = [54]
        for raise_amount in range(1, self.game.init_chips+1):
            self.actions.append(raise_amount)

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

    def get_legal_actions(self):
github datamllab / rlcard / rlcard / envs / uno.py View on Github external
import numpy as np

from rlcard.envs.env import Env
from rlcard import models
from rlcard.games.uno.game import UnoGame as Game
from rlcard.games.uno.utils import encode_hand, encode_target
from rlcard.games.uno.utils import ACTION_SPACE, ACTION_LIST
from rlcard.games.uno.card import UnoCard


class UnoEnv(Env):

    def __init__(self, allow_step_back=False):
        super().__init__(Game(allow_step_back), allow_step_back)
        self.state_shape = [7, 4, 15]

    def print_state(self, player):
        ''' Print out the state of a given player

        Args:
            player (int): Player id
        '''
        state = self.game.get_state(player)
        print('\n=============== Your Hand ===============')
        UnoCard.print_cards(state['hand'])
        print('')
        print('=============== Last Card ===============')
github datamllab / rlcard / rlcard / envs / doudizhu.py View on Github external
import numpy as np

from rlcard.envs.env import Env
from rlcard.games.doudizhu.game import DoudizhuGame as Game
from rlcard.games.doudizhu.utils import SPECIFIC_MAP, CARD_RANK_STR
from rlcard.games.doudizhu.utils import ACTION_LIST, ACTION_SPACE
from rlcard.games.doudizhu.utils import encode_cards


class DoudizhuEnv(Env):
    ''' Doudizhu Environment
    '''

    def __init__(self, allow_step_back=False):
        super().__init__(Game(allow_step_back), allow_step_back)
        self.state_shape = [6, 5, 15]

    def extract_state(self, state):
        ''' Encode state

        Args:
            state (dict): dict of original state

        Returns:
            numpy array: 6*5*15 array
                         6 : current hand
github datamllab / rlcard / rlcard / envs / mahjong.py View on Github external
import numpy as np

from rlcard.envs.env import Env
from rlcard.games.mahjong.game import MahjongGame as Game
from rlcard.games.mahjong.card import MahjongCard as Card
from rlcard.games.mahjong.utils import card_encoding_dict, encode_cards, pile2list

class MahjongEnv(Env):
    ''' Mahjong Environment
    '''

    def __init__(self, allow_step_back=False):
        super().__init__(Game(allow_step_back), allow_step_back)
        self.action_id = card_encoding_dict
        self.de_action_id = {self.action_id[key]: key for key in self.action_id.keys()}
        self.state_shape = [6, 34, 4]

    def extract_state(self, state):
        ''' Encode state

        Args:
            state (dict): dict of original state

        Returns:
github datamllab / rlcard / rlcard / envs / leducholdem.py View on Github external
import json
import os
import numpy as np

import rlcard
from rlcard.envs.env import Env
from rlcard.games.leducholdem.game import LeducholdemGame as Game
from rlcard.utils.utils import *
from rlcard import models


class LeducholdemEnv(Env):
    ''' Leduc Hold'em Environment
    '''

    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 = [6]

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

    def print_state(self, player):
        ''' Print out the state of a given player
github datamllab / rlcard / rlcard / envs / blackjack.py View on Github external
import numpy as np

from rlcard.envs.env import Env
from rlcard.games.blackjack.game import BlackjackGame as Game


class BlackjackEnv(Env):
    ''' Blackjack Environment
    '''

    def __init__(self, allow_step_back=False):
        ''' Initialize the Blackjack environment
        '''
        super().__init__(Game(allow_step_back), allow_step_back)
        self.rank2score = {"A":11, "2":2, "3":3, "4":4, "5":5, "6":6, "7":7, "8":8, "9":9, "T":10, "J":10, "Q":10, "K":10}
        self.actions = ['hit', 'stand']
        self.state_shape = [2]

    def get_legal_actions(self):
        ''' Get all leagal actions

        Returns:
            encoded_action_list (list): return encoded legal action list (from str to int)