Skip to content

Commit c869da3

Browse files
committed
added bin
1 parent e7140f4 commit c869da3

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

bin/__init__.py

Whitespace-only changes.

bin/interactive.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env python
2+
import os,sys
3+
sys.path.insert(1, os.path.join(sys.path[0], '..'))
4+
import argparse
5+
6+
from multiagent.environment import MultiAgentEnv
7+
from multiagent.policy import InteractivePolicy
8+
import multiagent.scenarios as scenarios
9+
10+
if __name__ == '__main__':
11+
# parse arguments
12+
parser = argparse.ArgumentParser(description=None)
13+
parser.add_argument('-s', '--scenario', default='', help='Path of the scenario Python script.')
14+
args = parser.parse_args()
15+
16+
# load scenario from script
17+
scenario = scenarios.load(args.scenario).Scenario()
18+
# create world
19+
world = scenario.make_world()
20+
# create multiagent environment
21+
env = MultiAgentEnv(world, scenario.reset_world, scenario.reward, scenario.observation, shared_viewer = False)
22+
# render call to create viewer window (necessary only for interactive policies)
23+
env.render()
24+
# create interactive policies for each agent
25+
policies = [InteractivePolicy(env,i) for i in range(env.n)]
26+
# execution loop
27+
obs_n = env.reset()
28+
while True:
29+
# query for action from each agent's policy
30+
act_n = []
31+
for i, policy in enumerate(policies):
32+
act_n.append(policy.action(obs_n[i]))
33+
# step environment
34+
obs_n, reward_n, done_n, _ = env.step(act_n)
35+
# render all agent views
36+
env.render()
37+
# display rewards
38+
for agent in env.world.agents:
39+
print(agent.name + " reward: %0.3f" % env._get_reward(agent))

0 commit comments

Comments
 (0)