Bot-Man-Toe/agents/README.md

1.9 KiB

🚀 Write your own agent!

An agent is a Python class that knows how to play one or more games.

Don't worry about writing a perfect strategy. Start with something that works, print the incoming game state, and improve it one step at a time.

Quick start

  1. Copy example.py.
  2. Rename the file and the ExampleAgent class.
  3. Update the agent's name, author and version.
  4. Implement play_tic_tac_toe().
  5. Import your agent in client.py and let it play a game.

That's enough to get started.

Understanding the game

Whenever your agent has to make a move, it receives the current game state as a Python dictionary.

Start by printing it:

print(payload)

Run a few games and watch how the payload changes after every move. Once you understand what you're receiving, you can start writing your own strategy!

Your function should return:

{"move": 7}

where the number is the square you want to play.

Testing your agent

Open client.py and replace one of the players with your own agent. For example:

from agents.my_agent import MyAgent
from agents.chaos import AgentOfChaos

players = [
    MyAgent(),
    AgentOfChaos(),
]

The repository includes AgentOfChaos, a very simple opponent that plays random moves. It's useful for testing your own agent while you're developing it.

⚠️ Don't try to build the perfect player immediately! Agents are easy to improve while you test against other agents. Plus, imperfect agents are typically the most interesting.

Run the client, inspect the output, tweak your algorithm, and repeat. You don't need to understand the rest of the project before you can start experimenting.

What's next?

Once you're happy with your agent, you can: