rlcard.envs¶
rlcard.envs.env¶
- class rlcard.envs.env.Env(config)¶
Bases:
object
The base Env class. For all the environments in RLCard, we should base on this class and implement as many functions as we can.
- get_action_feature(action)¶
For some environments such as DouDizhu, we can have action features
- Returns:
The action features
- Return type:
(numpy.array)
- get_payoffs()¶
Get the payoffs of players. Must be implemented in the child class.
- Returns:
A list of payoffs for each player.
- Return type:
(list)
Note: Must be implemented in the child class.
- get_perfect_information()¶
Get the perfect information of the current state
- Returns:
A dictionary of all the perfect information of the current state
- Return type:
(dict)
- get_player_id()¶
Get the current player id
- Returns:
The id of the current player
- Return type:
(int)
- get_state(player_id)¶
Get the state given player id
- Parameters:
player_id (int) – The player id
- Returns:
The observed state of the player
- Return type:
(numpy.array)
- is_over()¶
Check whether the curent game is over
- Returns:
True if current game is over
- Return type:
(boolean)
- reset()¶
Start a new game
- Returns:
Tuple containing:
(numpy.array): The begining state of the game (int): The begining player
- Return type:
(tuple)
- run(is_training=False)¶
Run a complete game, either for evaluation or training RL agent.
- Parameters:
is_training (boolean) – True if for training purpose.
- Returns:
(list): A list of trajectories generated from the environment. (list): A list payoffs. Each entry corresponds to one player.
- Return type:
(tuple) Tuple containing
- Note: The trajectories are 3-dimension list. The first dimension is for different players.
The second dimension is for different transitions. The third dimension is for the contents of each transiton
- seed(seed=None)¶
- set_agents(agents)¶
Set the agents that will interact with the environment. This function must be called before run.
- Parameters:
agents (list) – List of Agent classes
- step(action, raw_action=False)¶
Step forward
- Parameters:
action (int) – The action taken by the current player
raw_action (boolean) – True if the action is a raw action
- Returns:
Tuple containing:
(dict): The next state (int): The ID of the next player
- Return type:
(tuple)
- step_back()¶
Take one step backward.
- Returns:
Tuple containing:
(dict): The previous state (int): The ID of the previous player
- Return type:
(tuple)
Note: Error will be raised if step back from the root node.
rlcard.envs.registration¶
- class rlcard.envs.registration.EnvRegistry¶
Bases:
object
Register an environment (game) by ID
- make(env_id, config={'allow_step_back': False, 'seed': None})¶
Create and environment instance
- Parameters:
env_id (string) – The name of the environment
config (dict) – A dictionary of the environment settings
- register(env_id, entry_point)¶
Register an environment
- Parameters:
env_id (string) – The name of the environent
entry_point (string) – A string the indicates the location of the envronment class
- class rlcard.envs.registration.EnvSpec(env_id, entry_point=None)¶
Bases:
object
A specification for a particular instance of the environment.
- rlcard.envs.registration.make(env_id, config={})¶
Create and environment instance
- Parameters:
env_id (string) – The name of the environment
config (dict) – A dictionary of the environment settings
env_num (int) – The number of environments
- rlcard.envs.registration.register(env_id, entry_point)¶
Register an environment
- Parameters:
env_id (string) – The name of the environent
entry_point (string) – A string the indicates the location of the envronment class
rlcard.envs.blackjack¶
- class rlcard.envs.blackjack.BlackjackEnv(config)¶
Bases:
Env
Blackjack Environment
- get_payoffs()¶
Get the payoff of a game
- Returns:
list of payoffs
- Return type:
payoffs (list)
- rlcard.envs.blackjack.get_score(hand)¶
rlcard.envs.doudizhu¶
- class rlcard.envs.doudizhu.DoudizhuEnv(config)¶
Bases:
Env
Doudizhu Environment
- get_action_feature(action)¶
For some environments such as DouDizhu, we can have action features
- Returns:
The action features
- Return type:
(numpy.array)
- get_payoffs()¶
Get the payoffs of players. Must be implemented in the child class.
- Returns:
a list of payoffs for each player
- Return type:
payoffs (list)
- get_perfect_information()¶
Get the perfect information of the current state
- Returns:
A dictionary of all the perfect information of the current state
- Return type:
(dict)
rlcard.envs.limitholdem¶
- class rlcard.envs.limitholdem.LimitholdemEnv(config)¶
Bases:
Env
Limitholdem Environment
- get_payoffs()¶
Get the payoff of a game
- Returns:
list of payoffs
- Return type:
payoffs (list)
- get_perfect_information()¶
Get the perfect information of the current state
- Returns:
A dictionary of all the perfect information of the current state
- Return type:
(dict)
rlcard.envs.gin_rummy¶
File name: envs/gin_rummy.py Author: William Hale Date created: 2/12/2020
rlcard.envs.leducholdem¶
- class rlcard.envs.leducholdem.LeducholdemEnv(config)¶
Bases:
Env
Leduc Hold’em Environment
- get_payoffs()¶
Get the payoff of a game
- Returns:
list of payoffs
- Return type:
payoffs (list)
- get_perfect_information()¶
Get the perfect information of the current state
- Returns:
A dictionary of all the perfect information of the current state
- Return type:
(dict)
rlcard.envs.mahjong¶
rlcard.envs.nolimitholdem¶
- class rlcard.envs.nolimitholdem.NolimitholdemEnv(config)¶
Bases:
Env
Limitholdem Environment
- get_payoffs()¶
Get the payoff of a game
- Returns:
list of payoffs
- Return type:
payoffs (list)
- get_perfect_information()¶
Get the perfect information of the current state
- Returns:
A dictionary of all the perfect information of the current state
- Return type:
(dict)
rlcard.envs.bridge¶
File name: envs/bridge.py Author: William Hale Date created: 11/26/2021
- class rlcard.envs.bridge.BridgeEnv(config)¶
Bases:
Env
Bridge Environment
- get_payoffs()¶
Get the payoffs of players.
- Returns:
A list of payoffs for each player.
- Return type:
(list)
- get_perfect_information()¶
Get the perfect information of the current state
- Returns:
A dictionary of all the perfect information of the current state
- Return type:
(dict)
- class rlcard.envs.bridge.BridgePayoffDelegate¶
Bases:
object
- get_payoffs(game: BridgeGame)¶
Get the payoffs of players. Must be implemented in the child class.
- Returns:
A list of payoffs for each player.
- Return type:
(list)
Note: Must be implemented in the child class.
- class rlcard.envs.bridge.BridgeStateExtractor¶
Bases:
object
- extract_state(game: BridgeGame)¶
Extract useful information from state for RL. Must be implemented in the child class.
- Parameters:
game (BridgeGame) – The game
- Returns:
The extracted state
- Return type:
(numpy.array)
- static get_legal_actions(game: BridgeGame)¶
Get all legal actions for current state.
- Returns:
A OrderedDict of legal actions’ id.
- Return type:
(OrderedDict)
- get_state_shape_size() int ¶
- class rlcard.envs.bridge.DefaultBridgePayoffDelegate¶
Bases:
BridgePayoffDelegate
- get_payoffs(game: BridgeGame)¶
Get the payoffs of players.
- Returns:
A list of payoffs for each player.
- Return type:
(list)
- class rlcard.envs.bridge.DefaultBridgeStateExtractor¶
Bases:
BridgeStateExtractor
- extract_state(game: BridgeGame)¶
Extract useful information from state for RL.
- Parameters:
game (BridgeGame) – The game
- Returns:
The extracted state
- Return type:
(numpy.array)
- get_state_shape_size() int ¶
rlcard.envs.uno¶
- class rlcard.envs.uno.UnoEnv(config)¶
Bases:
Env
- get_payoffs()¶
Get the payoffs of players. Must be implemented in the child class.
- Returns:
A list of payoffs for each player.
- Return type:
(list)
Note: Must be implemented in the child class.
- get_perfect_information()¶
Get the perfect information of the current state
- Returns:
A dictionary of all the perfect information of the current state
- Return type:
(dict)