- Changes -- Will probably break things
- Major changes to the package/code.
- Features -- May or may not break things
- New, added features/functionality.
- Refactoring -- Shouldn't break things
- Changes/improvements to the code.
- Bugfixes -- Won't break things
- Smaller bugfixes, fixing broken functionality.
- Other -- Won't break things
- Any other changes that may be of note, such as updating/modifying of documentation.
- PyDealer is now under a GPLv3 license. I know I probably shouldn't be switching licenses suddenly, but the MIT license was just a little too open for my liking. I like open, but I also like to have my rights protected, and to make sure that PyDealer, or anything derived from it, remains open source, literally.
- Moved all constants, classes, utility functions into their own separate files, because they're easier to manage that way, instead of having everything in one large file.
card.py
contains theCard
class.const.py
contains the few constants used by PyDealer.deck.py
contains theDeck
class.stack.py
contains theStack
class.utils.py
contains all of the utility functions, which are used by the various methods/functions in the PyDealer package, but can also be used on their own as well though.
- Changed the
values
argument name, in the following helper functions, toranks
, because it makes more sense to me. check_sorted
sort_card_indices
sort_cards
- Changed the
- All of the sorting methods & functions now sort by
DEFAULT_RANKS
by default, instead ofPOKER_RANKS
.Deck
instances are also built using this order.
- The attribute name
Card.value
is nowCard.face
, because it makes more sense. - The
Card
comparison magic methods now usepydealer.const.DEFAULT_RANKS
instead ofpydealer.const.POKER_RANKS
for comparisons. If a user would rather use some other rank dict, they can use the newly added comparison functions described below, in the features section.
- Merged the constant
NUMBERS
withFACES
. There was no point in having them separate. - The
"values"
key inDEFAULT_RANKS
, andBIG2_RANKS
is now named"faces"
, to match the change of theCard
attribute name, described aboved, in the changes section. POKER_RANKS
now has a"faces"
key, to work with tweaked sorting functions.- Removed
BLACKJACK_VALS
, because it was pretty much useless, not being used for anything, and can be easily reproduced by anyone that needed it.
Deck.deal
now returns aStack
instance, instead of a list.Deck.deal
no longer accepts the argumentsrebuild
orshuffle
. They are nowDeck
attributes that you can set on instantiation. You may also change them any time afterwards as well.Deck.__init__
now recieves a single**kwargs
argument. The accepted arguments are still the same though. The only difference is that when providing cards on instantiation, you have to use the argumentcards=<cards>
, where<cards>
is a list of Card instances, or aStack
/Deck
instance.- Removed the argument
sort
fromDeck.__init__
, andDeck.build
, because decks are built sorted by default now.
Stack.deal
now returns aStack
instance, instead of a list.Stack.__init__
now recieves a single**kwargs
argument. The accepted arguments are still the same. The only difference is that when providing cards, you have to use the argumentcards=<cards>
, where<cards>
is a list of Card instances, orStack
/Deck
.- Changed the
Stack.__eq__
(andDeck.__eq__
) magic method, so that it doesn't compare instance type anymore, and so that it takes into account the ordering of the cards as well. This allows you to compare aStack
instance to aDeck
instance, and vice versa, or compare alist
ofCards
instances to aStack
/Deck
. - Removed the
__iter__
method. Was pointless.
- Added tests (98 of them). You can run all of the tests by running
test_suite.py
, in the "tests" folder. May try out nose for testing, and Travis CI at a later date. - Added documentation. It can be viewed at pydealer.readthedocs.org.
- Sorting now works with Jokers. They will always be at the bottom of the deck after sorting, when using any of the provided rank dicts.
- Added the comparison methods
Card.ge
,Card.gt
,Card.le
,Card.lt
,Card.eq
,andCard.ne
, in case a user wants more control over which rank dict is used forCard
rank/value comparisons. All of the functions accept the arguentranks
, which can beDEFAULT_RANKS
,POKER_RANKS
,BIG2_RANKS
, or any other rank dict matching the pattern of the included rank dicts. The default isDEFAULT_RANKS
.
- Added the constant
DEFAULT_RANKS
, which is the default sorting order for sorting methods & functions, and freshly builtDeck
instances. It is a combination ofPOKER_RANKS
andBIG2_RANKS
. The order ofDEFAULT_RANKS
, from least to greatest value, is 2 - 10, Jack, Queen, King, and Ace, for card faces, and Diamonds, Clubs, Hearts, and Spades for card suits. - Added the constants
TOP
andBOTTOM
, which are used by theend
argument inStack.deal
,Deck.deal
, andStack.add
, to respresent the top and bottom of aStack
orDeck
instance. They are just ints (0
, and1
respectively).
- Added the bool argument
rebuild
toDeck.__init__
, to set whether or not the deck will be rebuilt when all of the cards are dealt from it. - Added the attribute
Deck.rebuild
, to keep track of whether or not to rebuild. This way, you don't have to pass therebuild
argument toDeck.deal
. You can always turn rebuilding off withDeck.rebuild = False
(or on withDeck.rebuild = True
). It isFalse
by default.
- Added the attribute
- Added the bool argument
- Added the bool argument
re_shuffle
toDeck.__init__
, to set whether or not the deck will be shuffled when/if it's rebuilt. - Added the attribute
Deck.re_shuffle
, to keep track of whether or not to shuffle when rebuilding. This way, you don't have to pass therebuild
argument toDeck.deal
. You can always turn rebuild shuffling off withDeck.re_shuffle = False
(or on withDeck.re_shuffle = True
). It isFalse
by default.
- Added the attribute
- Added the bool argument
- Added the attribute
Deck.jokers
, which keeps track of whether the deck was built with jokers. - Added the attribute
Deck.num_jokers
which keeps track of how many jokers the deck was built with. - Added the function
convert
, which will take a givenStack
instance and return a newDeck
instance, with the same cards. - Added the argument
end
toDeck.deal
. It allows you to specify which end of the Deck to deal from (top or bottom). It accepts either0
(top) or1
(bottom). - You can now add a list of
Card
instances, or aStack
/Deck
instance to aDeck
instance, using the+
operand (or+=
).
- Added a
Stack
class, to represent a generic "card container", used to hold and work with cards (could be used as a hand, or a discard pile, etc.). It is essentially the oldDeck
class, with a new name, and a number of new methods. TheDeck
class is now just a subclass ofStack
, with a few extra methods, particular to decks. - All methods available to the
Stack
class are also available to theDeck
class as well.
- All methods available to the
- Added a
- Added the method
Stack.add
, to add given card(s) to the stack. - Has one argument,
end
, which can be either0
(top) or1
(bottom).end
determines which end of theStack
the card(s) get added to.
- Has one argument,
- Added the method
- Added the method
Stack.sort
, to sort a stack in place. - Added the method
Stack.split
, for splitting a stack in half, or at a given indice, and returning the two halves, as separateStack
instances. - Added the method
Stack.reverse
, which reverses the stack in place. - Added the method
Stack.save_cards
, for saving the cards in a stack, in plain text format in a txt file. Card order is maintained. - Added the method
Stack.open_cards
, for opening the cards in plain text files of cards generated byStack.save_cards
orpydealer.utils.save_cards
. Card order is maintained. - Added the method
Stack.empty
, which removes all cards from the stack and returns them as a list. - Has one argument,
return_cards
, which accepts a bool value, and determines whether or not the cards are returned.
- Has one argument,
- Added the method
- Added the method
Stack.random_card
for getting a random card from the stack. - Has one argument,
remove
, which accepts a bool value, and determines whether or not to remove the random card from theStack
.
- Has one argument,
- Added the method
- Added the method
Stack.insert
, for inserting a card into the stack at a given indice. - Added the method
Stack.insert_list
, for inserting a list of cards into a stack, at the given indice. - Added the method
Stack.count
, for counting the number of a card that matches a given term. - Added the method
Stack.count_list
, for counting the number of cards that match a given list of terms. - Added the argument
end
toStack.deal
. It allows a user to specify which end of the stack to deal from (top or bottom). It accepts either0
(top) or1
(bottom). - Added the argument
limit
toStack.find
,Stack.find_list
,Stack.get
andStack.get_list
. It lets a user specify a limit on how many items to retrieve for each term. For example, if you usedStack.get_list(["A", "2"], limit=1)
thenStack.get_list
would return only the first Ace, and first 2 that it found, instead of all 4 Aces and all 4 2s.Stack.get_list(["A", "2"], limit=2)
would return the first and second Ace and 2 that it found, etc. - Added the function
convert
, which will take a givenDeck
instance and return a newStack
instance, with the same cards. - Added
Stack.__ne__
, so that!=
comparisons should work properly now. - Fleshed out
Stack.__getitem__
, soStack
andDeck
instances cards can now be accessed, sliced, or reversed like lists, like you might expect. - Added the attribute
Stack.ranks
, which allows you to set the rank dict to use for sorting methods, etc. You can set it on instantiation using the argumentranks=<rank_dict>
, or any time afterwards usingStack.ranks = <rank_dict>
, where<rank_dict>
is the rank dict to use. - You can now add a list of
Card
instances, or aStack
/Deck
instance to aStack
instance, using the+
operand (or+=
).
- Moved the function
check_term
topydealer.utils
. - Moved the function
compare_stacks
topydealer.utils
. - Moved the function
sort_card_indices
topydealer.utils
. - Moved the function
sort_cards
topydealer.utils
. - Added the function
build_cards
that builds and returns a list containing a full deck ofCard
instances (a French deck of 52 cards). I basically moved the meat ofDeck.build
out of that method, and into a separate helper function.Deck.build
now callsbuild_cards
. I did this so that users can use the card building function as a standalone function, if they wish. - Added the function
check_sorted
to check whether the given cards (aStack
,Deck
, or list ofCard
instances) are sorted (by default ranks, poker ranks or big two ranks). - Added the function
find_card
, for finding a card with the given term, in the givenStack
,Deck
, or list of cards. - Added the function
find_list
, for finding cards with the given list of terms, in the givenStack
,Deck
, or list of cards. - Added the function
get_card
, for getting, and removing a card with the given term, from the givenStack
,Deck
, or list of cards. - Added the function
get_list
, for getting, and removing cards with the given list of terms, from the givenStack
,Deck
, or list of cards. - Added the function
open_cards
for opening a plain txt list of cards, generated bysave_cards
orStack.save_cards
. - Added the function
random_card
, which will return a random card from a givenStack
instance,Deck
instance, orlist
ofCard
instances. - Added the function
save_cards
for saving a hand, deck, or list of cards in plain text, to a txt file. Card order is maintained.
- All modules now use absolute imports.
__init__.py
imports all of the classes, for easier, more convenient access. Users can import any class usingfrom pydealer import <class>
, orimport pydealer.<class>
, instead offrom pydealer.<module> import <class>
, orimport pydealer.<module>.<class>
. Users may still do it the longer way though, if that is prefered. Actually, the longer ways are probably the more "proper" ways to do it. Utility functions can be imported usingfrom pydealer.utils import <function>
orimport pydealer.utils.<function>
.
- The
Deck
class is now just a subclass of theStack
class, with a few extra methods.
- Tweaked
Stack.get
, andStack.get_list
. - Changed
Stack.get
andStack.get_list
so that they don't rely ondeque.remove
to remove cards from the deck, which was relatively slow. They now just make a new copy of the cards in the deck, minus the gotten cards, using list comprehensions, and assign it toself.cards
. - Did away with a slow
for
loop inStack.get_list
. The loop made repeated calls (once for each term) toStack.find
, and repeated addition to a list. Now makes one call toStack.find_list
, and one list assignment. Now takes about 1/3rd the time.
- Changed
- Tweaked
- Added the property
Stack.cards
that, when assigning cards toStack.cards
directly, converts the given list ofCard
instances, or cards in aStack
/Deck
to a deque first.
- Did away with all of the rank dict checks in
sort_card_indices
andsort_cards
. Should be slightly faster, and more generic now, meaning a user can feed in his own dictionary, as long as it follows the pattern of the included rank dicts. sort_card_indices
andsort_cards
are now a little more flexible, and can sort by just suit now as well, if provided with a rank dict that only has suit ranks, instead of only being able to sort by either face or face & suit, .
- Fixed the comparison magic methods in
Card
, so they now work properly in Python 3. - Fixed a bug in the
Card.__eq__
magic method (changed anand
to anor
). - Fixed
card_abbrev
so that it properly abbreviates 10s now.
- Fixed the division in
Stack.split
. It now uses floor division (//
), so it works with Python 3.
- Tried to clarify a few docstrings.
- Got rid of all trailing/extra spaces.
- Fixed up the readme a bit.
- Added syntax highlighting to the examples.
- Added missing argument descriptions to the docstrings of
sort_card_indices
andsort_cards
.
- Added a couple of extra arguments to
Deck.__init__
. Deck.__init__
now takes a list of cards as the first argument,cards
, so you can instantiate a deck with a given list of cards.- You can now prevent a
Deck
from building itself automatically, on instantiation, with the bool argumentbuild
. Ifbuild=False
, theDeck
skips building.
- Added a couple of extra arguments to
Deck.find
, andDeck.get
no longer accept lists of terms, and only accept a single term. I have made separate methods for finding/getting lists of terms (see the features section below).- These methods also only return lists (empty or otherwise) now.
- Scrapped
Deck.peek
, because it was pretty much useless. - The abbreviation for jokers is now "JKR", instead of "JK".
- PyDealer is now hosted on the PyPi! Installing just got that much easier.
Deck``s now store their ``Cards
in a deque, instead of a list.- Added
Deck.find_list
, andDeck.get_list
, for retrieving items matching the terms in a given list. - Added a
sort
kwarg toDeck
,Deck.build
,Deck.find
,Deck.find_list
,Deck.get
andDeck.get_list
. sort
is a boolean argument, which, ifTrue
, will sort the newly builtDeck
, or results by poker rank, otherwise they are built/returned in the order they are created/found. Default isFalse
.
- Added a
- Added the global function
compare_decks
, for checking whether twoDeck
instances have the same cards (Card
suits & values, notCard
instances). - Added the global functions
sort_cards
, andsort_card_indices
, for sorting given cards, or deck indices by poker ranks. - Added the method
Deck.set_cards
, to set aDeck
's contents to a given list of cards at any time. You could just doDeck.cards = deque([Card, Card, ...])
as well. This method just handles the extra step of converting a list to a deque. Deck.shuffle()
now takes the argumenttimes
, which is the number of times to shuffle.
- Changed
Deck.cards
to a deque, instead of a list. - Tweaked the item retrieval methods
Deck.find
, andDeck.find_list
, so that they useenumerate
in their loops now, instead of getting card indexes usingself.cards.index(card)
. - Changed the ordering of the items in
FACES
, andSUITS
, so thatDeck
instances are sorted by big two ranks by default, when built.
- Fixed
check_term
again. Should actually work with 10s now. Really. - Added a dirty little try/except fix for the
xrange
function, because it doesn't exist in Python 3. Ifxrange
can't be found, implying the package is being run under Python 3, then Python 3'srange
is assigned to the variablexrange
, usingxrange = range
. - Changed
Deck.find
, so that it doesn't return lists with duplicates.
- Tweaked the function/method docstrings a bit, to try to make them easier to read.
- Updated the readme.
- Tweaked the section key at the top of the changelog slightly.
- Fixed
check_term
, so that it works with Python 3.
- Filled out the docstring for
Deck.__init__
. - Filled out the docstring for
Card.__init__
. - Fixed a few little errors in the readme.
- Fixed the methods
Deck.find
,Deck.get
, andDeck.peek
, so they don't throw an error when there is nothing to return. They now returnNone
if nothing is found.
- Changed
__init__.py
, so it now imports everything from the module, meaning you can now access the globals constants, andcheck_term
, when importing PyDealer. - Stripped the extra "n" at the end of the str representation of a
Deck
.
- Moved the constants
Deck.SUITS
,Deck.FACES
, andDeck.NUMBERS
out ofDeck
and into the global scope. They can now be accessed usingSUITS
,FACES
, andNUMBERS
. - Moved
Deck.check_term
out ofDeck
, and into the global scope. It can now be accessed by callingcheck_term
.
- Added some magic methods to the
Card
, andDeck
objects. - Added to
Card
: __eq__
__gt__
__hash__
__repr__
__str__
- Added to
- Added to
Deck
: __add__
__contains__
__delitem__
__eq__
__getitem__
__iter__
__len__
__repr__
__setitem__
__str__
- Added to
- Added some magic methods to the
- Added a few global constants, for use with some common card games:
POKER_RANKS
, which is a dict of poker ranks.- This is also used by
Card.__gt__
.
- This is also used by
BIG2_RANKS
, which is a dict of ranks for the game Big Two (Deuces).BLACKJACK_VALS
, which is a dict of card values for Black Jack (Twenty One).
Deck.peek
, in addition to accepting a single deck indice for an argument, can now accept a list of deck indices as well.Deck.get
, in addition to accepting card names/values/suits/abbrevs. as an argument, can now accept deck indices as well.
- Refactored most of the methods in
Deck
. - Refactored
Deck.deal
. - Refactored
Deck.find
. - Refactored
Deck.get
.
- Refactored
- Refactored most of the methods in
- Refactored the methods in
Card
. - Refactored
Card.gen_abbrev
. - Refactored
Card.gen_name
.
- Refactored
- Refactored the methods in
- Refactored
check_term
- Fixed
Card.gen_abbrev
, so it now properly abbreviates 10s.
- Added argument & return value descriptions to the method & function docstrings.
- Reformatted the changelog,
CHANGES.rst
.
- Pydealer is now a proper package, that can be installed/uninstalled using PIP.
- No longer have to call
Deck.build_deck
after instantiating a deck. It it done on initialization now. - Shortened a few method names.
Deck.build_deck
is nowDeck.build
.Deck.find_cards
is nowDeck.find
.Deck.get_cards
is nowDeck.get
.
- Decks can now be built with jokers.
- This can be done by passing the argument
jokers=True
toDeck
, when instantiating: - deck = pydealer.Deck(jokers=True)
- This can be done by passing the argument
- Negligibly optimized a few methods, by replacing some simple loops with list comprehensions.
- Fixed up the readme. Added simple usage examples.
- Fixed up the changelog,
CHANGES.rst
.
- Initial release.