-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
41 lines (35 loc) · 1.16 KB
/
test.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
import json
import numpy as np
from gym import spaces
def load_data(file_path="./data.json"):
with open(file_path, 'r', encoding='utf-8') as file:
# 使用json.load()方法解析JSON数据
data = json.load(file)
# first = data["1"]
# l1 = first["100000"]
# print(first)
# print(l1)
dataset = {
"observations": [],
"actions": [],
"next_observations": [],
"rewards": [],
"terminals": []
}
next_obs = np.concatenate((data["1"]["100000"], data["1"]["200000"], data["1"]["300000"], data["1"]["400000"]))
dataset['observations'] = np.zeros(12)
dataset['actions'] = next_obs
dataset['next_observations'] = next_obs
dataset['rewards'] = data["1"]["kill"] - data["1"]["death"]
dataset['terminals'] = 1
print(dataset)
if __name__ == "__main__":
# state = np.zeros(12)#状态空间
# observation_space = spaces.Box(low=-np.inf, high=np.inf, shape=(12, ), dtype=np.float64)
# print(observation_space)
# load_data()
with open('data.json', 'r', encoding='utf-8') as file:
# 使用json.load()方法解析JSON数据
data = json.load(file)
with open('test.json', 'w') as json_file:
json.dump(data, json_file, indent=4)