Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import collections
- def bubbleSort(arr):
- isSorted = False
- while not(isSorted):
- for i in range(len(arr) - 1):
- for j in range(len(arr) - 1 - i):
- if arr[j] > arr[j+1]:
- arr[j], arr[j+1] = arr[j+1],arr[j]
- else:
- isSorted = True
- def Occur(cards):
- scorelist = [2,4,8]
- counter = collections.Counter(cards)
- largest = [0,0]
- largest2 = [0,0]
- for key in counter:
- occur = counter[key]
- if occur > largest2[1]:
- if occur > largest[1]:
- largest2 = largest
- largest = [key,occur]
- else:
- largest2 = [key,occur]
- num = max([largest[0],largest2[0]])
- if largest[1] == 3 and largest2[1] == 2:
- return(7,largest[0])
- elif largest[1] == largest2[1]:
- return(3,num)
- elif largest[1] in [2,3,4]:
- return(scorelist[[2,3,4].index(largest[1])],num )
- return(1,num)
- def Flush(cards):
- counter = collections.Counter(cards)
- if len(counter) == 1:
- return(True,max(cards))
- return(False,max(cards))
- def Straight(cards):
- if cards[4] - cards[0] == 4:
- return(True,max(cards))
- return(False,max(cards))
- def Royal(cards):
- royal = [0,9,10,11,12]
- if cards == royal:
- return(True,13)
- return(False,13)
- def getScore(hand):
- suit = bubbleSort([i[1] for i in hand])
- value = bubbleSort([i[0] for i in hand])
- occurances = Occur(value)
- if occurances == 2:
- if Flush(suit) == 5:
- if Straight(value):
- return(9)
- if Royal(value):
- return(10)
- return(6)
- if Straight(value):
- return(5)
- return(1)
- return(occurances)
- class Deck: #!
- def __init__(self,numsuit,numcard):
- self.numsuit = numsuit
- self.numcard = numcard
- self.deck = [[True] * numsuit for i in range (numcard)]
- def createCard(self): #!
- if self.deck.count:
- suitval = random.randint(0,self.numsuit-1)
- cardval = random.randint(0,self.numcard-1)
- while self.deck[cardval][suitval] == False:
- suitval = random.randint(0,self.numsuit-1)
- cardval = random.randint(0,self.numcard-1)
- self.deck[cardval][suitval] = False
- return((cardval,suitval))
- def createHand(self,handSize):
- cards = []
- for i in range(handSize):
- card = Deck.createCard(self)
- cards.append(card)
- return(cards)
- def changeHand(self,hand,indexList):
- for i in range(len(indexList)):
- hand[indexList[i]] = self.deck.createCard(self)
- return(hand)
- theDeck = Deck(4,13)
- hand1 = theDeck.createHand(5)
- print(getScore(hand1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement