> For the complete documentation index, see [llms.txt](https://docs.catanatron.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.catanatron.com/using-catanatron/images-and-media.md).

# Python Library

You can also use `catanatron` package directly which provides a core implementation of the Settlers of Catan game logic.

```python
from catanatron import Game, RandomPlayer, Color

# Play a simple 4v4 game
players = [
    RandomPlayer(Color.RED),
    RandomPlayer(Color.BLUE),
    RandomPlayer(Color.WHITE),
    RandomPlayer(Color.ORANGE),
]
game = Game(players)
print(game.play())  # returns winning color
```

### Iterating Over Plys (ticks)

Instead of using `game.play()` to play a game until completion, you can iterate step-by-step on each ply (decision point) like so:

```python
game = Game(players)
while game.winning_color() is None:
    print(game.state)
    action = game.play_tick()
    print(action)
```

### Debugging Game State

Inspecting the game state mid-simulation in the example above can be challenging. Even though inspecting the following is helpful:

```python
print(game.state.board.map.tiles)
print(game.state.board.buildings)
print(game.state.board.roads)
print(game.state.player_state)
```

Its often best to see them in the GUI. For this, if you have the GUI Docker Services running alongside this process you can open the game at this state in the GUI with the `open_link` function:

```python
from catanatron.web.utils import open_link
open_link(game)  # opens game in browser
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.catanatron.com/using-catanatron/images-and-media.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
