-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataset_RL.py
70 lines (64 loc) · 3.28 KB
/
dataset_RL.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import os
import glob
import gym
import textworld.gym
def get_training_game_env_multiple_levels(data_dir, difficulty_level_list, training_size, requested_infos, max_episode_steps, batch_size):
assert training_size in [1, 20, 100]
# training games
game_file_names = []
for difficulty_level in difficulty_level_list:
game_path = data_dir + "/train_" + str(training_size) + "/difficulty_level_" + str(difficulty_level)
if os.path.isdir(game_path):
game_file_names += glob.glob(os.path.join(game_path, "*.z8"))
else:
game_file_names.append(game_path)
env_id = textworld.gym.register_games(sorted(game_file_names),
request_infos=requested_infos,
max_episode_steps=max_episode_steps,
batch_size=batch_size,
name="training",
asynchronous=False,
auto_reset=False)
env = gym.make(env_id)
num_game = len(game_file_names)
return env, num_game
def get_training_game_env(data_dir, difficulty_level, training_size, requested_infos, max_episode_steps, batch_size):
assert difficulty_level in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 99]
assert training_size in [1, 20, 100]
# training games
game_file_names = []
game_path = data_dir + "/train_" + str(training_size) + "/difficulty_level_" + str(difficulty_level)
if os.path.isdir(game_path):
game_file_names += glob.glob(os.path.join(game_path, "*.z8"))
else:
game_file_names.append(game_path)
env_id = textworld.gym.register_games(sorted(game_file_names),
request_infos=requested_infos,
max_episode_steps=max_episode_steps,
batch_size=batch_size,
name="training",
asynchronous=False,
auto_reset=False)
env = gym.make(env_id)
num_game = len(game_file_names)
return env, num_game
def get_evaluation_game_env(data_dir, difficulty_level, requested_infos, max_episode_steps, batch_size, valid_or_test="valid"):
assert valid_or_test in ["valid", "test"]
assert difficulty_level in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 99]
# eval games
game_file_names = []
game_path = data_dir + "/" + valid_or_test + "/difficulty_level_" + str(difficulty_level)
if os.path.isdir(game_path):
game_file_names += glob.glob(os.path.join(game_path, "*.z8"))
else:
game_file_names.append(game_path)
env_id = textworld.gym.register_games(sorted(game_file_names),
request_infos=requested_infos,
max_episode_steps=max_episode_steps,
batch_size=batch_size,
name="eval",
asynchronous=False,
auto_reset=False)
env = gym.make(env_id)
num_game = len(game_file_names)
return env, num_game