-
Notifications
You must be signed in to change notification settings - Fork 16
/
Card.py
115 lines (84 loc) · 2.18 KB
/
Card.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
class Card:
def __init__(self, rank, suit):
self.rank = Rank(rank)
self.suit = Suit(suit)
def __lt__(self, other):
return (self.rank < other.rank or (self.rank == other.rank and self.suit < other.suit))
def __ge__(self, other):
return not (self < other)
def __gt__(self, other):
return (self.rank > other.rank or (self.rank == other.rank and self.suit > other.suit))
def __le__(self, other):
return not (self > other)
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
def __ne__(self, other):
return not (self == other)
def rank(self):
return self.rank
def suit(self):
return self.suit
def __str__(self):
return self.rank.__str__() + self.suit.__str__()
'''
Suit identification (iden)
0: clubs
1: diamonds
2: spades
3: hearts
The suit that leads is trump, aces are high
'''
class Suit:
def __init__(self, iden):
self.iden = iden
self.string = ''
suits = ["c", "d", "s", "h"]
if iden == -1:
self.string = "Unset"
elif iden <= 3:
self.string = suits[iden]
else:
print 'Invalid card identifier'
def __eq__(self, other):
return self.iden == other.iden
def __ne__(self, other):
return not (self == other)
def __lt__(self, other):
return self.iden < other.iden
def __gt__(self, other):
return self.iden > other.iden
def __ge__(self, other):
return not (self < other)
def __le__(self, other):
return not (self > other)
def __str__(self):
return self.string
'''
Ranks indicated by numbers 2-14, 2-Ace
Where ace is high and two is low
'''
class Rank:
def __init__(self, rank):
self.rank = rank
self.string = ''
strings = ["J", "Q", "K", "A"]
if rank >= 2 and rank <= 10:
self.string = str(rank)
elif rank > 10 and rank <= 14:
self.string = strings[rank - 11]
else:
print 'Invalid rank identifier'
def __lt__(self, other):
return self.rank < other.rank
def __ge__(self, other):
return not (self < other)
def __gt__(self, other):
return self.rank > other.rank
def __le__(self, other):
return not (self > other)
def __eq__(self, other):
return self.rank == other.rank
def __ne__(self, other):
return not (self == other)
def __str__(self):
return self.string