Design Patterns

This page lays out some common design patterns for setting up your Phantom environment.

Simple Environment Pattern

This pattern is common for simple experiments. In this pattern all agents act at every step. Subclassing an environment from the PhantomEnv class is sufficient for this.

../_images/patterns-simple-env.svg

Finite State Machine Pattern

For more complex experiments with multiple steps and multiple agent groups potentially with a subset of agents taking actions each turn Phantom provides the FiniteStateMachineEnv class. This formalises the environment as a free state machine by extending the PhantomEnv class and providing a clean interface for managing the logic of each state and the transitions between states.

../_images/patterns-finite-state-machine.svg

Alternate Turn Pattern (Stackelberg Game)

A simple but commonly used pattern is that of a free state machine with two states that pass from one another. This is formally known as a Stackleberg game or a Stackelberg competition. This can easily be implemented using the FiniteStateMachineEnv class.

../_images/patterns-alternate-turn.svg