-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added example for a basic agent script
- Loading branch information
1 parent
5cb06a3
commit 3e2a6a1
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/bin/env python | ||
import gym | ||
import macad_gym # noqa F401 | ||
|
||
env = gym.make("HomoNcomIndePOIntrxMASS3CTWN3-v0") | ||
configs = env.configs | ||
env_config = configs["env"] | ||
actor_configs = configs["actors"] | ||
|
||
|
||
class SimpleAgent(object): | ||
def __init__(self, actor_configs): | ||
"""A simple, deterministic agent for an example | ||
Args: | ||
actor_configs: Actor config dict | ||
""" | ||
self.actor_configs = actor_configs | ||
self.action_dict = {} | ||
|
||
def get_action(self, obs): | ||
""" Returns `action_dict` containing actions for each agent in the env | ||
""" | ||
for actor_id in self.actor_configs.keys(): | ||
# ... Process obs of each agent and generate action ... | ||
if env_config["discrete_actions"]: | ||
self.action_dict[actor_id] = 3 # Drive forward | ||
else: | ||
self.action_dict[actor_id] = [1, 0] # Full-throttle | ||
return self.action_dict | ||
|
||
|
||
agent = SimpleAgent(actor_configs) # Plug-in your agent or use MACAD-Agents | ||
for ep in range(2): | ||
obs = env.reset() | ||
done = {"__all__": False} | ||
step = 0 | ||
while not done["__all__"]: | ||
obs, reward, done, info = env.step(agent.get_action(obs)) | ||
print(f"Step#:{step} Rew:{reward} Done:{done}") | ||
step += 1 |