{ "info": { "author": "Paul Wildenhain", "author_email": "pwildenhain@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "\ufeff# terminal_playing_cards\n\n[![CircleCI](https://circleci.com/gh/pwildenhain/terminal_playing_cards.svg?style=shield)](https://circleci.com/gh/pwildenhain/terminal_playing_cards)\n[![codecov](https://codecov.io/gh/pwildenhain/terminal_playing_cards/branch/master/graph/badge.svg)](https://codecov.io/gh/pwildenhain/terminal_playing_cards)\n\nPython \ud83d\udce6 for building playing card games in the terminal.\n\nCheckout how pretty these cards look in a terminal window!\n\n![](_static/run_as_module.png)\n\nCheckout this [blackjack](https://github.com/pwildenhain/blackjack) repo for an example of how to use `terminal_playing_cards` to create python card games that run in a terminal window.\n\n1. [Getting started](#getting-started)\n2. [Customize a View](#customize-a-view)\n * [Negative spacing](#negative-spacing)\n * [Sorting](#sorting)\n * [Adding cards](#adding-cards)\n * [Removing cards](#removing-cards)\n3. [Customize a Deck](#customize-a-deck)\n * [Customize card values](#customize-card-values)\n * [Hidden cards](#hidden-cards)\n * [Add Joker cards](#add-joker-cards)\n * [Remove face card emojis](#remove-face-card-emojis)\n4. [Built-in methods](#built-in-methods)\n * [Math with Cards](#math-with-cards)\n * [Iterate through a Deck/View](#iterate-through-a-deck/view)\n * [Check the length of a Deck/View](#check-the-length-of-a-deck/view)\n\n## Getting started\n\n:arrow_down: Install the package from PyPI.\n\n```\npip install terminal_playing_cards\n```\n\n:hammer: Build a standard 52 playing card deck.\n\n```python\nfrom terminal_playing_cards import Deck\n\ndeck = Deck()\n```\n\n:arrows_counterclockwise: Shuffle the deck, deal out some cards, and convert the list of cards into a `View` that can be printed to the terminal.\n\n```python\n>>> from terminal_playing_cards import View\n\n>>> deck.shuffle()\n# Deal 5 cards\n>>> player_1_hand = View([deck.pop() for _ in range(5)])\n>>> print(player_1_hand)\n```\n\n![](_static/five_card_view.png)\n\n## Customize a View\n\n### Negative spacing\n\nIf you anticipate having a lot of cards in a single `View`, specify a negative value for the `View.spacing` attribute.\n\n```python\n>>> player_1_hand = View(\n... cards=[deck.pop() for _ in range(5)],\n... spacing=-5\n... )\n>>> print(player_1_hand)\n```\n\n![](_static/five_card_view_negative_spacing.png)\n\n### Sorting\n\nWhenever I play card games, I have a particular way I like to sort my hand. Use the `View.sort()` method to sort a `View` by value, suit, or both!\n\n```python\n>>> player_1_hand.sort()\n>>> print(player_1_hand)\n```\n\n![](_static/view_default_sort.png)\n\nIf you prefer to sort purely by value, specify that in `sort_order`.\n\n```python\n>>> player_1_hand.sort(sort_order=[\"value\"])\n>>> print(player_1_hand)\n```\n\n![](_static/view_sort_by_value.png)\n\nSee `help(View.sort)` for further details.\n\n### Adding cards\n\nAdding cards to a `View` is easy! Just deal another card from the deck, and add it to the existing view.\n\n```python\n>>> next_card = deck.pop()\n>>> player_1_hand += [next_card]\n>>> print(player_1_hand)\n```\n\n![](_static/add_card_to_view.png)\n\nNotice that this was done with a `list` of `Card` objects. This allows multiple cards to be added into a `View` at one time, and also allows two `View` objects to be added together.\n\n### Removing cards\n\nSince `View` inherits many of it's methods from `Deck`, use the `View.pop()` to kick cards out of a `View`\n\n```python\n>>> played_card = player_1_hand.pop()\n>>> print(played_card)\n```\n![](_static/card_dealt_from_view.png)\n\nAnd now our hand doesn't have that card in it anymore.\n\n```python\n>>> print(player_1_hand)\n```\n\n![](_static/view_after_dealt_card.png)\n\n## Customize a Deck\n\n### Customize card values\n\nIn a game like [Blackjack](https://en.wikipedia.org/wiki/Blackjack), face cards are all valued at ten. But the default deck specifications assign a jack a value of eleven. Set the `specifications` parameter to customize options like card values.\n\n```python\n>>> blackjack_deck = Deck(specifications=[\"face_cards\"])\n```\n\nSee `help(Deck)` for more details on how to customize `Deck` build specifications.\n\n### Hidden cards\n\nIf you were going to build a game like [Texas hold'em](https://en.wikipedia.org/wiki/Texas_hold_%27em) then you would want to hide the turn and the river cards by default.\n\nWhen building the `Deck`, set the `hidden` parameter to hide all cards when printed to the terminal by default.\n\n```python\n>>> hidden_deck = Deck(hidden=True)\n>>> top_card = hidden_deck.pop()\n>>> print(top_card)\n```\n\n![](_static/hidden_card.png)\n\nThis ensures that that \"back\" of a card is printed to the terminal, rather than the regular face. In order to reveal this card, set the `Card.hidden` attribute to `False`.\n\n```python\n>>> top_card.hidden = False\n>>> print(top_card)\n```\n![](_static/unhide_hidden_card.png)\n\n### Add Joker cards\n\n[Jokers](https://en.wikipedia.org/wiki/Joker_(playing_card)) aren't included in a `Deck` by default. Add them in after the fact if you need them for your game.\n\n```python\n>>> from terminal_playing_cards import Card\n\n>>> deck = Deck()\n>>> jokers = [Card(\"JK\", suit=\"none\") for _ in range(2)]\n>>> deck += jokers\n>>> print(deck[53])\n```\n\n![](_static/joker.png)\n\n### Remove face card emojis\n\nOn some terminal windows, emoji's don't print out as expected. Check out how the queen of hearts prints out in the [cmder](https://cmder.net/) console emulator.\n\n![](_static/queen_hearts_cmder.png)\n\n:rage: Why is it messed up??? :rage:\n\nNever fear! If this happens on your terminal, make sure to set `picture` parameter to False when building the `Deck`.\n\n```python\n>>> no_pic_deck = Deck(picture=False)\n# Default position of queen of hearts in a sorted Deck\n>>> queen_hearts = no_pic_deck[47]\n>>> print(queen_hearts)\n```\n\n![](_static/queen_hearts_no_emoji.png)\n\n:+1: That's more like it!\n\n## Built-in methods\n\n### Math with Cards\n\nAll cards have a `Card.value` attribute that is used for logical comparisions and simple arithmetic with numbers and other `Card` objects.\n\n```python\n>>> from terminal_playing_cards import Card\n\n>>> ace_spades = Card(\"A\", \"spades\", value=1)\n>>> ace_hearts = Card(\"A\", \"hearts\", value=1)\n>>> two_hearts = Card(\"2\", \"hearts\", value=2)\n>>> ace_spades < two_hearts\nTrue\n>>> ace_spades == ace_hearts\nTrue\n>>> two_hearts - 1\n1\n>>> sum([ace_spades, ace_hearts, two_hearts])\n4\n```\n\nNote: Equality is based on **value alone**. This is why the `ace_spades` is equal to the `ace_hearts` even though they have different suits.\n\n### Iterate through a Deck/View\n\nIteration is simple, treat a `Deck`/`View` as a list of `Card` objects.\n\n```python\n>>> deck = Deck()\n>>> hand = View([deck.pop() for _ in range(3)])\n>>> for card in hand:\n... print(repr(card))\nCard('A', 'clubs', value=1, hidden=False, picture=True)\nCard('A', 'diamonds', value=1, hidden=False, picture=True)\nCard('A', 'spades', value=1, hidden=False, picture=True)\n>>> for card in deck[:3]:\n... print(repr(card))\nCard('A', 'hearts', value=1, hidden=False, picture=True)\nCard('2', 'clubs', value=2, hidden=False, picture=True)\nCard('2', 'diamonds', value=2, hidden=False, picture=True)\n```\n\n### Check the length of a Deck/View\n\nEasy-peasy.\n\n```python\n>>> deck = Deck()\n>>> len(deck)\n52\n>>> hand = View([deck.pop() for _ in range(3)])\n>>> len(hand)\n3\n```", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/pwildenhain/terminal_playing_cards", "keywords": "cards", "license": "MIT", "maintainer": "Paul Wildenhain", "maintainer_email": "pwildenhain@gmail.com", "name": "terminal-playing-cards", "package_url": "https://pypi.org/project/terminal-playing-cards/", "platform": "", "project_url": "https://pypi.org/project/terminal-playing-cards/", "project_urls": { "Homepage": "https://github.com/pwildenhain/terminal_playing_cards", "Repository": "https://github.com/pwildenhain/terminal_playing_cards" }, "release_url": "https://pypi.org/project/terminal-playing-cards/0.1.0/", "requires_dist": [ "colorama (>=0.4.1,<0.5.0)" ], "requires_python": ">=3.6,<4.0", "summary": "Create card games for the terminal", "version": "0.1.0" }, "last_serial": 5762483, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "d5b86dad893dd177880cf7f843a0ecb9", "sha256": "ba3e274d10fae133362a5cc2cb2505f4d859a131a06290ad3f9442387674eca9" }, "downloads": -1, "filename": "terminal_playing_cards-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "d5b86dad893dd177880cf7f843a0ecb9", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 12900, "upload_time": "2019-08-30T22:31:24", "url": "https://files.pythonhosted.org/packages/38/3b/01ace752c5d4df6c8b7fef72bcb79f3729747c0142a7b5a0e243cbe06a99/terminal_playing_cards-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7ac1d0ee044a971a0da31073f3f48667", "sha256": "bbc540da1e5ce81b4652e8f5b92748f5d495bc2affd338ed708965c6db0a17d4" }, "downloads": -1, "filename": "terminal_playing_cards-0.1.0.tar.gz", "has_sig": false, "md5_digest": "7ac1d0ee044a971a0da31073f3f48667", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 13433, "upload_time": "2019-08-30T22:31:27", "url": "https://files.pythonhosted.org/packages/16/fa/3f1d835036d8783e532eddf0bd72fb11fcb5d672a2bd7b16636ee2088b01/terminal_playing_cards-0.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d5b86dad893dd177880cf7f843a0ecb9", "sha256": "ba3e274d10fae133362a5cc2cb2505f4d859a131a06290ad3f9442387674eca9" }, "downloads": -1, "filename": "terminal_playing_cards-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "d5b86dad893dd177880cf7f843a0ecb9", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 12900, "upload_time": "2019-08-30T22:31:24", "url": "https://files.pythonhosted.org/packages/38/3b/01ace752c5d4df6c8b7fef72bcb79f3729747c0142a7b5a0e243cbe06a99/terminal_playing_cards-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7ac1d0ee044a971a0da31073f3f48667", "sha256": "bbc540da1e5ce81b4652e8f5b92748f5d495bc2affd338ed708965c6db0a17d4" }, "downloads": -1, "filename": "terminal_playing_cards-0.1.0.tar.gz", "has_sig": false, "md5_digest": "7ac1d0ee044a971a0da31073f3f48667", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 13433, "upload_time": "2019-08-30T22:31:27", "url": "https://files.pythonhosted.org/packages/16/fa/3f1d835036d8783e532eddf0bd72fb11fcb5d672a2bd7b16636ee2088b01/terminal_playing_cards-0.1.0.tar.gz" } ] }