赞
踩
转自:专知
SMAC是Github上的一个用于在暴雪星际争霸2上进行多智能体协同强化学习(MARL)的环境。SMAC用了暴雪星际争霸2的机器学习API和DeepMing的PySC2为智能体与星际争霸2的交互提供了友好的接口,方便开发者观察和执行行动。
项目地址
https://github.com/oxwhirl/smac
安装SMAC
pip install git+https://github.com/oxwhirl/smac.git
另外,星际争霸2也是要安装的。
示例代码
在下面的代码中,独立的智能体在接收到观察和全局状态后会执行随机策略。
from smac.env import StarCraft2Env
import numpy as np
def main():
env = StarCraft2Env(map_name="8m")
env_info = env.get_env_info()
n_actions = env_info["n_actions"]
n_agents = env_info["n_agents"]
n_episodes = 10
for e in range(n_episodes):
env.reset()
terminated = False
episode_reward = 0
while not terminated:
obs = env.get_obs()
state = env.get_state()
actions = []
for agent_id in range(n_agents):
avail_actions = env.get_avail_agent_actions(agent_id)
avail_actions_ind = np.nonzero(avail_actions)[0]
action = np.random.choice(avail_actions_ind)
actions.append(action)
reward, terminated, _ = env.step(actions)
episode_reward += reward
print("Total reward in episode {} = {}".format(e, episode_reward))
env.close()
推荐阅读
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。