-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhand_class.py
90 lines (50 loc) · 1.87 KB
/
hand_class.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Feb 17 18:41:37 2021
@author: robertblack
"""
from random import randint
class Hand:
def __init__(self):
self.__m_cards = []
def getNumberOfCardsLeft(self):
return len(self.__m_cards)
def addCard(self, card):
self.__m_cards.append(card)
def getCards(self):
return self.__m_cards
def dicardCard(self, index):
card = None
if len(self.__m_cards) > 0:
index -= 1
card = self.__m_cards[index]
del self.__m_cards[index]
return card
def dicardRandomCard(self):
card = None
if len(self.__m_cards) > 0:
randCardNum = randint(0, len(self.__m_cards) -1)
card = self.__m_cards[randCardNum]
del self.__m_cards[randCardNum]
return card
def checkFourCardSameValue(self):
retVal = False
sameValue = 0
for x in range(len(self.__m_cards)):
card_1 = self.__m_cards[x]
for i in range(len(self.__m_cards)):
card_2 = self.__m_cards[i]
if card_1.isSameType(card_2):
sameValue += 1
if sameValue >= 4:
retVal = True
break
sameValue = 0
return retVal
def __str__(self):
cardsStr = ""
for card in self.__m_cards:
cardsStr += str(card)
cardsStr += "\n"
return cardsStr