Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import collections
- import random
- 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
- return (arr)
- 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)
- def setup():
- global restart_text,pause_text,throw_text,score_text,menuboxes,gameboxes,pokertable,pokertitle,start_text,whichmenu
- global bankamount,betamount,negatory_text,pository_text,amount_text,bet_text,check_text,fold_text,call_text,raise_text,balance_text
- global handsize,numberofplayers,backofcard,drawtwocards_text,deckimage,hand1,cardl,cardw,hand2,thedeck
- cardw = 80
- cardl = 110
- size(1000,650)
- #This is the amount of money each user wants to bet
- betamount = 0
- #Amount of money in bank
- bankamount = 100
- pokertable = loadImage("poker.jpg")
- pokertitle = loadImage("PokerTitle.png")
- backofcard = loadImage("backofcard.jpg")
- deckimage = loadImage("deck.png")
- start_text = [450,310,100,50,"START",color(255,99,71)]
- bet_text = [780,100,200,50,"Bet",color(0,0,0)]
- negatory_text = [780,150,50,50,"-",color(50,50,50)]
- pository_text = [930,150,50,50,"+",color(50,50,50)]
- amount_text = [820,150,110,50,"$"+str(betamount),color(0,200,0)]
- check_text = [780,200,200,50,"check",color(139, 0, 255)]
- fold_text = [780,250,200,50,"fold",color(255, 0, 0)]
- call_text = [780,300,200,50,"call",color(255, 255, 0)]
- raise_text = [780,350,200,50,"raise",color( 255, 127, 0)]
- drawtwocards_text = [780,400,200,50,"change cards",color(0,0,0)]
- balance_text = [100,70,200,50,"balance:$"+str(bankamount),color(249,123,31)]
- whichmenu = 1
- menuboxes = [start_text]
- handsize = 5
- numberofplayers =2
- thedeck = Deck(4,13)
- cardw = 80
- cardl = 110
- def draw():
- global whichmenu
- if whichmenu == 0:
- menu()
- elif whichmenu == 1:
- pokerTable()
- def menu():
- global whichmenu
- background(0)
- image(pokertable,0,0,1000,650)
- image(pokertitle,315,190,400,100)
- print(mouseX,mouseY)
- drawTextboxes(menuboxes)
- if isClicked(textboxes[0]):
- whichmenu = 1
- def pokerTable():
- global betamount,bankamount,bet_text,negatory_text,pository_text,amount_text,bet_text,check_text,fold_text,call_text,raise_text,balance_text
- global backofcard,handsize,numberofplayers,drawtwocards_text,deckimage,hand1,hand2,thedeck
- image(pokertable,-100,-50,1100,750)
- gameboxes = [bet_text,negatory_text,pository_text,amount_text,bet_text, check_text,fold_text,call_text,raise_text,balance_text,drawtwocards_text]
- drawTextboxes(gameboxes)
- betamount = getBet(gameboxes[2],gameboxes[1],betamount,bankamount)
- amount_text = [820,150,110,50,"$"+str(betamount),color(0,200,0)]
- #this displays back of card
- hand1 = thedeck.createHand(5)
- hand2 = thedeck.createHand(5)
- drawHand([[0,0],[0,0],[0,0],[0,0],[0,0]],1,backofcard,1152,1600)
- drawHand([[0,0],[0,0],[0,0],[0,0],[0,0]],0,backofcard,1152,1600)
- #This displays the hand
- drawHand(hand1,0,deckimage,80,110)
- drawHand(hand2,1,deckimage,80,110)
- hand1score = getScore(hand1)
- hand2score = getScore(hand2)
- if hand1score > hand2score:
- print("Hand 1 win with score of "+str(hand1score))
- elif hand1score < hand2score:
- print("Hand 2 win with score of "+str(hand2score))
- else:
- print("Tie with score of "+str(hand1score))
- if isClicked(gameboxes[5]):
- check()
- elif isClicked(gameboxes[6]):
- fold()
- elif isClicked(gameboxes[7]):
- call()
- elif isClicked(gameboxes[8]):
- #Raise() is uppercase cuz raise() is a in-built function
- Raise()
- def copypokerCards(handsize,numberofplayers,cardimage,ogcordx,ogcordy,ogwidth,ogheight,newx,newy,newwidth,newheight):
- for i in range(handsize):
- for l in range(numberofplayers):
- copy(cardimage,ogcordx,ogcordy,ogwidth,ogheight,newx+130*i,newy+250*l,newwidth,newheight)
- def Raise():
- pass
- def call():
- pass
- def check():
- pass
- def fold():
- pass
- def getBet(plusbox,minusbox,betamount,bankamount):
- if isClicked(minusbox) and betamount>1:
- betamount -=1
- elif isClicked(plusbox) and betamount<bankamount:
- betamount+=1
- return(betamount)
- def drawTextboxes(textboxes):
- textSize(30)
- fill(255)
- for i in range(len(textboxes)):
- fill(textboxes[i][5])
- rect(textboxes[i][0],textboxes[i][1],textboxes[i][2],textboxes[i][3])
- fill(255)
- text(textboxes[i][4],textboxes[i][0],textboxes[i][1]+35)
- def drawtextboxes(textboxes):
- textSize(30)
- fill(255)
- for i in range(len(textboxes)):
- fill(textboxes[i][5])
- rect(textboxes[i][0],textboxes[i][1],textboxes[i][2],textboxes[i][3])
- fill(255)
- text(textboxes[i][4],textboxes[i][0],textboxes[i][1]+35)
- def isClicked(info):
- clicked = False
- if mousePressed and mouseButton == LEFT:
- if info[0] < mouseX < info[0] + info[2] and info[1] < mouseY < info[1] + info[3]:
- clicked = True
- return clicked
- def drawHand(hand,num,theimage,cardw,cardl):
- print(hand)
- for i in range(len(hand)):
- cardval = hand[i][0]
- suitval = hand[i][1]
- textSize(30)
- copy(theimage, cardw*(cardval ), cardl*suitval, cardw, cardl, 110+130*i, 150+(num*250), 115, 160)
- 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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement