| 3 | |
| 4 | |
| 5 | class Card: |
| 6 | suits = ["spades", "hearts", "diamonds", "clubs"] |
| 7 | |
| 8 | values = [ |
| 9 | None, |
| 10 | None, |
| 11 | "2", |
| 12 | "3", |
| 13 | "4", |
| 14 | "5", |
| 15 | "6", |
| 16 | "7", |
| 17 | "8", |
| 18 | "9", |
| 19 | "10", |
| 20 | "Jack", |
| 21 | "Queen", |
| 22 | "King", |
| 23 | "Ace", |
| 24 | ] |
| 25 | |
| 26 | def __init__(self, v, s): |
| 27 | """suit + value are ints""" |
| 28 | self.value = v |
| 29 | self.suit = s |
| 30 | |
| 31 | def __lt__(self, c2): |
| 32 | if self.value < c2.value: |
| 33 | return True |
| 34 | if self.value == c2.value: |
| 35 | if self.suit < c2.suit: |
| 36 | return True |
| 37 | else: |
| 38 | return False |
| 39 | return False |
| 40 | |
| 41 | def __gt__(self, c2): |
| 42 | if self.value > c2.value: |
| 43 | return True |
| 44 | if self.value == c2.value: |
| 45 | if self.suit > c2.suit: |
| 46 | return True |
| 47 | else: |
| 48 | return False |
| 49 | return False |
| 50 | |
| 51 | def __repr__(self): |
| 52 | v = self.values[self.value] + " of " + self.suits[self.suit] |
| 53 | return v |
| 54 | |
| 55 | |
| 56 | class Deck: |