Skip to content

Add a new agent

Emma "Frank" Tosch edited this page Mar 24, 2020 · 1 revision

Naming conventions

Each agent lives in its own file under the game it plays. So, if you are writing an agent you wish to call MyAgent that plays Breakout, you'd create myagent.py under the breakout folder. The agents already in this repository all run from . import * to ensure that the content of the game module gets imported, but you can probably skip this.

Implementation

Your agent should subclass the abstract Agent class and override the get_action method:

class MyAgent(Agent):
"""An agent that always moves left."""

    def get_action(self):
        input = Input()
        input.left = True
        return input

The module initialization also makes the intervention API available, and you can use that for querying the current context:

class MyAgent(Agent):
"""An agent that uses context to decide what to do."""

    def get_action(self):
        input = Input()
        with breakout.BreakoutIntervention(self.toybox) as intervention:
            # do something different, depending on context.
            pass
        return input
Clone this wiki locally