Skip to content

Commit 1539701

Browse files
committed
Imported SMAC code
1 parent c2243b2 commit 1539701

36 files changed

+1978
-1
lines changed

README.md

Lines changed: 148 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,148 @@
1-
# smac
1+
```diff
2+
- This is a BETA release.
3+
```
4+
5+
# SMAC - StarCraft Multi-Agent Challenge
6+
7+
[SMAC](https://github.com/oxwhirl/smac) is [WhiRL](http://whirl.cs.ox.ac.uk)'s environment for research in the field of collaborative multi-agent reinforcement learning (MARL) based on [Blizzard](http://blizzard.com)'s [StarCraft II](https://en.wikipedia.org/wiki/StarCraft_II:_Wings_of_Liberty) RTS game. SMAC makes use of Blizzard's [StarCraft II Machine Learning API](https://github.com/Blizzard/s2client-proto) and [DeepMind](https://deepmind.com)'s [PySC2](https://github.com/deepmind/pysc2) to provide a convenient interface for autonomous agents to interact with StarCraft II, getting observations and performing actions. Unlike the [PySC2](https://github.com/deepmind/pysc2), SMAC concentrates on *decentralised micromanamgent* scenarios, where each unit of the game is controlled by an individual RL agent.
8+
9+
Please refer to the accompanying [paper](https://arxiv.org/abs/TODO) and [blogpost](http://whirl.cs.ox.ac.uk/blog/smac) for the outline of our motivation for using SMAC as a testbed for MARL research and the initial experimental results.
10+
11+
## About
12+
13+
Together with SMAC we also release [PyMARL](https://github.com/oxwhirl/pymarl) - our framework for MARL research, which includes implementations of several state-of-the-art algorithms, such as [QMIX](https://arxiv.org/abs/1803.11485) and [COMA](https://arxiv.org/abs/1705.08926).
14+
15+
Should you have any question, please reach to [mikayel@samvelyan.com](mailto:[mikayel@samvelyan.com) or [tabish.rashid@cs.ox.ac.uk](mailto:[tabish.rashid@cs.ox.ac.uk).
16+
17+
18+
# Quick Start
19+
20+
## Installing SMAC
21+
22+
You can install SMAC by using the following command:
23+
24+
```shell
25+
$ pip install git+https://github.com/oxwhirl/smac.git
26+
```
27+
28+
Alternatively, you can clone the SMAC repository and then install `smac` with its dependencies:
29+
30+
```shell
31+
$ git clone https://github.com/oxwhirl/smac.git
32+
$ pip install smac/
33+
```
34+
35+
SMAC uses features of PySC2 that are not included in the latest release yet. If you have PySC2-2.0.1 already installed, please uninstall it first. SMAC will install a newer version from the master branch. You may also need to upgrade pip: `pip install --upgrade pip` for the install to work.
36+
37+
## Installing StarCraft II
38+
39+
SMAC is based on the full game of StarCraft II (versions >= 3.16.1). To install the game, follow the commands bellow.
40+
41+
### Linux
42+
43+
Please use the Blizzard's [repository](https://github.com/Blizzard/s2client-proto#downloads) to download the Linux version of StarCraft II. By default, the game is expected to be in `~/StarCraftII/` directory. This can be changed by setting the environment variable `SC2PATH`.
44+
45+
### MacOS/Windows
46+
47+
Please install StarCraft II from [Battle.net](https://battle.net). The free [Starter Edition](http://battle.net/sc2/en/legacy-of-the-void/) also works. PySC2 will find the latest binary should you use the default install location. Otherwise, similar to the Linux version, you would need to set the `SC2PATH` environment variable with the correct location of the game.
48+
49+
## SMAC maps
50+
51+
SMAC is composed of many combat scenarios with pre-configured maps. Before SMAC can be used, these maps need to be downloaded into the `Maps` directory of StarCraft II.
52+
53+
Download the [SMAC Maps](https://github.com/oxwhirl/smac/releases/download/v1.2/smac_maps.zip) and extract them to your `$SC2PATH/Maps` directory.(**TODO** fix the link) If you installed SMAC via git, simply copy the `SMAC_Maps` directory from `smac/env/starcraft2/maps/` into `$SC2PATH/Maps` directory.
54+
55+
### List the maps
56+
57+
To see the list of SMAC maps, together with the number of ally and enemy units and episode limit, run:
58+
59+
```shell
60+
$ python -m smac.bin.map_list
61+
```
62+
63+
## Testing SMAC
64+
65+
Please run the following command to make sure that `smac` and its maps are properly installed.
66+
67+
```bash
68+
$ python -m smac.examples.random
69+
```
70+
71+
## Watch a replay
72+
73+
You can watch saved replays by running:
74+
75+
```shell
76+
$ python -m pysc2.bin.play --norender --rgb_minimap_size 0 --replay <path-to-replay>
77+
```
78+
79+
This works for any replay as long as the map can be found by the game.
80+
81+
For more information, please refer to [PySC2](https://github.com/deepmind/pysc2) documentation.
82+
83+
# Documentation
84+
85+
For the detailed description of the environment, read the [SMAC documentation](docs/smac.md). The initial results of our experiments using SMAC can be found in the [accompanying paper](https://arxiv.org/abs/TODO).
86+
87+
# Citing SMAC
88+
89+
If you use SMAC in your research, please cite the [SMAC Paper](https://arxiv.org/abs/TODO).
90+
91+
*M. Samvelyan, T. Rashid, C. Schroeder de Witt, G. Farquhar, N. Nardelli, T.G.J Rudner, CM Hung, P.H.S. Torr, J. Foerster, S. Whiteson. The StarCraft Multi-Agent Challenge, CoRR abs/TBD, 2018*
92+
93+
In BibTeX format:
94+
95+
```tex
96+
@article{samvelyan19smac,
97+
title = {{The} {StarCraft} {Multi}-{Agent} {Challenge}},
98+
author = {Mikayel Samvelyan and Tabish Rashid and Christian Schroeder de Witt and Gregory Farquhar and Nantas Nardelli and Tim G. J. Rudner and Chia-Man Hung and Philiph H. S. Torr and Jakob Foerster and Shimon Whiteson},
99+
journal = {CoRR},
100+
volume = {abs/TBD},
101+
year = "2019"
102+
}
103+
```
104+
105+
# Code Example
106+
107+
Bellow is a small code example which illustrates how SMAC can be used. Here, individual agents execute random policies after receiving the observations and global state from the environment.
108+
109+
If you want to try the state-of-the-art algorithms (such as [QMIX](https://arxiv.org/abs/1803.11485) and [COMA](https://arxiv.org/abs/1705.08926)) on SMAC, make use of [PyMARL](https://github.com/oxwhirl/smac) - our framework for MARL research.
110+
111+
```python
112+
from smac.env import StarCraft2Env
113+
import numpy as np
114+
115+
116+
def main():
117+
env = StarCraft2Env(map_name="8m")
118+
env_info = env.get_env_info()
119+
120+
n_actions = env_info["n_actions"]
121+
n_agents = env_info["n_agents"]
122+
123+
n_episodes = 10
124+
125+
for e in range(n_episodes):
126+
env.reset()
127+
terminated = False
128+
episode_reward = 0
129+
130+
while not terminated:
131+
obs = env.get_obs()
132+
state = env.get_state()
133+
134+
actions = []
135+
for agent_id in range(n_agents):
136+
avail_actions = env.get_avail_agent_actions(agent_id)
137+
avail_actions_ind = np.nonzero(avail_actions)[0]
138+
action = np.random.choice(avail_actions_ind)
139+
actions.append(action)
140+
141+
reward, terminated, _ = env.step(actions)
142+
episode_reward += reward
143+
144+
print("Total reward in episode {} = {}".format(e, episode_reward))
145+
146+
env.close()
147+
148+
```

0 commit comments

Comments
 (0)