- #1
DanielJackins
- 40
- 0
Homework Statement
I have to create a function which determines which hand is the winning (3-card) poker hand.
Code:
import random
from subprocess import Popen, PIPE
from bpipe import *
from time import sleep
class Card:
def __init__(self, suit='club', rank ='A'):
self.suit = suit
self.rank = rank
def __str__(self):
return self.suit + '-' + self.rank
class Deck:
def __init__(self):
self.cards = []
for suit in ['club','spade','heart','diamond']:
for rank in ['A','2','3','4','5','6','7','8', \
'9','10','J','Q','K']:
self.cards += [Card(suit,rank)]
def shuffle(self):
for i in range(len(self.cards)):
j = random.randrange(i, len(self.cards))
self.cards[i],self.cards[j] = self.cards[j],self.cards[i]
def deal(self):
return self.cards.pop()
class Hand:
def __init__(self, cards = [], displayed=0):
self.cards = cards
self.displayed = displayed
def get_card(self, card):
self.cards += [card]
def eval(self):
return
def display(hands, round):
for i in range(2):
for j in range(hands[i].displayed, len(hands[i].cards)):
s = hands[i].cards[j].__str__()
qdin.write('loadimage %s.png %s\n' % (s, s+str(round)))
qdin.write('drawimage %d %d %s\n' % (265+j*80, 100+200*i, s+str(round)))
hands[i].displayed = len(hands[i].cards)
qd = Popen("java -jar quickdraw.jar", shell=True, bufsize=1, \
stdin=PIPE, stdout=PIPE, close_fds=True)
qdin, qdout = qd.stdin, qd.stdout
qdin.write( "mouseclick True\n" )
deck = Deck()
deck.shuffle()
qdin.write("color 30 20 60\n fillrect 650 100 100 60\n" )
qdin.write("color 255 255 255\n text (Re)play 675 135\n")
qdin.write("color 30 20 60\n fillrect 650 250 100 60\n" )
qdin.write("color 255 255 255\n text Quit 675 285\n")
round = 0
while True:
event, val = ParseEvent( qdout.readline() )
if event == "MouseClicked":
x, y = val[0], val[1]
if 650<x<750:
if 100<y<160:
round +=1
qdin.write("color 0 0 0\n text YouWin! 100 350\n")
qdin.write("color 0 0 0\n text HouseWins! 100 150\n")
qdin.write("color 0 0 0\n text Tie! 370 500\n")
deck = Deck()
deck.shuffle()
hands = [Hand([deck.deal()]+[deck.deal()] + [deck.deal()] )] + \
[Hand([deck.deal()]+[deck.deal()] + [deck.deal()] )]
display(hands,round)
p_score = hands[1].eval()
h_score = hands[0].eval()
if h_score < p_score:
qdin.write("color 255 255 255\n text YouWin! 100 350\n" )
elif h_score > p_score:
qdin.write("color 255 255 255\n text HouseWins! 100 150\n")
else:
qdin.write("color 255 255 255\n text Tie! 370 500\n")
if 250<y<310: break
qdin.write("quit")
So I have to define the function eval.
The Attempt at a Solution
None thus far. I don't really know where to start. The only thing I can really think of is a bunch of if statements with complicated conditions, but I'm not sure about that. A nudge in the right direction would be greatly appreciated