PyBaccarat: pybaccarat.playingcards.Card Class Reference

PyBaccarat visit the ministry of silly walks

Public Member Functions | Public Attributes | List of all members
pybaccarat.playingcards.Card Class Reference

The Card class represents a single playing card. More...

Inheritance diagram for pybaccarat.playingcards.Card:

## Public Member Functions
def | __init__ (self, new_ordinal, new_suit=None)
| Create a new playing card. More...
def | get_rank (self)
| Return the rank of this card. More...
def | get_suit (self)
| Return the suit of this card. More...
def | get_ordinal (self)
| Return the ordinal value. More...
def | __str__ (self)
| Return the string representation for this card. More...
def | __eq__ (self, other)
| Returns the result of equals (==) between this Card and other Card. More...
def | __ne__ (self, other)
| Returns the result of not equals (!=) between this Card and other Card. More...
def | __lt__ (self, other)
| Less than method. More...
def | __le__ (self, other)
| Less or equal than method. More...
def | __gt__ (self, other)
| Greater than method. More...
def | __ge__ (self, other)
| Greater than or equal method. More...
def | __hash__ (self)
| Override the default hash behavior (that returns the id of the object). More...
def | __init__ (self, new_ordinal, new_suit=None)
| Create a new playing card. More...
def | get_rank (self)
| Return the rank of this card. More...
def | get_suit (self)
| Return the suit of this card. More...
def | get_ordinal (self)
| Return the ordinal value. More...
def | __str__ (self)
| Return the string representation for this card. More...
def | __eq__ (self, other)
| Returns the result of equals (==) between this Card and other Card. More...
def | __ne__ (self, other)
| Returns the result of not equals (!=) between this Card and other Card. More...
def | __lt__ (self, other)
| Less than method. More...
def | __le__ (self, other)
| Less or equal than method. More...
def | __gt__ (self, other)
| Greater than method. More...
def | __ge__ (self, other)
| Greater than or equal method. More...
def | __hash__ (self)
| Override the default hash behavior (that returns the id of the object). More...

## Public Attributes
| face_up

## Detailed Description

The Card class represents a single playing card.

It is immutable. That is, once created this Card can not be changed. This Card is a general purpose playing card that can be use by many different games.

Example usage:

import baccarat.playingcards
#create a five of spades
card5s = baccarat.playingcards.Card(43) #(5, 's')
#print this card
print(card5s) #displays '5s'

See also
  Shoe

It is immutable. That is, once created this Card can not be changed. This Card is a general purpose playing card that can be use by many different games.

Example usage:

import pybaccarat.playingcards
#create a five of spades
card5s = pybaccarat.playingcards.Card(43) #(5, 's')
#print this card
print(card5s) #displays '5s'

See also
  Shoe

## Constructor & Destructor Documentation

## ◆ __init__() [1/2]

def pybaccarat.playingcards.Card.__init__ | ( |  | self,
|  |  | new_ordinal,
|  |  | new_suit = `None`
| ) |  |

Create a new playing card.

There are 3 syntaxes that can be used to create this new card. First, a single integer in the range 0 to 51. Where each integer maps to a particular rank and suit. The second syntax is to supply a rank and suit. Third, a string naming of the rank and suit.

Example usage:

import baccarat.playingcards
#create a five of spades
card5s = baccarat.playingcards.Card(43) #(5, 's')
#create a jack of diamods
cardJh = baccarat.playingcards.Card(11, 'd')
#create an ace of clubs
cardAs = baccarat.playingcards.Card("Ac")

The first syntax is a single integer value 0 to 51. This would likely be used by a program that wants to create an array of cards quickly. Such as a complete deck of cards. To create a complete deck of cards use the following code.

import baccarat.playingcards
deck = []
for c in range(52):
deck.append(Card(c))

The second syntax would be the case of creating a single specific playing card. This would likely be a rare useage. But, it is available in case a single card is wanted. The syntax would be 2 arguments: rank and suit. The rank is an integer in the range 1 to 13. The suit is a single string character.

The third syntax is similar to the second, only using the string representation of the Card. This is the same syntax used to write a Card object with the str() method.

Parameters

  self | this object pointer reference
  new_ordinal | integer value 0 to 51 inclusive. If 2 arguements are given for the creation of a card the integer value will be the rank in the range 1 to 13. Or a string representation of the Card value.
  new_suit | Used only when 2 arguments are given for creating a new card. The single string character will represent the suit. Accepted values are 's', 'h', 'd', or 'c'.

Exceptions

  ValueError | If the input parameter is not valid this exception will be raised.

An example of an exception is:

import baccarat.playingcards
c = baccarat.playingcards.Card(66)
ValueError: new_ordinal(66) not in legal range 0..51

## ◆ __init__() [2/2]

def pybaccarat.playingcards.Card.__init__ | ( |  | self,
|  |  | new_ordinal,
|  |  | new_suit = `None`
| ) |  |

Create a new playing card.

There are 3 syntaxes that can be used to create this new card. First, a single integer in the range 0 to 51. Where each integer maps to a particular rank and suit. The second syntax is to supply a rank and suit. Third, a string naming of the rank and suit.

Example usage:

import pybaccarat.playingcards
#create a five of spades
card5s = pybaccarat.playingcards.Card(43) #(5, 's')
#create a jack of diamods
cardJh = pybaccarat.playingcards.Card(11, 'd')
#create an ace of clubs
cardAs = pybaccarat.playingcards.Card("Ac")

The first syntax is a single integer value 0 to 51. This would likely be used by a program that wants to create an array of cards quickly. Such as a complete deck of cards. To create a complete deck of cards use the following code.

import pybaccarat.playingcards
deck = []
for c in range(52):
deck.append(Card(c))

The second syntax would be the case of creating a single specific playing card. This would likely be a rare useage. But, it is available in case a single card is wanted. The syntax would be 2 arguments: rank and suit. The rank is an integer in the range 1 to 13. The suit is a single string character.

The third syntax is similar to the second, only using the string representation of the Card. This is the same syntax used to write a Card object with the str() method.

Parameters

  self | this object pointer reference
  new_ordinal | integer value 0 to 51 inclusive. If 2 arguements are given for the creation of a card the integer value will be the rank in the range 1 to 13. Or a string representation of the Card value.
  new_suit | Used only when 2 arguments are given for creating a new card. The single string character will represent the suit. Accepted values are 's', 'h', 'd', or 'c'.

Exceptions

  ValueError | If the input parameter is not valid this exception will be raised.

An example of an exception is:

import pybaccarat.playingcards
c = pybaccarat.playingcards.Card(66)
ValueError: new_ordinal(66) not in legal range 0..51

## Member Function Documentation

## ◆ __eq__() [1/2]

def pybaccarat.playingcards.Card.__eq__ | ( |  | self,
|  |  | other
| ) |  |

Returns the result of equals (==) between this Card and other Card.

Overwrites the default object class behavior. The default object class compares instanciated Card's addresses. Thus two cards with the same rank and suit will not be equal. This method will cause two cards of the same rank and suit to be considered equal.

Example usage:

import pybaccarat.playingcards
#create a five of spades
first = pybaccarat.playingcards.Card(43) #(5, 's')
#create a second five of spades
second = pybaccarat.playingcards.Card(43) #(5, 's')
#test if they are equal
if first == second:
print("they are equal")
#print the message

Parameters

  self | this object pointer reference
  other | object A second Card to compare with

Returns
  True is this Card equals other Card rank and suit, otherwise False. If other is not of Card class type then it will be passed to the object class, which will return False.

## ◆ __eq__() [2/2]

def pybaccarat.playingcards.Card.__eq__ | ( |  | self,
|  |  | other
| ) |  |

Returns the result of equals (==) between this Card and other Card.

Overwrites the default object class behavior. The default object class compares instanciated Card's addresses. Thus two cards with the same rank and suit will not be equal. This method will cause two cards of the same rank and suit to be considered equal.

Example usage:

import baccarat.playingcards
#create a five of spades
first = baccarat.playingcards.Card(43) #(5, 's')
#create a second five of spades
second = baccarat.playingcards.Card(43) #(5, 's')
#test if they are equal
if first == second:
print("they are equal")
#print the message

Parameters

  self | this object pointer reference
  other | object A second Card to compare with

Returns
  True is this Card equals other Card rank and suit, otherwise False. If other is not of Card class type then it will be passed to the object class, which will return False.

## ◆ __ge__() [1/2]

def pybaccarat.playingcards.Card.__ge__ | ( |  | self,
|  |  | other
| ) |  |

Greater than or equal method.

Greater than or equal does not have meaning for a general purpose playing card, so it is disabled.

Parameters

  self | this object pointer reference
  other | object A second Card to compare with

Exceptions

  NotImplmentedError |

## ◆ __ge__() [2/2]

def pybaccarat.playingcards.Card.__ge__ | ( |  | self,
|  |  | other
| ) |  |

Greater than or equal method.

Greater than or equal does not have meaning for a general purpose playing card, so it is disabled.

Parameters

  self | this object pointer reference
  other | object A second Card to compare with

Exceptions

  NotImplmentedError |

## ◆ __gt__() [1/2]

def pybaccarat.playingcards.Card.__gt__ | ( |  | self,
|  |  | other
| ) |  |

Greater than method.

Greater than does not have meaning for a general purpose playing card, so it is disabled.

Parameters

  self | this object pointer reference
  other | object A second Card to compare with

Exceptions

  NotImplmentedError |

## ◆ __gt__() [2/2]

def pybaccarat.playingcards.Card.__gt__ | ( |  | self,
|  |  | other
| ) |  |

Greater than method.

Greater than does not have meaning for a general purpose playing card, so it is disabled.

Parameters

  self | this object pointer reference
  other | object A second Card to compare with

Exceptions

  NotImplmentedError |

## ◆ __hash__() [1/2]

def pybaccarat.playingcards.Card.__hash__ | ( |  | self | ) |

Override the default hash behavior (that returns the id of the object).

The new hash will be the two saved values that define which card this class represents.

Parameters

  self | this object pointer reference

Returns
  hash code

## ◆ __hash__() [2/2]

def pybaccarat.playingcards.Card.__hash__ | ( |  | self | ) |

Override the default hash behavior (that returns the id of the object).

The new hash will be the two saved values that define which card this class represents.

Parameters

  self | this object pointer reference

Returns
  hash code

## ◆ __le__() [1/2]

def pybaccarat.playingcards.Card.__le__ | ( |  | self,
|  |  | other
| ) |  |

Less or equal than method.

Less than or equal does not have meaning for a general purpose playing card, so it is disabled.

Parameters

  self | this object pointer reference
  other | object A second Card to compare with

Exceptions

  NotImplmentedError |

## ◆ __le__() [2/2]

def pybaccarat.playingcards.Card.__le__ | ( |  | self,
|  |  | other
| ) |  |

Less or equal than method.

Less than or equal does not have meaning for a general purpose playing card, so it is disabled.

Parameters

  self | this object pointer reference
  other | object A second Card to compare with

Exceptions

  NotImplmentedError |

## ◆ __lt__() [1/2]

def pybaccarat.playingcards.Card.__lt__ | ( |  | self,
|  |  | other
| ) |  |

Less than method.

Less than does not have meaning for a general purpose playing card, so it is disabled.

Parameters

  self | this object pointer reference
  other | object A second Card to compare with

Exceptions

  NotImplmentedError |

## ◆ __lt__() [2/2]

def pybaccarat.playingcards.Card.__lt__ | ( |  | self,
|  |  | other
| ) |  |

Less than method.

Less than does not have meaning for a general purpose playing card, so it is disabled.

Parameters

  self | this object pointer reference
  other | object A second Card to compare with

Exceptions

  NotImplmentedError |

## ◆ __ne__() [1/2]

def pybaccarat.playingcards.Card.__ne__ | ( |  | self,
|  |  | other
| ) |  |

Returns the result of not equals (!=) between this Card and other Card.

Overwrites the default object class behavior. The default object class compares instanciated Card's addresses. Thus two cards with the same rank and suit will not be equal. I want two cards of the same rank and suit will be equal.

Parameters

  self | this object pointer reference
  other | object A second Card to compare with

Returns
  True if this Card not equal to other Card, otherwise False. If other is not of Card class type then passed to the object class, which will return True.

## ◆ __ne__() [2/2]

def pybaccarat.playingcards.Card.__ne__ | ( |  | self,
|  |  | other
| ) |  |

Returns the result of not equals (!=) between this Card and other Card.

Overwrites the default object class behavior. The default object class compares instanciated Card's addresses. Thus two cards with the same rank and suit will not be equal. I want two cards of the same rank and suit will be equal.

Parameters

  self | this object pointer reference
  other | object A second Card to compare with

Returns
  True if this Card not equal to other Card, otherwise False. If other is not of Card class type then passed to the object class, which will return True.

## ◆ __str__() [1/2]

def pybaccarat.playingcards.Card.__str__ | ( |  | self | ) |

Return the string representation for this card.

This method overwrites the object class method of this same name.

Example usage:

card5s = Card(43) #(5, 's')
print(card5s) #displays '5s'

Parameters

  self | this object pointer reference

Returns
  2 character long string; rank and suit.

## ◆ __str__() [2/2]

def pybaccarat.playingcards.Card.__str__ | ( |  | self | ) |

Return the string representation for this card.

This method overwrites the object class method of this same name.

Example usage:

card5s = Card(43) #(5, 's')
print(card5s) #displays '5s'

Parameters

  self | this object pointer reference

Returns
  2 character long string; rank and suit.

## ◆ get_ordinal() [1/2]

def pybaccarat.playingcards.Card.get_ordinal | ( |  | self | ) |

Return the ordinal value.

The ordinal value is computed as a single integer value for each of the 52 cards.

Parameters

  self | this object pointer reference

Returns
  integer 0..51

## ◆ get_ordinal() [2/2]

def pybaccarat.playingcards.Card.get_ordinal | ( |  | self | ) |

Return the ordinal value.

The ordinal value is computed as a single integer value for each of the 52 cards.

Parameters

  self | this object pointer reference

Returns
  integer 0..51

## ◆ get_rank() [1/2]

def pybaccarat.playingcards.Card.get_rank | ( |  | self | ) |

Return the rank of this card.

Parameters

  self | this object pointer reference

Returns
  integer 1..13

  1 | ace
  2 to 10 | are numbered cards 2 to 10
  11 | jack
  12 | queen
  13 | king

## ◆ get_rank() [2/2]

def pybaccarat.playingcards.Card.get_rank | ( |  | self | ) |

Return the rank of this card.

Parameters

  self | this object pointer reference

Returns
  integer 1..13

  1 | ace
  2 to 10 | are numbered cards 2 to 10
  11 | jack
  12 | queen
  13 | king

## ◆ get_suit() [1/2]

def pybaccarat.playingcards.Card.get_suit | ( |  | self | ) |

Return the suit of this card.

Parameters

  self | this object pointer reference

Returns
  single lower case character

  'c' | clubs
  'd' | diamonds
  'h' | hearts
  's' | spades

## ◆ get_suit() [2/2]

def pybaccarat.playingcards.Card.get_suit | ( |  | self | ) |

Return the suit of this card.

Parameters

  self | this object pointer reference

Returns
  single lower case character

  'c' | clubs
  'd' | diamonds
  'h' | hearts
  's' | spades

The documentation for this class was generated from the following file:

- build/lib/pybaccarat/playingcards.py