mirror of
https://github.com/Farama-Foundation/Gymnasium.git
synced 2025-08-08 08:48:26 +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
41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
import gym
|
|
from .space import Space
|
|
|
|
|
|
class Tuple(Space):
|
|
"""
|
|
A tuple (i.e., product) of simpler spaces
|
|
|
|
Example usage:
|
|
self.observation_space = spaces.Tuple((spaces.Discrete(2), spaces.Discrete(3)))
|
|
"""
|
|
def __init__(self, spaces):
|
|
self.spaces = spaces
|
|
super().__init__(None, None)
|
|
|
|
def seed(self, seed):
|
|
[space.seed(seed) for space in self.spaces]
|
|
|
|
def sample(self):
|
|
return tuple([space.sample() for space in self.spaces])
|
|
|
|
def contains(self, x):
|
|
if isinstance(x, list):
|
|
x = tuple(x) # Promote list to tuple for contains check
|
|
return isinstance(x, tuple) and len(x) == len(self.spaces) and all(
|
|
space.contains(part) for (space,part) in zip(self.spaces,x))
|
|
|
|
def __repr__(self):
|
|
return "Tuple(" + ", ". join([str(s) for s in self.spaces]) + ")"
|
|
|
|
def to_jsonable(self, sample_n):
|
|
# serialize as list-repr of tuple of vectors
|
|
return [space.to_jsonable([sample[i] for sample in sample_n]) \
|
|
for i, space in enumerate(self.spaces)]
|
|
|
|
def from_jsonable(self, sample_n):
|
|
return [sample for sample in zip(*[space.from_jsonable(sample_n[i]) for i, space in enumerate(self.spaces)])]
|
|
|
|
def __eq__(self, other):
|
|
return self.spaces == other.spaces
|