Browse Source

more args and door / key handling

refactoring
Thomas Knoll 1 year ago
parent
commit
ddc0a048b2
  1. 26
      examples/shields/rl/helpers.py

26
examples/shields/rl/helpers.py

@ -28,16 +28,29 @@ class ShieldingConfig(Enum):
def extract_keys(env): def extract_keys(env):
keys = [] keys = []
#print(env.grid)
for j in range(env.grid.height): for j in range(env.grid.height):
for i in range(env.grid.width): for i in range(env.grid.width):
obj = env.grid.get(i,j) obj = env.grid.get(i,j)
if obj and obj.type == "key": if obj and obj.type == "key":
keys.append(obj.color)
keys.append((obj, i, j))
if env.carrying and env.carrying.type == "key":
keys.append((env.carrying, -1, -1))
return keys return keys
def extract_doors(env):
doors = []
for j in range(env.grid.height):
for i in range(env.grid.width):
obj = env.grid.get(i,j)
if obj and obj.type == "door":
doors.append(obj)
return doors
def create_log_dir(args): def create_log_dir(args):
return F"{args.log_dir}sh:{args.shielding}-env:{args.env}" return F"{args.log_dir}sh:{args.shielding}-env:{args.env}"
@ -56,6 +69,8 @@ def get_action_index_mapping(actions):
return Actions.pickup return Actions.pickup
elif "done" in action_str: elif "done" in action_str:
return Actions.done return Actions.done
elif "drop" in action_str:
return Actions.drop
raise ValueError(F"Action string {action_str} not supported") raise ValueError(F"Action string {action_str} not supported")
@ -74,7 +89,11 @@ def parse_arguments(argparse):
"MiniGrid-LavaSlipperyS12-v1", "MiniGrid-LavaSlipperyS12-v1",
"MiniGrid-LavaSlipperyS12-v2", "MiniGrid-LavaSlipperyS12-v2",
"MiniGrid-LavaSlipperyS12-v3", "MiniGrid-LavaSlipperyS12-v3",
# "MiniGrid-DoorKey-8x8-v0",
"MiniGrid-DoorKey-8x8-v0",
"MiniGrid-DoubleDoor-16x16-v0",
"MiniGrid-DoubleDoor-12x12-v0",
"MiniGrid-DoubleDoor-10x8-v0",
"MiniGrid-SingleDoor-7x6-v0",
# "MiniGrid-LockedRoom-v0", # "MiniGrid-LockedRoom-v0",
# "MiniGrid-FourRooms-v0", # "MiniGrid-FourRooms-v0",
# "MiniGrid-LavaGapS7-v0", # "MiniGrid-LavaGapS7-v0",
@ -95,6 +114,7 @@ def parse_arguments(argparse):
parser.add_argument("--shielding", type=ShieldingConfig, choices=list(ShieldingConfig), default=ShieldingConfig.Full) parser.add_argument("--shielding", type=ShieldingConfig, choices=list(ShieldingConfig), default=ShieldingConfig.Full)
parser.add_argument("--steps", default=20_000, type=int) parser.add_argument("--steps", default=20_000, type=int)
parser.add_argument("--expname", default="exp") parser.add_argument("--expname", default="exp")
parser.add_argument("--shield_creation_at_reset", action=argparse.BooleanOptionalAction)
args = parser.parse_args() args = parser.parse_args()
return args return args
Loading…
Cancel
Save