> 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
