Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Define Card by storing Number (Ace = 1, Jack = 11, Queen = 12, King = 13) value
- # and Suit value (0=Hearts, 1=Clubs, 2=Spades, 3=Diamonds)
- class Card:
- SUIT = ["Hearts", "Clubs", "Spades", "Diamonds"]
- VALUES = ["ACE", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, "JACK", "QUEEN", "KING"]
- CARD_SUIT=0
- CARD_VALUE=0
- def __init__(self, number, suit):
- self.CARD_SUIT = suit
- self.CARD_VALUE= number
- def print_card(my_card):
- print(str(Card.VALUES[my_card.CARD_VALUE]) + " of " + Card.SUIT[my_card.CARD_SUIT])
- class Hand:
- #Track each players 5 card hand
- #Detect strength of hand (Pair, 2 pair, 3 of a kind etc)
- #Compare 2 hands to see which one is stronger
- #Sort method to assist hand detection
- cards_in_hand = []
- def __init__(self, cards):
- for c in cards:
- #adding each card to the cards in hand
- self.cards_in_hand.append(c)
- # self.cards_in_hand.append(Card(c[0], c[1]))
- #self.cards_in_hand = sort_hard(cards_in_hand)
- def print_hand(my_hand):
- print("It should be entering this function but it isnt")
- for c in my_hand.cards_in_hand:
- Card.print_card(c)
- def sort_hard(hand_1):
- #Returns a sorted hand based upon values of cards in hand
- return hand_1;
- def hand_strength(hand_1):
- #Detect what the hand is
- # 0 = High Card, 1 = Pair, 2 = Two Pair, 3 = Three of a Kind*
- # 4 = Straight, 5 = Flush, 6 = Full House, 7 = Four of a Kind
- # 8 = Straight Flush 9 = Royal Flush
- return 1;
- def stronger_hand(hand_1, hand_2):
- strength_1 = hand_strength(hand_1)
- strength_2 = hand_strength(hand_2)
- if strength_1 > strength_2: #returns -1 if hand_1 is stronger
- return -1
- elif strength_2 > strength_1:
- return 1 #returns 1 if hand_2 is stronger
- else:
- return 0 #returns 0 if hand_1 and hand_2 are of equal strength
- #below are methods for detecting each type of hand
- def pair(my_hand):
- return False
- def two_pair(my_hand):
- return False
- def three_of_a_kind(my_hand):
- return False
- def straight(my_hand):
- return False
- def flush(my_hand):
- suit = my_hand.cards_in_hand[0].CARD_SUIT
- for card in my_hand.cards_in_hand:
- if card.CARD_SUIT != suit:
- return False
- return True
- def full_house(my_hand):
- return False
- def four_of_a_kind(my_hand):
- return False
- def straight_flush(my_hand):
- if straight(my_hand) & flush(my_hand):
- return True
- return False
- def royal_flush(my_hand):
- return False
- handy = Hand([(1, 2), (1, 3), (2, 3), (1, 1), (3, 8)])
- Hand.print_hand(handy)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement