1 Replies - 1226 Views - Last Post: 06 December 2007 - 06:57 PM Rate Topic: -----

#1 losttoomuch  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 06-December 07

Python class, text/strings

Post icon  Posted 06 December 2007 - 04:53 PM

I have written this class and I am having trouble figuring out the code for a straight. How would I check it in IDLE to see if it works


class PokerHand:
	def __init__(self):
		self.hand = [None, None, None, None, None]

	def set_card(self, position, card):
		self.hand[position] = card
		
	def eval_hand(self):
		faces = 13 * [0]
		suits = 4 * [0]
		
		for card in self.hand:
			face_val = card % 13
			suit_val = card / 13
			faces[face_val] += 1
			suits[suit_val] += 1

		if faces.count(4) == 1:
			return "four of a kind"
		if faces.count(3) == 1 and faces.count(2) == 1:
			return "full house"
		if suits.count(5) == 1:
			return "flush"
		
		x = faces.index(1) == 1
		if x <= 8:
			for i in range(4):
				x+= x[1]
			return "straight"
		




I am trying to get the strings I have returned in the class above into the function below but I keep getting a message that says the class has no instance of the class


def deal_card():
	win = GraphWin("Poker", 800, 600)
	win.setBackground('green4')
	deck = CardDeck()
	deck.shuffle()
	p1 = PokerHand()
	p2 = PokerHand()
	x = 100
	for i in range(5):
		x = x + 100
		c = deck.deal_one()
		filename = get_card_info(c)
		draw_card(filename, x , 100, win)
		p1.set_card(i, c)
	p1.getText()



This post has been edited by losttoomuch: 06 December 2007 - 05:32 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Python class, text/strings

#2 Sharke  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 02-December 07

Re: Python class, text/strings

Posted 06 December 2007 - 06:57 PM

Here's a clue for the straight code (you might have to alter your code a little):

If there are five 1's in your face count list, and the HIGHEST card is exactly 4 higher than the LOWEST card, you have a straight.

Then it's a simple matter of seeing if all suits are the same to determine whether it's a straight flush.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1