From 705d0249931d5ec65e8dc80d468c9febd57a1589 Mon Sep 17 00:00:00 2001 From: moto Date: Mon, 9 May 2016 17:59:55 -0700 Subject: [PATCH] Feature/len (#68) * Add __len__ to discrete * Add __len__ to tuple --- gym/spaces/discrete.py | 2 ++ gym/spaces/tuple_space.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/gym/spaces/discrete.py b/gym/spaces/discrete.py index f3b3fa372..e0b4cfd89 100644 --- a/gym/spaces/discrete.py +++ b/gym/spaces/discrete.py @@ -21,3 +21,5 @@ class Discrete(Space): return "Discrete(%d)" % self.n def __eq__(self, other): return self.n == other.n + def __len__(self): + return n diff --git a/gym/spaces/tuple_space.py b/gym/spaces/tuple_space.py index e0f392878..03ef73189 100644 --- a/gym/spaces/tuple_space.py +++ b/gym/spaces/tuple_space.py @@ -7,6 +7,9 @@ class Tuple(Space): def __init__(self, spaces): self.spaces = spaces + def __len__(self): + return len(self.spaces) + def sample(self): return tuple([space.sample() for space in self.spaces])