We will be using number to represent a playing card suit and rank. These are the suits:
For example the suit at index 0:
The ranks are:
[None, 'A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']
For instance the rank at index 1 is (Note that the rank at index 0 is none, as we want to ranks to match the indices):
source
Card
Card (suit:int, rank:int)
A playing card
| suit |
int |
An index into suits |
| rank |
int |
An index into ranks |
Here is an example of creating and displaying a card
c = Card(suit=1, rank=3)
c
Comparison Operators
Equality, greater than, and less than
test_eq(Card(suit=1, rank=3), Card(suit=1, rank=3))
test_ne(Card(suit=2, rank=3), Card(suit=1, rank=3))
test_ne(Card(suit=1, rank=2), Card(suit=1, rank=3))
assert Card(suit=1, rank=3) > Card(suit=1, rank=2)
assert Card(suit=2, rank=3) > Card(suit=1, rank=3)
assert not Card(suit=1, rank=2) > Card(suit=1, rank=3)
assert Card(suit=1, rank=2) < Card(suit=1, rank=3)
assert Card(suit=1, rank=2) < Card(suit=2, rank=2)
assert not Card(suit=1, rank=3) < Card(suit=1, rank=2)