Skip to main content

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.

Metadata

Release files for literature 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for literature 1.0.0
File Size Uploaded
literature-1.0.0.tar.gz 21.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for literature 1.0.0
File Interpreter ABI Platform
literature-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 46.3 kB

Release files / literature-1.0.0.tar.gz

Download URL literature-1.0.0.tar.gz
Size 21.5 kB
Tags Source
SHA-256 checksum
How to use checksums
80cde9e921fc4ff9758e5fedebf53569dad454e8b677fc5de50a9f20efd0234e
BLAKE2b-256 checksum
How to use checksums
987ed50c56114e49681f91f8eca478d11d29ddd4e176796f46c7835980c2a570
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release files / literature-1.0.0-py3-none-any.whl

Download URL literature-1.0.0-py3-none-any.whl
Size 24.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ed52b4f04a330c15b6bda05233ccb3500009fd49b9ab609c371d12ee66270f89
BLAKE2b-256 checksum
How to use checksums
06d0136d93df3bf7b29dc61f995b193539f2caa0f4e1ceb81900592f1d4701fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page