Anti-Poaching Game
This is the environment for the Anti-Poaching game. This is a muli-agent competitive game between poachers and rangers. This is currently on v2, and implements the model as described in the formal model description.
Environment (PettingZoo)
The main environment is implemented in anti_poaching_game.py, following the PettingZoo specification. Utils that the environment needs are placed in the utils folder. This includes the following files:
-
game_utils.py includes the
Trap
andGridState
classes used to represent the Conservation Game world internally byConservationGame
. -
wrappers.py includes the
NonCategoricalFlatten: ParallelEnv -> ObservationWrapper(ParallelEnv)
andStackerWrapper: ParallelEnv -> MultiAgentEnv
wrappers.MultiAgentEnv
is the RLlib equivalent ofParallelEnv
. -
flatten_utils.py contains the
box_flatten
andbox_flatten_obs
functions that are used by the wrappers.
Virtual Environment (Python)
To have a ready-to-go environment created for you, execute the following line of code
$ source init.sh
Running tests
Tests can be run from the root folder using pytest
as follows:
$ pytest [test/]
Furthermore, tools like coverage
can be used to generate more extensive data like branch coverage as followS:
$ coverage --branch -m pytest
$ coverage html
Examples + RLlib
A few examples are found in the examples folder.
Manual policies
- the fixed_policy.py and the random_policy.py show how to use the game using hand-coded policies, or just to show the basic RL loop.
Rllib examples
The examples run MARL algorithms (Policy Gradients and PPO) on the developed model using RLlib. All code is now implemented in the central script main.py. This runs an RLlib algorithm in Multi-Agent Independent Learning mode for an AntiPoachingGame
instance. All examples have parameters that can be specified via command line (use --help to see all options); everything is wrapped to provide compatibility with RLlib.
# from the repository root
$ cd examples/rllib_examples
$ python main.py --grid 5