from random import *

fromdatetime import *

##Hands (in order):

## 1. royal flush (e.g., AH, KH, QH, JH, 10H)

## 2. straight flush (9C, 8C, 7C, 6C, 5C)

## 3. four of a kind (KH, KD, KS, KC)

## 4. full house (10H, 10D, 10C, 3S, 3D)

## 5. flush (e.g., 10H, 8H, 6H, 3H, 2H)

## 6. straight (e.g., KH, QD, JC, 10H, 9S)

## 7. 3 of a kind (e.g.,3D, 3H, 3Q, 10S, 4H)

## 8. two pair (8H, 8D, 4C, 4D, AS)

## 9. one pair (e.g., KD, KS, 9S, 7C, 3H)

## 10. high card (e.g., AS, QS, 9C, 4H, 2D)

class Card(object):

def __init__

def __lt__

def __str__

classDeckofCards(object):

def __init__

defgetdeck

defshuffledeck

defgetcard

class Player(object):

def __init__

defgetscore

defprintHand

classFiveCardStud(object):

def __init__(self,name):

self.deck = DeckofCards()

self.listofplayers = [Player(name,100),Player('p2',100,True),Player('p3',100,True)]

defanteup(self):

ante = 10

fori in self.listofplayers: #For placing bets, first round

if(i.money - ante) > 0:

i.currbet = ante

else:

print(i.name + " is out of money ")

x = self.listofplayers.index(i)

self.listofplayers.pop(x)

defplacebets(self):

fori in range(len(self.listofplayers)): #For placing bets, first round

if not self.listofplayers[i].fold:

if not self.listofplayers[i].comp:

b = -1

while b == -1:

b = int(input("Enter bet: "))

if b == 0:

self.listofplayers[i].fold = True

elif (self.listofplayers[i].money - b) < 0:

b = -1

else:

self.listofplayers[i].currbet+= b

print(self.listofplayers[i].name + " bets: " + str(b))

else:

x = min(self.listofplayers[i].money,20)

k = randrange(x)

self.listofplayers[i].currbet += k

print(self.listofplayers[i].name + " bets: " + str(k))

print()

##Hands (in order):

## 1. royal flush (e.g., AH, KH, QH, JH, 10H)

## 2. straight flush (9C, 8C, 7C, 6C, 5C)

## 3. four of a kind (KH, KD, KS, KC)

## 4. full house (10H, 10D, 10C, 3S, 3D) *

## 5. flush (e.g., 10H, 8H, 6H, 3H, 2H)

## 6. straight (e.g., KH, QD, JC, 10H, 9S)

## 7. 3 of a kind (e.g.,3D, 3H, 3Q, 10S, 4H) *

## 8. two pair (8H, 8D, 4C, 4D, AS)

## 9. one pair (e.g., KD, KS, 9S, 7C, 3H)

## 10. high card (e.g., AS, QS, 9C, 4H, 2D)

defbreaktie(self,score):

p = 0

b = 0

sl = ['C','D','H','S']

bs = 0

for x in range(len(self.listofplayers)):

ifself.listofplayers[x].currscore == score:

if score == 1:

k = self.deck.deck.index(self.listofplayers[x].hand[0])

if k < b:

k = b

p = x

elif score == 3 or score == 8:

f = self.listofplayers[x].hand[1].face

if f=='A':

k = 14

elif f == 'K':

k = 13

elif f == 'Q':

k = 12

elif f == 'J':

k = 11

else:

k = int(f)

if k > b:

k = b

p = x

elif score == 10 or score == 2 or score ==5 or score == 6:

f = self.listofplayers[x].hand[0].face

s = self.listofplayers[x].hand[0].suit

if f=='A':

k = 14

elif f == 'K':

k = 13

elif f == 'Q':

k = 12

elif f == 'J':

k = 11

else:

k = int(f)

if k > b:

b = k

p = x

elif k == b:

si = sl.index(s)

ifsibs:

bs = si

p = x

elif score == 9:

for s in range(1,len(self.listofplayers[x].hand)):

if self.listofplayers[x].hand[s-1].face==self.listofplayers[x].hand[s].face:

f = self.listofplayers[x].hand[s].face

if f=='A':

k = 14

elif f == 'K':

k = 13

elif f == 'Q':

k = 12

elif f == 'J':

k = 11

else:

k = int(f)

if k > b:

b = k

p = x

return(p)

def deal(self,i):

for x in self.listofplayers:

if (i):

x.hand.append(self.deck.getcard())

if (not x.fold):

x.hand.append(self.deck.getcard())

p = True

for x in self.listofplayers:

if (not x.fold):

x.printHand(p)

p = False

print()

defplaygame(self):

x = input("The default is to play against 2 other computer players. Do you wish to play against more players? ")

if (x == 'yes'):

y = int(input("Enter number of players (other than yourself): "))

if y == 1:

self.listofplayers.pop()

elif y >2:

for z in range(y-2):

n = 'p'+str(z+2)

k = Player(n,100,True)

self.listofplayers.append(k)

playagain = True

## ct = 0;

whileplayagain:

self.anteup()

iflen(self.listofplayers) > 1:

self.deal(True)

self.placebets()

c = 0;

while c < 3 and len(self.listofplayers) > 1:

self.deal(False)

self.placebets()

c += 1

for x in self.listofplayers:

if not x.fold:

x.getscore()

else:

x.currscore = 12

best = 0

tie = False

for x in range(1,len(self.listofplayers)):

ifself.listofplayers[x].currscoreself.listofplayers[best].currscore:

best = x

tie = False

elifself.listofplayers[x].currscore == self.listofplayers[best].currscore:

tie = True

if tie:

print("breaking tie")

best = self.breaktie(self.listofplayers[best].currscore)

print(self.listofplayers[best].name + " won!")

print()

pot =0

for x in range(0,len(self.listofplayers)):

if x != best:

pot += self.listofplayers[x].currbet

self.listofplayers[x].money -= self.listofplayers[x].currbet

self.listofplayers[best].money += pot

for x in self.listofplayers:

ifx.money <= 0:

y = self.listofplayers.index(x)

print(x.name + " is out ")

self.listofplayers.pop(y)

else:

print(x.name + " has " + str(x.money))

print()

iflen(self.listofplayers) == 1:

print(self.listofplayers[0].name + " won with " + str(self.listofplayers[0].money))

playagain = False

eliflen(self.listofplayers) < 1:

print("No winners ")

playagain = False

else:

for x in self.listofplayers:

x.currbet = 0

x.currscore = -1

x.hand = []

x.fold = False

def main():

name = input("Enter your name: ")

game = FiveCardStud(name)

game.playgame()

main()