-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcard.py
85 lines (72 loc) · 2.19 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
class Card:
def __init__(self, suit, value):
self.suit = suit
self.value = value
if value > 9:
self.pegging_value = 10
else:
self.pegging_value = value
# suits are 0-3
def get_suit_name(self):
if self.suit == 0:
return "hearts"
elif self.suit == 1:
return "clubs"
elif self.suit == 2:
return "diamonds"
elif self.suit == 3:
return "spades"
else:
raise Exception("card has undefined suit")
# suits are 0-3
def get_suit_symbol(self):
if self.suit == 0:
return "\♡"
elif self.suit == 1:
return "\♣"
elif self.suit == 2:
return "\♢"
elif self.suit == 3:
return "\♠"
else:
raise Exception("card has undefined suit")
# values are 1-13
def get_value_name(self):
if self.value == 1:
return "ace"
elif self.value < 11:
return str(self.value)
elif self.value == 11:
return "jack"
elif self.value == 12:
return "queen"
elif self.value == 13:
return "king"
else:
raise Exception("card has undefined value")
# values are 1-13
def get_value_symbol(self):
if self.value == 1:
return "A"
elif self.value < 11:
return str(self.value)
elif self.value == 11:
return "J"
elif self.value == 12:
return "Q"
elif self.value == 13:
return "K"
else:
raise Exception("card has undefined value")
def filename(self):
return self.get_value_name() + ' of ' + self.get_suit_name()
def __repr__(self):
return self.get_value_symbol() + self.get_suit_symbol()
def __lt__(self, other):
if self.value < other.value:
return True
def __eq__(self, o): return not self < o and not o < self
def __ne__(self, o): return self < o or o < self
def __gt__(self, o): return o < self
def __ge__(self, o): return not self < o
def __le__(self, o): return not o < self