Skip to main content

An implementation of the card game Coup intended for machine learning

Project description

CoupML

CoupML is an implementation of the card game Coup intended for machine learning.

The rules can be found at https://boardgamegeek.com/boardgame/131357/coup. A flowchart clarifying the game play can be found at https://boardgamegeek.com/filepage/86105/action-resolution-order-flowchart.

The original game contains elements of simultaneous play, but for simplicity and compatibility with agent-based models, the turn order is serialized and deterministic in this implementation. Particularly:

  • After a player declares an action or reaction which is linked to a role, every other (living) player gets a chance to challenge the action, in turn order. Whether or not each player will challenge is kept secret until all players have responded. Ater this, the challenge is resolved. If the challenge is correct (the player declaring the action does not reveal the required role), then this player loses the influence, as usual. However, if the challenge is incorrect, ALL players who chose to challenge must reveal (and lose) an influence, in turn order. I feel this is in keeping with the spirit of the original game.

  • There is one case where multiple players can choose to block an action: foreign aid (blocked by any player with a duke). As with a challenge, each player gets a chance to block (secretly). Once all players have decided, if more than one player wants to block, one of them is selected at random by the dealer. This is a significant deviation from the original rules, but it is needed to avoid too much complexity. I doubt this will much affect an agent's ability to learn a good strategy, since foreign aid is a minor action in the game. If anything, agents will learn to block foreign aid slightly more that they would otherwise, since there is a probability that its block will have no effect (when the dealer chooses a different player to block.)

Some other points where the rules sometimes vary from player to player:

  • When a player is challenged, he may choose to reveal a role that is different from the one he claimed, i.e., intentionally losing the challenge as part of a longer bluff. (In accordance with the flowchart.)

  • If a player assassinates, is challenged and loses the challenge, they do not pay the 3 credits. If they win the challenge (or no one challenges), they pay the 3 credits, regardless of whether the opponent blocks. (In accordance with the flowchart.)

  • If a player assassinates and the opponent incorrectly challenges the assassin, the opponent loses an influence. The opponent then still has the chance to block with a contessa. (In accordance with the flowchart.)

  • If a player steals and the opponent dies (by incorrectly challenging the captain), the stealing player gets no money. This is a convenient behaviour given the implementation. (The correct behaviour in this case is not clear in the official rules or flowchart.)

Example of playing a game:

from coupml import Coup
import numpy as np

np_random = np.random.RandomState()
coup = Coup(4, np_random)
coup.init_game()

while not coup.is_game_over():
    actions = coup.get_legal_actions()
    action = np_random.choice(actions)
    print(f'Player {coup.player_to_act()} plays {action}')
    coup.play_action(action)

final_state = coup.get_state()
winner = final_state['game']['winning_player']
print(f'Player {winner} wins')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

coupml-0.1.0.tar.gz (28.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

coupml-0.1.0-py3-none-any.whl (26.5 kB view details)

Uploaded Python 3

File details

Details for the file coupml-0.1.0.tar.gz.

File metadata

  • Download URL: coupml-0.1.0.tar.gz
  • Upload date:
  • Size: 28.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for coupml-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0386d8f826047ee55e92ad8ca45bdc904cf0045dcb2102062bd2e5fb2a9577ef
MD5 fc58a803ddba78b5c7fa774e5a787036
BLAKE2b-256 0a8e688f4e161b96db4e624527ccd6107d2c249df6ecaba31c5ccc20317e6778

See more details on using hashes here.

File details

Details for the file coupml-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: coupml-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 26.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for coupml-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 279c437bf4d659fbd94a050df0a9aaf6c9d45ee94c3997cf6c4958db7427be02
MD5 2e5bdd138eb4c6566b43d89d62078e28
BLAKE2b-256 b6f2eaad0dadac94dfa0edda57d31a4e9e434f8e3ff2c96a77a00d1f42cac24f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page