hive.envs.base module
- class hive.envs.base.BaseEnv(env_spec, num_players)[source]
Bases:
abc.ABC
,hive.utils.registry.Registrable
Base class for environments.
- Parameters
- abstract reset()[source]
Resets the state of the environment.
- Returns
The initial observation of the new episode. turn (int): The index of the agent which should take turn.
- Return type
observation
- abstract step(action)[source]
Run one time-step of the environment using the input action.
- Parameters
action – An element of environment’s action space.
- Returns
Indicates the next state that is an element of environment’s observation space. reward: A reward achieved from the transition. done (bool): Indicates whether the episode has ended. turn (int): Indicates which agent should take turn. info (dict): Additional custom information.
- Return type
observation
- abstract seed(seed=None)[source]
Reseeds the environment.
- Parameters
seed (int) – Seed to use for environment.
- save(save_dir)[source]
Saves the environment.
- Parameters
save_dir (str) – Location to save environment state.
- load(load_dir)[source]
Loads the environment.
- Parameters
load_dir (str) – Location to load environment state from.
- property env_spec
- class hive.envs.base.ParallelEnv(env_name, num_players)[source]
Bases:
hive.envs.base.BaseEnv
Base class for environments that take make all agents step in parallel.
ParallelEnv takes an environment that expects an array of actions at each step to execute in parallel, and allows you to instead pass it a single action at each step.
This class makes use of Python’s multiple inheritance pattern. Specifically, when writing your parallel environment, it should extend both this class and the class that implements the step method that takes in actions for all agents.
If environment class A has the logic for the step function that takes in the array of actions, and environment class B is your parallel step version of that environment, class B should be defined as:
class B(ParallelEnv, A): ...
The order in which you list the classes is important. ParallelEnv must come before A in the order.
- Parameters
- reset()[source]
Resets the state of the environment.
- Returns
The initial observation of the new episode. turn (int): The index of the agent which should take turn.
- Return type
observation
- step(action)[source]
Run one time-step of the environment using the input action.
- Parameters
action – An element of environment’s action space.
- Returns
Indicates the next state that is an element of environment’s observation space. reward: A reward achieved from the transition. done (bool): Indicates whether the episode has ended. turn (int): Indicates which agent should take turn. info (dict): Additional custom information.
- Return type
observation