0ad/source/tools/rlclient/python
Dunedan e36c6a31fe
Enable additional ruff rules
In the ruff config file added in #6954 explicitly selecting the ruff
rules to check was missed, resulting in ruff only checking a very small
subset of its available rules. That hasn't been desired, so this is the
first of a series of commits enabling more rules. In this PR all rules
whose violations can be either automatically fixed by ruff or are
trivial to fix manually get enabled. For the follow up PRs it's intended
to focus on one area of rules per PR to gradually improve the Python
code quality.
2024-08-25 06:29:39 +02:00
..
samples Enable additional ruff rules 2024-08-25 06:29:39 +02:00
tests Enable additional ruff rules 2024-08-25 06:29:39 +02:00
zero_ad Enable additional ruff rules 2024-08-25 06:29:39 +02:00
__init__.py Enable additional ruff rules 2024-08-25 06:29:39 +02:00
README.md Add an interface for Reinforcement Learning. 2020-08-01 10:52:59 +00:00
requirements-dev.txt Add an interface for Reinforcement Learning. 2020-08-01 10:52:59 +00:00
setup.py Enable additional ruff rules 2024-08-25 06:29:39 +02:00

0 AD Python Client

This directory contains zero_ad, a python client for 0 AD which enables users to control the environment headlessly.

Installation

zero_ad can be installed with pip by running the following from the current directory:

pip install .

Development dependencies can be installed with pip install -r requirements-dev.txt. Tests are using pytest and can be run with python -m pytest.

Basic Usage

If there is not a running instance of 0 AD, first start 0 AD with the RL interface enabled:

pyrogenesis --rl-interface=127.0.0.1:6000

Next, the python client can be connected with:

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)

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:

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)

For a more thorough example, check out samples/simple-example.py!