2020-08-01 03:52:59 -07:00
|
|
|
# 0 AD Python Client
|
2024-08-27 01:06:31 -07:00
|
|
|
|
|
|
|
|
This directory contains `zero_ad`, a python client for 0 AD which enables users to control the
|
|
|
|
|
environment headlessly.
|
2020-08-01 03:52:59 -07:00
|
|
|
|
|
|
|
|
## Installation
|
2024-08-27 01:06:31 -07:00
|
|
|
|
2020-08-01 03:52:59 -07:00
|
|
|
`zero_ad` can be installed with `pip` by running the following from the current directory:
|
2024-08-27 01:06:31 -07:00
|
|
|
|
2020-08-01 03:52:59 -07:00
|
|
|
```
|
|
|
|
|
pip install .
|
|
|
|
|
```
|
|
|
|
|
|
2024-08-27 01:06:31 -07:00
|
|
|
Development dependencies can be installed with `pip install -r requirements-dev.txt`. Tests are
|
|
|
|
|
using pytest and can be run with `python -m pytest`.
|
2020-08-01 03:52:59 -07:00
|
|
|
|
|
|
|
|
## Basic Usage
|
2024-08-27 01:06:31 -07:00
|
|
|
|
2020-08-01 03:52:59 -07:00
|
|
|
If there is not a running instance of 0 AD, first start 0 AD with the RL interface enabled:
|
2024-08-27 01:06:31 -07:00
|
|
|
|
2020-08-01 03:52:59 -07:00
|
|
|
```
|
|
|
|
|
pyrogenesis --rl-interface=127.0.0.1:6000
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Next, the python client can be connected with:
|
2024-08-27 01:06:31 -07:00
|
|
|
|
2020-08-01 03:52:59 -07:00
|
|
|
```
|
|
|
|
|
import zero_ad
|
|
|
|
|
from zero_ad import ZeroAD
|
|
|
|
|
|
|
|
|
|
game = ZeroAD('http://localhost:6000')
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
A map can be loaded with:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
with open('./samples/arcadia.json', 'r') as f:
|
|
|
|
|
arcadia_config = f.read()
|
|
|
|
|
|
|
|
|
|
state = game.reset(arcadia_config)
|
|
|
|
|
```
|
|
|
|
|
|
2024-08-27 01:06:31 -07:00
|
|
|
where `./samples/arcadia.json` is the path to a game configuration JSON (included in the first
|
|
|
|
|
line of the commands.txt file in a game replay directory) and `state` contains the initial game
|
|
|
|
|
state for the given map. The game engine can be stepped (optionally applying actions at each step)
|
|
|
|
|
with:
|
2020-08-01 03:52:59 -07:00
|
|
|
|
|
|
|
|
```
|
|
|
|
|
state = game.step()
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
For example, enemy units could be attacked with:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
my_units = state.units(owner=1)
|
|
|
|
|
enemy_units = state.units(owner=2)
|
|
|
|
|
actions = [zero_ad.actions.attack(my_units, enemy_units[0])]
|
|
|
|
|
state = game.step(actions)
|
|
|
|
|
```
|
|
|
|
|
|
2024-09-09 23:24:48 -07:00
|
|
|
For a more thorough example, check out samples/simple_example.py!
|