-
Notifications
You must be signed in to change notification settings - Fork 1
/
cardParser.py
82 lines (47 loc) · 1.65 KB
/
cardParser.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
NUMBER = 0
SUIT = 1
CARDS_IN_HAND = 2
CARDS_IN_FLOP = 3
CARDS_IN_TURN = 1
numbers = ["2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A"]
suits = {
"C": "♣️",
"D": "♦️",
"H": "♥️",
"S": "♠️",
}
def parseCardsInHand(userInput):
cards = userInput.split()
if (not isCorrectNumberOfCards(CARDS_IN_HAND, cards)):
return "error"
firstHandCard = parseCardValue(cards[0])
secondHandCard = parseCardValue(cards[1])
if (firstHandCard == "error" or secondHandCard == "error"):
return "error"
return firstHandCard, secondHandCard
def parseCardsInFlop(userInput):
cards = userInput.split()
if (not isCorrectNumberOfCards(CARDS_IN_FLOP, cards)):
return "error"
firstFlopCard = parseCardValue(cards[0])
secondFlopCard = parseCardValue(cards[1])
thirdFlopCard = parseCardValue(cards[2])
if (firstFlopCard == "error" or secondFlopCard == "error" or thirdFlopCard == "error"):
return "error"
return firstFlopCard, secondFlopCard, thirdFlopCard
def parseCardsInTurn(userInput):
cards = userInput.split()
if (not isCorrectNumberOfCards(CARDS_IN_TURN, cards)):
return "error"
turnCard = parseCardValue(cards[0])
if (turnCard == "error"):
return "error"
return turnCard
def parseCardValue(card):
if (len(card) != 2):
return "error"
if (card[NUMBER] not in numbers or card[SUIT].upper() not in suits):
return "error"
return card[NUMBER] + suits[card[SUIT].upper()]
def isCorrectNumberOfCards(correctNumber, cards):
return len(cards) == correctNumber