-
Notifications
You must be signed in to change notification settings - Fork 0
/
env_test.py
50 lines (39 loc) · 1.71 KB
/
env_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
42
43
44
45
46
47
48
49
50
from mlagents_envs.environment import UnityEnvironment
env = UnityEnvironment(file_name='./env/GcMaze.app')
env.reset()
behavior_name = list(env.behavior_specs._dict.keys())[0]
print(f"Name of the behavior : {behavior_name}")
spec = env.behavior_specs[behavior_name]
decision_steps, terminal_steps = env.get_steps(behavior_name)
tracked_agent = -1
done = False
episode_rewards = 0
done_num = 0
step = 0
alive_agent = 100
for _ in range(10000):
# env.set_actions(behavior_name, spec.create_random_action(len(decision_steps)))
env.set_actions(behavior_name, spec.action_spec.random_action(len(decision_steps)))
env.step()
step += 1
# if tracked_agent == -1 and len(decision_steps) >= 1:
# tracked_agent = decision_steps.agent_id[0]
decision_steps, terminal_steps = env.get_steps(behavior_name)
print(f"step = {step} agent = {len(decision_steps.agent_id)} done = {len(terminal_steps.agent_id)} alive = {alive_agent}")
if terminal_steps.agent_id.shape[0] != 0:
print(f"{terminal_steps.agent_id} is done, {decision_steps.agent_id}")
done_num += len(decision_steps.agent_id)
alive_agent -= len(decision_steps.agent_id)
# if done_num >= 4:
# env.reset()
# done_num = 0
# step = 0
# elif decision_steps.agent_id.shape[0] + terminal_steps.agent_id.shape[0] != 4 :
# print("Dont get four obs")
# if tracked_agent in decision_steps: # The agent requested a decision
# episode_rewards += decision_steps[tracked_agent].reward
# if tracked_agent in terminal_steps: # The agent terminated its episode
# episode_rewards += terminal_steps[tracked_agent].reward
# done = True
env.close()
print("Closed environment")