Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion multigrid/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def reset(
# Check that agents don't overlap with other objects
for agent in self.agents:
start_cell = self.grid.get(*agent.state.pos)
assert start_cell is None or start_cell.can_overlap()
# assert start_cell is None or start_cell.can_overlap()

# Step count since episode start
self.step_count = 0
Expand Down
6 changes: 5 additions & 1 deletion multigrid/core/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class Color(str, IndexedEnum):
Enumeration of object colors.
"""
red = 'red'
green = 'green'
blue = 'blue'
green = 'green'
purple = 'purple'
yellow = 'yellow'
grey = 'grey'
Expand Down Expand Up @@ -95,6 +95,10 @@ class State(str, IndexedEnum):
open = 'open'
closed = 'closed'
locked = 'locked'
pickedup = 'pickedup'
available = 'available'
alive = 'alive'
dead = 'dead'


class Direction(enum.IntEnum):
Expand Down
36 changes: 34 additions & 2 deletions multigrid/core/world_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,14 +506,46 @@ class Key(WorldObj):
Key object that can be picked up and used to unlock doors.
"""

def __new__(cls, color: str = Color.blue):
def __new__(cls, color: str = Color.blue, is_pickedup: bool = False, is_available: bool = True, ):
"""
Parameters
----------
color : str
Object color
"""
return super().__new__(cls, color=color)
key = super().__new__(cls, color=color)
key.is_pickedup = is_pickedup
key.is_available = is_available
return key

@property
def is_pickedup(self) -> bool:
"""
Whether the key is pickedup.
"""
return self.state == State.pickedup

@is_pickedup.setter
def is_pickedup(self, value: bool):
"""
Set the key to be pickup or not.
"""
self.state = State.pickedup # set state to pickedup

@property
def is_available(self) -> bool:
"""
Whether the key is is available.
"""
return self.state == State.available

@is_available.setter
def is_available(self, value: bool):
"""
Set the key to be available or not.
"""
self.state = State.available # set state to available


def can_pickup(self) -> bool:
"""
Expand Down
4 changes: 4 additions & 0 deletions multigrid/envs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@
"""

from .blockedunlockpickup import BlockedUnlockPickupEnv
from .competative_red_blue_door import CompetativeRedBlueDoorEnv, CompetativeRedBlueDoorEnvV2
from .empty import EmptyEnv
from .locked_hallway import LockedHallwayEnv
from .playground import PlaygroundEnv
from .redbluedoors import RedBlueDoorsEnv


CONFIGURATIONS = {
'MultiGrid-BlockedUnlockPickup-v0': (BlockedUnlockPickupEnv, {}),
'MultiGrid-CompetativeRedBlueDoor-v0': (CompetativeRedBlueDoorEnv, {'size': 8}),
'MultiGrid-CompetativeRedBlueDoor-v2': (CompetativeRedBlueDoorEnvV2, {'size': 8, "allow_agent_overlap": False}),
'MultiGrid-Empty-5x5-v0': (EmptyEnv, {'size': 5}),
'MultiGrid-Empty-Random-5x5-v0': (EmptyEnv, {'size': 5, 'agent_start_pos': None}),
'MultiGrid-Empty-6x6-v0': (EmptyEnv, {'size': 6}),
Expand Down
Loading