예제 #1
0
 def create_env(cls, flags, featurizer=None):
     f = featurizer or X.Concat([X.Text(), X.ValidMoves()])
     print('loading env')
     start_time = time.time()
     env = gym.make(flags.env, room_shape=(flags.height, flags.width), partially_observable=flags.partial_observability, max_placement=flags.max_placement, featurizer=f, shuffle_wiki=flags.shuffle_wiki, time_penalty=flags.time_penalty)
     print('loaded env in {} seconds'.format(time.time() - start_time))
     return env
예제 #2
0
 def create_env(cls, flags, featurizer=None):
     return super().create_env(flags, featurizer=featurizer or X.Concat([X.Text(), X.ValidMoves(), X.RelativePosition()]))
예제 #3
0
from rtfm.dynamics.monster import Player
from rtfm import featurizer as F


if __name__ == '__main__':
    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--env', help='environment to use', default='rock_paper_scissors')
    parser.add_argument('--height', type=int, help='room size', default=12)
    parser.add_argument('--width', type=int, help='room size', default=22)
    parser.add_argument('--seed', type=int, help='seed', default=42)
    parser.add_argument('-p', '--partially_observable', action='store_true', help='only show partial observability')
    parser.add_argument('-c', '--control', action='store_true', help='assume direct control')
    parser.add_argument('-w', '--shuffle_wiki', action='store_true', help='shuffle facts in the wiki')
    args = parser.parse_args()

    featurizer = F.Concat([F.Progress(), F.ValidMoves(), F.Terminal()])
    env = gym.make('rtfm:{}-v0'.format(args.env), featurizer=featurizer, partially_observable=args.partially_observable, room_shape=(args.height, args.width), shuffle_wiki=args.shuffle_wiki)

    random.seed(args.seed)

    score = total = 0
    while True:
        env.reset()
        feat = reward = finished = won = None
        while not finished:
            if args.control:
                ch = None
                while ch not in Player.keymap:
                    print('Current score {} out of {}'.format(score, total))
                    print('Enter your command. x to quit.')
                    ch = getch.getch()