mirror of
https://github.com/Farama-Foundation/Gymnasium.git
synced 2025-08-16 19:49:13 +00:00
* Delete prng.py Since it seems like this seeding function is rarely used. * Update __init__.py * Update kellycoinflip.py * Update core.py * Update box.py * Update discrete.py * Update multi_binary.py * Update multi_discrete.py * Update test_determinism.py * Update test_determinism.py * Update test_determinism.py * Update core.py * Update box.py * Update test_determinism.py * Update core.py * Update box.py * Update discrete.py * Update multi_binary.py * Update multi_discrete.py * Update dict_space.py * Update tuple_space.py * Update core.py * Create space.py * Update __init__.py * Update __init__.py * Update box.py * Update dict_space.py * Update discrete.py * Update dict_space.py * Update multi_binary.py * Update multi_discrete.py * Update tuple_space.py * Update discrete.py * Update box.py * Update dict_space.py * Update multi_binary.py * Update multi_discrete.py * Update tuple_space.py * Update multi_discrete.py * Update multi_binary.py * Update dict_space.py * Update box.py * Update test_determinism.py * Update kellycoinflip.py * Update space.py
38 lines
890 B
Python
38 lines
890 B
Python
import numpy as np
|
|
import gym
|
|
from .space import Space
|
|
|
|
|
|
class Discrete(Space):
|
|
"""
|
|
{0,1,...,n-1}
|
|
|
|
Example usage:
|
|
self.observation_space = spaces.Discrete(2)
|
|
"""
|
|
def __init__(self, n):
|
|
self.n = n
|
|
super().__init__((), np.int64)
|
|
self.np_random = np.random.RandomState()
|
|
|
|
def seed(self, seed):
|
|
self.np_random.seed(seed)
|
|
|
|
def sample(self):
|
|
return self.np_random.randint(self.n)
|
|
|
|
def contains(self, x):
|
|
if isinstance(x, int):
|
|
as_int = x
|
|
elif isinstance(x, (np.generic, np.ndarray)) and (x.dtype.kind in np.typecodes['AllInteger'] and x.shape == ()):
|
|
as_int = int(x)
|
|
else:
|
|
return False
|
|
return as_int >= 0 and as_int < self.n
|
|
|
|
def __repr__(self):
|
|
return "Discrete(%d)" % self.n
|
|
|
|
def __eq__(self, other):
|
|
return self.n == other.n
|