Skip to main content

Abstract games stuff

Project description

Abstract games stuff

Install

pip install AGStuff

Requirements

  • Python 3.6 or higher

Usage

Cards

Core

Card(sign)

Some card from standard 52 cards deck.

Sign consisting of two symbols (1st symbol is card weight, 2nd symbol is card suit).

Weight symbols: '2' (Two), '3' (Three), '4' (Four), '5' (Five), '6' (Six), '7' (Seven), '8' (Eight), '9' (Nine), 'T' (Ten), 'J' (Jack), 'Q' (Queen), 'K' (King), 'A' or '1' (Ace).

Suit symbols: 'c' (clubs), 'd' (diamonds), 'h' (hearts), 's' (spades).

Sign symbols are ignored since 3rd one.

>>> from agstuff.cards.core import Card

>>> card = Card('As')
>>> card
A
>>> card.name
'Ace of spades'

Сards can be compared

>>> from agstuff.cards.core import Card

>>> card1 = Card('9h')
>>> card2 = Card('5d')
>>> card1 != card2
True
>>> card1 < card2
False
>>> card1 > card2
True
>>> card1 == card2
False

>>> card3 = Card('Qc')
>>> card4 = Card('Qs')
>>> card3 != card4
False
>>> card3 < card4
False
>>> card3 > card4
False
>>> card3 == card4
True

Card weights or suits can be compared directly

>>> from agstuff.cards.core import Card

>>> card1 = Card('Td')
>>> card2 = Card('3d')
>>> card1.weight != card2.weight
True
>>> card1.weight < card2.weight
False
>>> card1.weight > card2.weight
True
>>> card1.weight == card2.weight
False
>>> card1.suit != card2.suit
False
>>> card1.suit == card2.suit
True

>>> card3 = Card('7h')
>>> card4 = Card('7c')
>>> card3.weight != card4.weight
False
>>> card3.weight < card4.weight
False
>>> card3.weight > card4.weight
False
>>> card3.weight == card4.weight
True
>>> card3.suit != card4.suit
True
>>> card3.suit == card4.suit
False

Also possible use abstract cards

>>> from agstuff.cards.core import Card

>>> card1 = Card('8s')
>>> card2 = Card('K') # abstract king card
>>> card3 = Card('8') # abstract eight card
>>> card1 != card2
True
>>> card1 < card2
True
>>> card1 > card2
False
>>> card1 == card2
False
>>> card1 != card3
False
>>> card1 < card3
False
>>> card1 > card3
False
>>> card1 == card3
True

>>> card4 = Card('4h')
>>> card5 = Card('d') # abstract diamonds card
>>> card6 = Card('h') # abstract hearts card
>>> card4 != card5
True
>>> card4 == card5
False
>>> card4 != card6
False
>>> card4 == card6
True
Deck()

Standard 52 cards deck.

There are 13 weights (Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King, Ace) and 4 suits (clubs, diamonds, hearts, spades).

>>> from agstuff.cards.core import Deck

>>> deck = Deck()
>>> deck
[
    2, 2, 2, 2,
    3, 3, 3, 3,
    4, 4, 4, 4,
    5, 5, 5, 5,
    6, 6, 6, 6,
    7, 7, 7, 7,
    8, 8, 8, 8,
    9, 9, 9, 9,
    T, T, T, T,
    J, J, J, J,
    Q, Q, Q, Q,
    K, K, K, K,
    A, A, A, A
]
>>> deck.size
52
>>> cards = deck.push_cards(3)
>>> cards # generator of 3 random cards
<generator object Deck.push_cards at 0x7f5b1d52e228>
>>> list(cards)
[6, 4, J]
>>> deck.size
49
>>> deck.refresh()
>>> deck.size
52
Cards(cards_string=None, cards=None, max_count=7)

Several cards.

Cards could be set from deck

>>> from agstuff.cards.core import Deck, Cards

>>> cards = Cards()
>>> cards.size
0
>>> cards
[]

>>> deck = Deck()
>>> deck.size
52
>>> cards.pull(deck, 3) # pull 3 random cards
>>> deck.size
49
>>> cards.size
3
>>> cards
[4, 5, 7]

>>> cards.pull(deck, 2) # add 2 more cards
>>> cards.size
5
>>> cards
[4, 5, 7, 9, J]

>>> cards.clean()
>>> cards.size
0
>>> cards
[]

Also cards could be set by cards string

>>> from agstuff.cards.core import Cards

>>> cards = Cards("2c/3c/4c/5c/6c")
>>> cards
[2, 3, 4, 5, 6]

Also cards could be set by iterable of Card instanses

>>> from agstuff.cards.core import Card, Cards

>>> cards = Cards(cards=[Card("Jd"), Card("2s"), Card("6c")])
>>> cards
[2, 6, J]

There is a possibility to find out whether the cards contain a card or not

>>> from agstuff.cards.core import Card, Cards

>>> card1 = Card("Qd")
>>> card2 = Card("8s")
>>> cards = Cards("Ad/Kd/Qd/Jd/Td")
>>> card1 in cards
True
>>> card2 in cards
False

By default Cards can contain no more than 52 items, and it could be changed

>>> from agstuff.cards.core import Deck, Cards

>>> cards1 = Cards(max_count=7)
>>> deck = Deck()
>>> cards1.pull(deck, 10)
>>> cards1
[5, 3, Q, J, J, 8, 9]

>>> cards2 = Cards("2s/3s/4s/5s/6s/7s/8s/9s/Ts/Js/Qs/Ks/As", max_count=5)
>>> cards2
[2, 3, 4, 5, 6]

Project details


Release history Release notifications

This version

1.0.0

Download files

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

Files for AGStuff, version 1.0.0
Filename, size File type Python version Upload date Hashes
Filename, size AGStuff-1.0.0-py3-none-any.whl (14.1 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size AGStuff-1.0.0.tar.gz (10.2 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page