mirror of
https://github.com/Farama-Foundation/Gymnasium.git
synced 2025-08-07 00:11:46 +00:00
* add dtype to Box * remove board_game, debugging, safety, parameter_tuning environments * massive set of breaking changes - remove python logging module - _step, _reset, _seed, _close => non underscored method - remove benchmark and scoring folder * Improve render("human"), now resizable, closable window. * get rid of default step and reset in wrappers, so it doesn’t silently fail for people with underscore methods * CubeCrash unit test environment * followup fixes * MemorizeDigits unit test envrionment * refactored spaces a bit fixed indentation disabled test_env_semantics * fix unit tests * fixes * CubeCrash, MemorizeDigits tested * gym backwards compatibility patch * gym backwards compatibility, followup fixes * changelist, add spaces to main namespaces * undo_logger_setup for backwards compat * remove configuration.py
28 lines
775 B
Python
28 lines
775 B
Python
import numpy as np
|
|
from gym import Space, spaces
|
|
|
|
class Discrete(Space):
|
|
"""
|
|
{0,1,...,n-1}
|
|
|
|
Example usage:
|
|
self.observation_space = spaces.Discrete(2)
|
|
"""
|
|
def __init__(self, n):
|
|
self.n = n
|
|
Space.__init__(self, (), np.int64)
|
|
def sample(self):
|
|
return spaces.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
|