Skip to main content

Literature card game implementation

Project description

Literature

Travis CI

Literature card game implementation: https://en.wikipedia.org/wiki/Literature_(card_game)

Setup

Install with pip install literature. Built for Python 3.6.0.

Example gameplay:

>>> from literature import get_game, Card, Suit
>>> import logging
>>> logging.basicConfig(level=logging.INFO)
>>> l = get_game(4)
>>> l.turn
Player 3
>>> l.players[3].hand_to_dict()
Suit.CLUBS: [A of C, K of C]
Suit.DIAMONDS: [2 of D, 10 of D, J of D, Q of D, K of D]
Suit.HEARTS: [A of H, 5 of H, J of H]
Suit.SPADES: [A of S, Q of S]
>>> move = l.players[3].asks(l.players[2]).to_give(Card.Name(3, Suit.DIAMONDS))
>>> l.commit_move(move)
INFO:literature.literature:Failure: Player 3 requested the 3 of D from Player 2

Play against a model that I trained with:

>>> import literature
>>> import logging
>>> logging.basicConfig(level=logging.INFO)
>>> literature.learning.play_against_model('literature/model_10000.out')

See literature.py for documentation.

Limitations

  • The bots only consider asking for a Card that they know a Player does not possess in the case that there are no other possible Moves. I made this simplification because the initial training took too long otherwise.
  • The game state for a given Player encodes what that Player knows that all other Players know about each other's hands, but I don't encode any levels further than that. For example, the game state for Player i doesn't encode what Player j knows that Player k knows that Player l knows.
    • I chose not to represent this because it vastly increases the dimensionality of the problem, and I don't think that the information is particularly valuable.
  • During training, the bots will occasionally get caught in an infinite loop. To mitigate this, I add noise to the scores for each move and kill games after 200 moves.
  • I'm only training the bots for games of four right now. The code can be easily adapted to work for a different number of players.

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

literature-1.0.0.tar.gz (21.5 kB view details)

Uploaded Source

Built Distribution

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

literature-1.0.0-py3-none-any.whl (24.8 kB view details)

Uploaded Python 3

File details

Details for the file literature-1.0.0.tar.gz.

File metadata

  • Download URL: literature-1.0.0.tar.gz
  • Upload date:
  • Size: 21.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for literature-1.0.0.tar.gz
Algorithm Hash digest
SHA256 80cde9e921fc4ff9758e5fedebf53569dad454e8b677fc5de50a9f20efd0234e
MD5 064dbbfce0682298234903f4f7259024
BLAKE2b-256 987ed50c56114e49681f91f8eca478d11d29ddd4e176796f46c7835980c2a570

See more details on using hashes here.

File details

Details for the file literature-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: literature-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 24.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for literature-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ed52b4f04a330c15b6bda05233ccb3500009fd49b9ab609c371d12ee66270f89
MD5 d796123c48313d7b63567b00dc55bc94
BLAKE2b-256 06d0136d93df3bf7b29dc61f995b193539f2caa0f4e1ceb81900592f1d4701fa

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