o
    c²“iÁ  ã                   @   s¤   d dl Z d dlmZmZ d dlZd dlmZ d dlm	Z	m
Z
 d dlmZ e  e¡Zeddefdd	„ƒZeddefd
d„ƒZdedeeeej f dejfdd„ZdS )é    N)ÚTypeÚUnion)Ú
EnvContext)ÚERR_MSG_INVALID_ENV_DESCRIPTORÚEnvError)Ú	PublicAPIFÚerrorc                 C   ó0   zddl }|W S  ty   | rtdƒ‚Y dS w )a	  Tries importing pyspiel and returns the module (or None).

    Args:
        error: Whether to raise an error if pyspiel cannot be imported.

    Returns:
        The pyspiel module.

    Raises:
        ImportError: If error=True and pyspiel is not installed.
    r   NzˆCould not import pyspiel! Pygame is not a dependency of RLlib and RLlib requires you to install pygame separately: `pip install pygame`.)ÚpyspielÚImportError)r   r
   © r   úP/home/ubuntu/.local/lib/python3.10/site-packages/ray/rllib/env/utils/__init__.pyÚtry_import_pyspiel   ó   ÿùr   c                 C   r	   )a  Tries importing open_spiel and returns the module (or None).

    Args:
        error: Whether to raise an error if open_spiel cannot be imported.

    Returns:
        The open_spiel module.

    Raises:
        ImportError: If error=True and open_spiel is not installed.
    r   Nz—Could not import open_spiel! open_spiel is not a dependency of RLlib and RLlib requires you to install open_spiel separately: `pip install open_spiel`.)Ú
open_spielr   )r   r   r   r   r   Útry_import_open_spiel,   r   r   Úenv_contextÚenv_descriptorÚreturnc              
   C   s¦   z
ddl }| ¡  W n tttfy   Y nw t|tƒr*| d¡r*ddl}t	 
|¡ zt|tƒr7|| ƒ}W |S t	j|fi | ¤Ž}W |S  t	jjyR   tt |¡ƒ‚w )a¿  Tries to create a gym env given an EnvContext object and descriptor.

    Note: This function tries to construct the env from a string descriptor
    only using possibly installed RL env packages (such as gym, pybullet_envs,
    etc). These packages are no installation requirements for RLlib. In case
    you would like to support more such env packages, add the necessary imports
    and construction logic below.

    Args:
        env_context: The env context object to configure the env.
            Note that this is a config dict, plus the properties:
            `worker_index`, `vector_index`, and `remote`.
        env_descriptor: The env descriptor as a gym-registered string, e.g. CartPole-v1,
            ALE/MsPacman-v5, or CartPoleContinuousBulletEnv-v0.
            Alternatively, the gym.Env subclass to use.

    Returns:
        The actual gym environment object.

    Raises:
        gym.error.Error: If the env cannot be constructed.
    r   Nzale_py:ALE/)Úpybullet_envsÚgetListÚAttributeErrorÚModuleNotFoundErrorr   Ú
isinstanceÚstrÚ
startswithÚale_pyÚgymÚregister_envsÚtypeÚmaker   ÚErrorr   r   Úformat)r   r   r   r   Úenvr   r   r   Ú_gym_env_creatorG   s$   ÿ


üýÿr$   )F)ÚloggingÚtypingr   r   Ú	gymnasiumr   Úray.rllib.env.env_contextr   Úray.rllib.utils.errorr   r   Úray.util.annotationsr   Ú	getLoggerÚ__name__ÚloggerÚboolr   r   r   ÚEnvr$   r   r   r   r   Ú<module>   s$    
ÿþý