Implemented loader for CustomConfigEnv for humanPlayer

This commit is contained in:
Dominik Moritz Roth 2022-09-20 21:56:50 +02:00
parent 74ebb6e250
commit 0412afb69c

View File

@ -1,16 +1,17 @@
from time import sleep, time
import numpy as np
import pygame
import yaml
from columbus import env
from columbus.observables import Observable, CnnObservable
def main():
Env = chooseEnv()
env = Env(fps=30)
env.start_pos = [0.6, 0.3]
playEnv(env)
env = chooseEnv()
while True:
playEnv(env)
input('<again?>')
env.close()
@ -22,6 +23,33 @@ def getAvaibleEnvs():
yield getattr(env, s)
def loadConfigDefinedEnv(EnvClass):
p = input('[Path to config> ')
with open(p, 'r') as f:
docs = list([d for d in yaml.safe_load_all(
f) if 'name' in d and d['name'] not in ['SLURM']])
for i, doc in enumerate(docs):
name = doc['name']
print('['+str(i)+'] '+name)
ds = int(input('[0]> ') or '0')
doc = docs[ds]
cur = doc
path = 'params.task.env_args'
p = path.split('.')
while True:
try:
if len(p) == 0:
break
key = p.pop(0)
print(key)
cur = cur[key]
except Exception as e:
print('Unable to find key "'+key+'"')
path = input('[Path> ')
print(cur)
return EnvClass(fps=30, **cur)
def chooseEnv():
envs = list(getAvaibleEnvs())
for i, Env in enumerate(envs):
@ -35,7 +63,10 @@ def chooseEnv():
if i < 0 or i >= len(envs):
print(
'[!] That is a number, but not one that makes sense in this context...')
return envs[i]
if envs[i] in [env.ColumbusConfigDefined]:
return loadConfigDefinedEnv(envs[i])
Env = envs[i]
return Env(fps=30)
def playEnv(env):