Created
May 28, 2015 01:01
-
-
Save mkowoods/8bc7e105f19febef65c7 to your computer and use it in GitHub Desktop.
part 1 of 3 for Texas Hold Em Daily Programmer Project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
#https://www.reddit.com/r/dailyprogrammer/comments/378h44/20150525_challenge_216_easy_texas_hold_em_1_of_3/ | |
class Deck: | |
def __init__(self): | |
self.deck = [(rank, suit) for rank in range(1, 14) for suit in ["S", "C", "D", "H"]] | |
random.shuffle(self.deck) | |
def deal_card(self): | |
return Card(self.deck.pop()) | |
class Card: | |
def __init__(self, card_id): | |
self.card_id = card_id | |
def __repr__(self): | |
suit = {'S': 'Spades', 'C': 'Clubs', 'D': 'Diamonds', 'H': 'Hearts'} | |
rank = {1: 'Ace', 11: 'Jack', 12: 'Queen', 13 : 'King'} | |
r, s = self.card_id | |
return '%s of %s'%(rank.get(r, r), suit.get(s)) | |
class Game: | |
def __init__(self, players): | |
self.players = players | |
self.deck = Deck() | |
self.player_hands = {} | |
self.table_cards = [] | |
def start_game(self): | |
for i in range(self.players*2): | |
pl_id = i%self.players | |
if pl_id in self.player_hands: | |
self.player_hands[pl_id].append(self.deck.deal_card()) | |
else: | |
self.player_hands[pl_id] = [self.deck.deal_card()] | |
#burn before flop | |
self.deck.deal_card() | |
self.table_cards = [self.deck.deal_card() for _ in range(3)] | |
self.deck.deal_card() | |
self.table_cards += [self.deck.deal_card()] | |
self.deck.deal_card() | |
self.table_cards += [self.deck.deal_card()] | |
for i in range(self.players): | |
if i == 0: | |
print 'Your Hand: ', self.player_hands[i] | |
else: | |
print 'CPU%d Hand: '%i, self.player_hands[i] | |
print 'Flop :', self.table_cards[:3] | |
print 'Turn :', self.table_cards[3] | |
print 'River:', self.table_cards[4] | |
if __name__ == "__main__": | |
game = Game(3) | |
game.start_game() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment