Skip to content

Game library

OpenSpiel, Google DeepMind's game library, has more than 120 games: board games, poker, dice and card games, games with hidden information, chance, simultaneous moves, more than two players and cooperation. Each one is an AgentPlay world, so models and people can play it, and tournaments, ratings, experiments and benchmarks work on it as on any other world.

The rules are in SPEC-028.

Install

pip install "agentplaykit[openspiel]"
agentplaykit env list openspiel

OpenSpiel needs Python 3.9 or newer on Linux and macOS, and 3.11 or newer on Windows. The rest of AgentPlay works without it. env list openspiel lists every game, marks the featured ones, and says which games need params and which cannot be played.

Kuhn poker, a small poker game with bluffing, between two models:

agentplay: 1
name: kuhn-poker
seed: 1
world: {use: openspiel/kuhn_poker}
agents:
  - {id: alice, use: ollama, config: {model: "qwen2.5:7b", constrain: true}}
  - {id: bob, use: ollama, config: {model: llama3.2, constrain: true}}
agentplaykit play examples/openspiel/kuhn-poker.yaml --runs 20
agentplaykit report runs/

Each game is one hand, and each seed deals different cards, so --runs 20 plays 20 hands. The first agent is OpenSpiel's player 0, the second player 1, and so on.

Play Liar's Dice yourself against a model, in the terminal or with --live in the browser:

agentplaykit play examples/openspiel/liars-dice.yaml --human you
openspiel/liars_dice: you are you.
Liar's Dice. Each player rolls their dice in secret (faces 1 to 6). ...

  "your_dice": [6],
  "moves_so_far": [{"by": "model", "move": "2-5"}],

legal moves: 2-6 Liar
your move (you): 2-6

Any other game

Every game is openspiel/<name>, with OpenSpiel's options as params:

world: {use: openspiel/goofspiel, config: {params: {num_cards: 6}}}
world: {use: openspiel/liars_dice, config: {params: {numdice: 2}}}

A game whose number of players can change takes players: Kuhn poker for three is params: {players: 3}, with three agents in the scenario. Some games are built on another game, which you name the same way: openspiel/misere with params: {game: tic_tac_toe} is tic-tac-toe where three in a row loses.

agentplaykit check reports an unknown game, a misspelled parameter or a wrong number of agents before anything plays, with a "did you mean" hint:

error: goofspiel has no parameter "num_cardz" (s.yaml:world.config.params) -> did you mean
"num_cards"? its parameters, with their defaults: ... num_cards=13 ... [config.invalid]

Reports keep different params apart: openspiel/goofspiel(num_cards=6) and openspiel/goofspiel are two worlds, with separate ratings.

A few games cannot be played: mean-field games (a population, not players), crossword (its moves are not a list), and games whose chance cannot be replayed from a seed.

What a player sees

A player sees only what OpenSpiel says that player may see, never another player's cards or dice:

  • view: OpenSpiel's own text for that player, shown as preformatted text in the replay page and in the terminal;
  • you_are: the agent and its player number, such as bob (player 1);
  • game, and moves_left when the game has a maximum length;
  • for featured games, readable fields such as your_card and moves_so_far.

The legal moves are OpenSpiel's names for them, such as Bet, x3, 2-5 or Liar, and are listed every turn. Chance (deals, dice) is drawn from the run's seed, so the same seed and the same moves always give the same game. When the game is over, run_end.outcome.revealed shows what was hidden, such as both players' cards. Each player's score is OpenSpiel's return: chips won or lost in poker, +1 or -1 in most board games.

For games without written rules, the rules are built from the game's type: how many players, whether there is chance or hidden information, and that the legal moves are listed every turn. Strong models often know the game by name; small ones do better with featured games.

These have written rules and readable observations:

Game What it tests
connect_four planning ahead on a board, drawn as a grid in the viewer
kuhn_poker bluffing and calling bluffs, with three cards
leduc_poker betting over two rounds, with a public card
liars_dice bluffing and judging probabilities from your own dice
goofspiel bidding at the same time, and spending a fixed hand well
battleship memory of shots, and hidden information
hanabi cooperation: all players win or lose together (chat is off; hints are moves); not in OpenSpiel's Windows package
matrix_pd the Prisoner's Dilemma: cooperate or defect, played once

Other matrix games (matrix_sh Stag Hunt, matrix_bos Bach or Stravinsky, matrix_mp Matching Pennies and more) get the payoff table in each player's observation.

Tips

  • Set limits.max_steps for long games such as Go or backgammon: a game ends there, with no winner.
  • Models do better with constrain: true (on ollama and other chat_api presets), which limits a reply to the legal moves.
  • Every game that can be played passes the world conformance kit that agentplaykit test runs, in CI on Linux, Windows and macOS.