def __init__(self): self.desks = [] self.bank_cards = [] self.player_cards = [] self.game_state = 2 self.deck = Deck() self.deck.shuffle()
def __init__(self, pygame_clock, game_controller): self.dt = 0 self.pygame_clock, self.game_controller = pygame_clock, game_controller self.deck = Deck() self.load_image_assets() self.board = Board(pygame_clock, self.deck) self.back_image = self.deck.cards_list[-1].current_image.copy() self.deck_x, self.deck_y = (SCREENWIDTH // 2), (SCREENHEIGHT // 2) - (self.back_image.get_rect().size[1] // 2) # mouse + position self.click = False self.mx, self.my = 0, 0 self.were_init_cards_dealt = False self.animating_init_deck = True self.animating_init_deal = False self.show_card_size = False self.animate_deck_count = 1 # used in self.animate_init_deck self.animate_init_deal_count = 0 # used in deal_cards_init_animation self.players = [] self.player_count = 0 self.attacker = None self.add_player(Player("Alex", True, 0)) self.add_player(simpleBot("NPC837", 1)) self.add_player(simpleBot("NPC619", 2))
class PasyansGameState(CardGameState): """Represents the history of a Pasyans game, allowing turns to be reversed or a game to be resumed.""" ranks = [ Rank.SIX, Rank.SEVEN, Rank.EIGHT, Rank.NINE, Rank.TEN, Rank.JACK, Rank.QUEEN, Rank.KING, Rank.ACE ] command_aliases = { 'move': ['move', 'mv'], 'exit': ['exit', 'end', 'quit'], 'win': ['win'] } cell_names = ['1', '2', '3', '4', '5', '6', '7', '8', '9', 'F', 'f'] def __init__(self, debug_mode=False): super().__init__(self.ranks, debug_mode) self.deck.shuffle() self.cells = [[self.deck.draw() for i in range(4)] for j in range(9)] self.free_cell = None def reset_game(self): self.deck = Deck(self.ranks) self.deck.shuffle() self.cells = [[self.deck.draw() for i in range(4)] for j in range(9)] self.free_cell = None self.turn_history = [] self.is_won = False
class DeckTest(unittest.TestCase): def setUp(self): self.deck = Deck() def test_get_suit(self): self.assertEqual(self.deck.get_suit(0), 'Spades') self.assertEqual(self.deck.get_suit(13), 'Hearts') self.assertEqual(self.deck.get_suit(26), 'Diamonds') self.assertEqual(self.deck.get_suit(39), 'Clubs') def test_get_rank(self): self.assertEqual(self.deck.get_rank(0), 1) self.assertEqual(self.deck.get_rank(13), 1) self.assertEqual(self.deck.get_rank(26), 1) self.assertEqual(self.deck.get_rank(39), 1) def test_get_card(self): i = 0 cardnumber = self.deck[i] card = ( self.deck.get_rank(cardnumber), self.deck.get_suit(cardnumber) ) self.assertEqual(self.deck.get_card(i), card) def test_teek(self): self.assertEqual(self.deck.peek(0), self.deck[0]) def test_shuffle(self): shuffled_deck = Deck() shuffled_deck.shuffle() self.assertNotEqual(self.deck, shuffled_deck)
def main(): print( "Hi! Welcome to the Blackjack table. Let's see if you can beat the dealer" ) money = ask_how_much_money( "How much money do you want to start with? You must enter a positve integer \n" ) round = 1 deck = Deck() while (money > 0): print("Round " + str(round)) print("Currently you have " + str(money) + " money") if new_round(): bet = ask_how_much_money("How much money do you want to bet? \n", money) if len(deck.cards) < MIN_NUMBER_CARDS_IN_DECK: # reshuffle the cards, and start off with a full deck if have less than 10 cards deck = Deck() playerHand, dealerHand, deck = play_round(deck) if playerHand.cur_value == GOAL_CONSTANT or dealerHand.cur_value > GOAL_CONSTANT: money += bet elif playerHand.cur_value > GOAL_CONSTANT: money -= bet elif playerHand.cur_value > dealerHand.cur_value: win_statement("You", playerHand.cur_value) money += bet else: lose_statement("You", playerHand.cur_value) money -= bet round += 1 else: print("You have left the game with " + str(money) + " money") return print("You have run out of money") return
def __init__(self): """ Constructor, do the setup here. After setup with Solitaire.columns = 7, Solitaire.cards_in_column = 5 You should have: self.tableau -> 7 columns of cards with 5 cards in each column self.stock -> 16 cards self.waste -> 1 card """ self.deck = Deck() self.tableau = [] self.waste = [] self.stock = [] self.deck.shuffle_deck() for col in range(Solitaire.columns): column = [] # Deal cards to each column in range of given nr. for cards in range(Solitaire.cards_in_column): column.append(self.deck.deal_card()) self.tableau.append(column) self.waste.append(self.deck.deal_card()) while not self.deck.is_empty(): self.stock.append(self.deck.deal_card())
def start_game(self): print_info("Game started!") # Initialize Deck deck = Deck() deck.shuffle() # print_deck(deck) # Initialize all players print_info("Dealing {} cards each to {} players".format( self.numOfCardsPerPlayer, self.numOfPlayers)) # Initialize player 0 - fork subprocess user_id = 0 playerProcess = Thread(target=self.player_process, args=(user_id, deck)) self.threads.append(playerProcess) # Initialize CPU's - fork subprocesses for CPU's for cpu_id in range(1, self.numOfPlayers): # CPU Processes cpuProcess = Thread(target=self.cpu_process, args=(cpu_id, deck)) self.threads.append(cpuProcess) for thread in self.threads: thread.start() self.turns[0].put(1)
def __init__(self): """Creates the cards and sets up the images and labels for two cards to be displayed, the state label, and two command buttons. """ EasyFrame.__init__(self, title="Card Game") self.setSize(220,200) #create cards/deck self.card1=Deck() self.card="b" #labels self.cardLabel1= self.addLabel("",row=0, column=0, sticky= "NSEW",columnspan=2) self.stateLabel = self.addLabel(self.card, row = 1, column = 0, sticky = "NSEW", columnspan = 2) self.addButton(row = 2, column = 0, text = "Draw", command = self.nextDraw) self.addButton(row = 2, column = 1, text = "New game", command = self.newGame) self.refreshImages()
class TestDeck(unittest.TestCase): def setUp(self): self.deck = Deck() def test52(self): self.assertEqual(len(self.deck), 52) def test_no_dupes(self): seen = set() for card in self.deck: self.assertNotIn(card, seen) seen.add(card) def test_repr_string(self): self.assertIsInstance(repr(self.deck), str) def test_shuffle(self): deck2 = Deck() random.shuffle(deck2) self.assertNotEqual(self.deck.cards, deck2.cards) def test_deal_5(self): hand = self.deck.deal(5) self.assertEqual(len(hand), 5) def test_draw(self): hand = self.deck.deal(5) self.deck.draw(hand) self.assertEqual(len(hand), 6)
def defends(self, attack_cards, trump_suit): print("Here're your cards: ") self.deck.show() print("Comp attacks you with these cards: ") for i in range(len(attack_cards)): print(VALUES_DICT[attack_cards.get_card_by_index(i).value], attack_cards.get_card_by_index(i).suit) defend_cards = Deck() cards_indices = list( map( int, input( "What cards do you put for attack? Write their indices (if you can't beat a card, type '-1'): " ).split())) for card_index in cards_indices: for attack_card in attack_cards: if card_index == -1: self.deck.add_cards(attack_cards) return "You couldn't defend and picked up cards" defend_card = self.deck.get_card_by_index(card_index) if is_beatable(defend_card, attack_card, trump_suit) == False: return "Wrong action" defend_cards.add_card(defend_card) print("You're throwing these cards: ") defend_cards.show() updated_deck = Deck() for j in range(len(self.deck)): if j in cards_indices: continue updated_deck.add_card(self.deck[j]) self.deck = updated_deck print("Here're your cards now: ") self.deck.show() return "Defended succesfully"
def __init__(self, player_list): self.player_list = player_list self.deck = Deck() self.deck.construct_new_deck() # Move dealer to end player_list.append(player_list.pop(0)) self.game_end = False
def __init__(self): """ Constructor, do the setup here. After setup with Solitaire.columns = 7, Solitaire.cards_in_column = 5 You should have: self.tableau -> 7 columns of cards with 5 cards in each column self.stock -> 16 cards self.waste -> 1 card """ self.deck = Deck() # -> Deck instance self.tableau = [ ] # -> list of (columns[lists] (where each list -> cards_in_column * Card instances)) self.waste = [] # -> list of Card instances self.stock = [] # -> list of Card instances self.deck.shuffle_deck() # -> shuffle_deck() from package cards for column in range(self.columns): column = [] for card in range(self.cards_in_column): column.append( self.deck.deal_card()) # -> deal_card() from package cards self.tableau.append(column) self.waste.append(self.deck.deal_card()) for card in range(len(self.deck.cards)): self.stock.append(self.deck.deal_card())
def testAddCard(self): d = Deck() card = d.pop_card() self.assertEqual(51, len(d.cards)) d.add_card(card) self.assertEqual(52, len(d.cards))
def testPopCard(self): d = Deck() card = d.pop_card() self.assertEqual(12, card.rank) self.assertEqual(3, card.suit) self.assertEqual(51, len(d.cards))
def simulateAGame(): P1Hand = Deck() P2Hand = Deck() community = buildCommunityDeck() for i in range(0,8): P1Hand.insertCard(community['mainDeck'].cards.pop()) P2Hand.insertCard(community['mainDeck'].cards.pop()) # print "player 2 cards" # P2Hand.revealSorted() print "Remaining:" # mainDeck.revealAll() b = Card(Color.RED.value,10) computer = ai.DumbAI() computer2=ai.AlwaysDraw() while True: if len(P2Hand)<8: raise Exception("P2 doesn't have 8 cards") if len(P1Hand)<8: raise Exception("P1 doesn't have 8 cards") print "Cards remaining: {}".format(len(community['mainDeck'])) print "Player 1 cards" P1Hand.revealSorted() printGameBoard(community) # getMove("P1",P1Hand,community) computer.computerMakeMove("P1",P1Hand,community) if gameOver(community['mainDeck']): break print "Cards remaining: {}".format(len(community['mainDeck'])) # P2Hand.revealSorted() printGameBoard(community) # getMove("P2",P2Hand,community) computer2.computerMakeMove("P2",P2Hand,community) if gameOver(community['mainDeck']): break return printGameSummary(community)
def __init__(self): self._deck = Deck() self._deck.shuffle() #Pass the player and the dealer two cards each self._player = Player([self._deck.deal(), self._deck.deal()]) self._dealer = Dealer([self._deck.deal(), self._deck.deal()])
class Cribbage: HUMAN = "human" COMPUTER = "computer" def __init__(self): self.deck = None self.starter = None self.board = None self.players = {Cribbage.HUMAN: HumanPlayer(), Cribbage.COMPUTER: ComputerPlayer()} self.crib = [] self.game_state = GAME_STATE_DONE def play(self): self.deck = Deck() self.board = {Cribbage.HUMAN: 0, Cribbage.COMPUTER: 0} self.players[Cribbage.COMPUTER].deal([self.deck.draw() for c in range(6)], False) self.players[Cribbage.HUMAN].deal([self.deck.draw() for c in range(6)], False) def get_computer_cards(self): return self.players[Cribbage.COMPUTER].get_cards() def get_human_cards(self): return self.players[Cribbage.HUMAN].get_cards() def update(self): pass
def generatePokerHands(self): """Generates every possible poker hand Returns ------- num: integer Number of hand instances """ deck_1 = Deck().cards for card_1 in deck_1: deck_2 = list(deck_1) deck_2.pop(deck_1.index(card_1)) filename = 'poker_hand_%s_%s.data' % (card_1.suit, card_1.rank) file = open(filename, 'a+') for card_2 in deck_2: deck_3 = list(deck_2) deck_3.pop(deck_2.index(card_2)) for card_3 in deck_3: deck_4 = list(deck_3) deck_4.pop(deck_3.index(card_3)) for card_4 in deck_4: deck_5 = list(deck_4) deck_5.pop(deck_4.index(card_4)) for card_5 in deck_5: hand = self.createDataRow( [card_1, card_2, card_3, card_4, card_5]) hand = str(hand).strip('[]') file.write(hand + "\n") deck_5.append(card_4) deck_4.append(card_3) deck_3.append(card_2) deck_2.append(card_1) file.close()
def test_shuffle(): deck = Deck() deck.shuffle() card1 = deck.draw_card() card2 = deck.draw_card() assert card1.rank != "King" and card1.suit != "Spades" and card2.rank != "King" and card2.suit != "Hearts"
def __init__(self, server, channel): self.status = "Waiting for players to join" # Keep track of the current channel/server self.channel = channel self.server = server #flag to keep track of whether or not game is running self.running = True #list of active players in a game self.players = [] #dummy with a small deck for testing. #replace with actual card loading from DB later self.deck = Deck() # Who is the current czar in self.players? # Starting at -1 so the first iteration has the czar be the first person to join self.current_czar = -1 # What is the current black card? self.current_card = None # Cards submitted self.submissions = {}
def test_deck_length1(self): x = Deck() card = Card("a", "b") x[:] = [card] actual = x.draw() self.assertEqual(actual, card) self.assertListEqual(x, [])
def test_2elements(self): card1 = Card("a", "b") card2 = Card("c", "d") x = Deck([card1, card2]) x.shuffle() # NOTE: don't check order because it has a 50% chance of not changing self.assertSetEqual(set(x), set([card1, card2]))
def newDeck(self): """Create a new craps game and updates the view.""" self.deck = Deck() self.deck.shuffle() self.stateLabel["text"] = "" card = "" self.refreshImages(card)
def deck_card_count_test(): '''Testing create deck function, that it creates a 52 card deck''' d = Deck() if d.card_count() == 52: return True else: return False
def __init__(self, mode=None, print_games=True): self.deck = Deck() self.mode = mode self.dealer_hand = [] self.player_hand = [] # deal out initial cards dealer_card = self.deck.draw() dealer_card.facing = "down" self.dealer_hand.append(dealer_card) self.player_hand.append(self.deck.draw()) self.dealer_hand.append(self.deck.draw()) self.player_hand.append(self.deck.draw()) if print_games: logging.basicConfig(stream=sys.stdout, level=logging.DEBUG, format="%(message)s") else: logging.basicConfig(level=logging.CRITICAL) logging.info("--------- A GAME OF BLACKJACK ---------") logging.info(self) if self.mode == "stdin": while True: command = raw_input( "What would you like to do? [s]tay, [h]it...") self.dealer_command(command)
def war(num_players = 4): deck = Deck().shuffle() decks = deck.split(num_players) human = Player(deck = decks[0]) cpus = [Player(deck = decks[i+1]) for i in range(num_players-1)] # play game here, player.deck.cards.pop(0) removes and returns first card in player's deck return
def test_3elements(self): card1 = Card("a", "b") card2 = Card("c", "d") card3 = Card("e", "f") x = Deck([card1, card2, card3]) x.shuffle_riffle() self.assertSetEqual(set(x), set([card1, card2, card3]))
class DeckTest(unittest.TestCase): def setUp(self): self.deck = Deck() def test_get_suit(self): self.assertEqual(self.deck.get_suit(0), 'Spades') self.assertEqual(self.deck.get_suit(13), 'Hearts') self.assertEqual(self.deck.get_suit(26), 'Diamonds') self.assertEqual(self.deck.get_suit(39), 'Clubs') def test_get_rank(self): self.assertEqual(self.deck.get_rank(0), 1) self.assertEqual(self.deck.get_rank(13), 1) self.assertEqual(self.deck.get_rank(26), 1) self.assertEqual(self.deck.get_rank(39), 1) def test_get_card(self): i = 0 cardnumber = self.deck[i] card = (self.deck.get_rank(cardnumber), self.deck.get_suit(cardnumber)) self.assertEqual(self.deck.get_card(i), card) def test_teek(self): self.assertEqual(self.deck.peek(0), self.deck[0]) def test_shuffle(self): shuffled_deck = Deck() shuffled_deck.shuffle() self.assertNotEqual(self.deck, shuffled_deck)
def test_full(self): x = Deck() x.reset() before = list(x) x.shuffle() after = list(x) self.assertTrue(before != after) self.assertSetEqual(set(x), set(before))
def test1(): card1 = Card("spades", 10) card2 = Card("diamonds", 11) deck1 = Deck() deck1.add_card(card1) deck1.add_card(card2) for card in deck1: card.show_card()
def deck_deal_cards_test(): d = Deck() h = Hand() d.deal_cards(h, 10) if d.card_count() == 42 and h.card_count() == 10: return True else: return False
def reset_game(self): self.deck = Deck(self.ranks) self.deck.shuffle() self.cells = [[self.deck.draw() for i in range(4)] for j in range(9)] self.free_cell = None self.turn_history = [] self.is_won = False
def hand_card_count_test(): d = Deck() h = Hand() d.deal_cards(h, 8) if h.card_count() == 8: return True else: return False
def test_deck_full(self): x = Deck() x.reset() expected_state_after = x[:-1] expected_card = x[-1] actual_card = x.draw() self.assertEqual(actual_card, expected_card) self.assertListEqual(x, expected_state_after)
def test_deck_length2(self): x = Deck() card1 = Card("a", "b") card2 = Card("c", "d") x[:] = [card1, card2] actual = x.draw() self.assertEqual(actual, card2) self.assertListEqual(x, [card1])
def test_num_cards(self): """ Test number of cards in deck is correct """ d1, d13 = Deck(), Deck() d1.reload() d13.reload(13) d1_len, d13_len = len(d1.cards), len(d13.cards) self.assertEqual(d1_len, 52) self.assertEqual(d13_len, 676)
def __init__(self, interface): # interface is an object for user interaction # Initializes the instance variables self.money = 100 # user starts with $100 self.deck = Deck() # start with a shuffled deck self.deck.shuffle() self.player = None # player hand (initially None) self.dealer = None # Dealer hand (initially None self.interface = interface # for user interaction
def __init__(self): """Sets up the two players, the war pile, the deck, and the game state.""" self._player1 = Player() self._player2 = Player() self._warPile = [] self._gameState = "" self._deck = Deck() self._deck.shuffle()
def reset(self, deck=None): self.clear() self._moveLog = [] if deck == None: self._deck = Deck() self._deck.shuffle() else: self._deck = deck self.deal() self.getPotentialMoves()
def __init__(self, numberOfPlayers): # initialize local variables deck = Deck(WITHOUT_JOKERS) deck.shuffleDeck() # initialize class variables self.deck = deck self.numberOfPlayers = numberOfPlayers self.dealer = deck.getCards() # dealer gets all cards self.players = [] for i in range(0, numberOfPlayers): self.players.append([]) # players get no cards
def __init__(self): self.grid = [] deck = Deck() deck.shuffle() n = 0 for i in range(1,5): self.grid.append([]) for j in range(1, 14): card = deck.cards[n] if card.rank[0] == "A": card = None self.grid[i-1].append(card) n += 1
class CardDemo(Frame): def __init__(self): """Sets up the window and widgets.""" Frame.__init__(self) self.master.title("Card Demo") self.grid() self._deck = Deck() self._backImage = PhotoImage(file = Card.BACK_NAME) self._cardImage = None self._imageLabel = Label(self, image = self._backImage) self._imageLabel.grid(row = 0, column = 0, rowspan = 3) self._textLabel = Label(self, text = "") self._textLabel.grid(row = 3, column = 0) self._dealButton = Button(self, text = "Deal", command = self._deal) self._dealButton.grid(row = 0, column = 1) self._shuffleButton = Button(self, text = "Shuffle", command = self._shuffle) self._shuffleButton.grid(row = 1, column = 1) self._newButton = Button(self, text = "New Deck", command = self._new) self._newButton.grid(row = 2, column = 1) def _deal(self): """If the deck is not empty, deals and displays the next card. Otherwise, returns the program to its initial state.""" card = self._deck.deal() if card != None: self._cardImage = PhotoImage(file = card.fileName) self._imageLabel["image"] = self._cardImage self._textLabel["text"] = str(card) else: self._new() def _shuffle(self): self._deck.shuffle() def _new(self): """Returns the program to its initial state.""" self._deck = Deck() self._cardImage = None self._imageLabel["image"] = self._backImage self._textLabel["text"] = ""
def pop_card(self): #All cards are used create an new deck of cards if self.deck.cards_left() == 0: self.deck = Deck(self.number_of_decks) self.deck.shuffle() return self.deck.pop_card()
def __init__(self): """Sets up the window and widgets.""" Frame.__init__(self) self.master.title("Card Demo") self.grid() self._deck = Deck() self._backImage = PhotoImage(file = Card.BACK_NAME) self._cardImage = None self._imageLabel = Label(self, image = self._backImage) self._imageLabel.grid(row = 0, column = 0, rowspan = 3) self._textLabel = Label(self, text = "") self._textLabel.grid(row = 3, column = 0) self._dealButton = Button(self, text = "Deal", command = self._deal) self._dealButton.grid(row = 0, column = 1) self._shuffleButton = Button(self, text = "Shuffle", command = self._shuffle) self._shuffleButton.grid(row = 1, column = 1) self._newButton = Button(self, text = "New Deck", command = self._new) self._newButton.grid(row = 2, column = 1)
def __init__(self, name, sb=1, bb=2, ante=0, max_players=6, players=None, min_buyin=None, max_buyin=None): self.id = name self.name = name self.sb = sb self.bb = bb self.ante = ante self.min_buyin = min_buyin or 50*bb self.max_buyin = max_buyin or 200*bb self.players = [None] * max_players if players: for i, p in enumerate(players): self.players[i] = p # http://www.learn-texas-holdem.com/questions/blind-rules-when-players-bust-out.htm self.owes_bb = set() self.owes_sb = set() # individual hand state self.deck = Deck() self.game_state = { "sb_idx": None, "bb_idx": None, "board": [] } self.games = [HandHistory()]
def __init__(self, dealer, tricks=None, hands=None, round_state=None, called_trump=None, trump=None, turn=None, maybe_trump=None, going_alone=None): deck = Deck() self.tricks = tricks or [] self.hands = hands or [Hand(deck.deal(5)) for x in range(4)] # Other valid states: "bid2", "play", "end" self.round_state = round_state or "bid" self.called_trump = called_trump or None # Nobody has called trump yet self.trump = trump or None # Initially, there is no trump self.dealer = dealer # Player num self.turn = turn or (dealer + 1) % 4 # Who starts? # The card that might be trump self.maybe_trump = maybe_trump or deck.deal(1)[0] # Is the player who called trump going alone? self.going_alone = going_alone or False
def new_hand(self): self.log("===Starting hand {}===".format(len(self.games))) self.games.append(HandHistory()) self.game_state['board'] = [] self.deck = Deck() self.new_street() for player in self.get_active_players(): player.new_hand()
def __init__(self, players=None): self.game_over = False cards = Deck() divided_cards = cards.split_equally(4) if players is None: players = [DumbAI(hand=Hand(cards_list=hand), name='Player %s' % index) for index, hand in enumerate(divided_cards)] if all(player.hand is None for player in players): for idx, player in enumerate(players): player.hand = divided_cards[idx] self.players = players for player in self.players: player.create_players([p.name for p in self.players]) print(*['%s - %s' % (player.name, player.hand) for player in self.players], sep='\n') self.present_trick = Trick(len(self.get_player_still_game()))
def __init__(self): self.deckStyle = 'French' self.deck = Deck(self.deckStyle) self.playerLimit = [3,4,5,6,7] self.handLimit = [11,13,15,17,19,21,23] super(Rules, self).__init__() self.handCounter = 0 self.hands = [Hand(n, self.handLimit) for n in range(self.handLimit)]
def test_noargs(self): # if no args are given then the deck should be initialized to 52 cards x = Deck() self.assertEqual(len(x), 52) expected_elements = list(Deck.iter_cards()) self.assertListEqual(x, expected_elements) rlock_type = type(threading.RLock()) self.assertIs(type(x.lock), rlock_type)
def __init__(self,h,n=5,b=1): self.Stat = Stats() self.number_of_decks = n self.house = h self.players = [] self.deck = Deck(self.number_of_decks) self.minimum_bet = b self.deck.shuffle()
def test_full(self): x = Deck() split_1 = 20 split_2 = 30 chunk1 = x[:split_1] chunk2 = x[split_1:split_2] chunk3 = x[split_2:] before = set(x) x.shuffle_3waycut(split_index_1=split_1, split_index_2=split_2) after = set(x) self.assertSetEqual(before, after) # make sure that each chunk is preserved in the deck chunks = [chunk1, chunk2, chunk3] for chunk in chunks: index = x.index(chunk[0]) sublist = x[index:index+len(chunk)] self.assertListEqual(sublist, chunk)
def __init__(self): super(Rules, self).__init__() self.deckStyle = 'French' self.deck = Deck(self.deckStyle) print self.deck self.playerLimit = [4] self.gameLimit = 0 self.roundLimit = 0 self.handLimit = 0
def cah_madlib(self, server, event, bot): '''Entertaining function for dev, delete later.''' d = Deck() b = d.draw("black") madlib = b.body blanks = b.num_answers if blanks == 0: madlib += ' ' + d.draw("white").body.rstrip('.') elif madlib.count('_') == 0: madlib += ' ' + ', '.join([d.draw("white").body.rstrip('.') for x in range(blanks)]) else: replacements = [] madlib = madlib.replace("%","%%").replace("_", "%s") for i in range(blanks): replacements.append("\x02\x1F%s\x0F" % d.draw("white").body.rstrip('.')) madlib = madlib % tuple(replacements) server.privmsg(event.target, madlib)
def __init__(self): # Create the deck self.deck = Deck(6) # Create the player self.player = Player(self.deck) # Create the dealer self.dealer = Dealer(self.deck, [self.player])
class DeckGUI(EasyFrame): def __init__(self): EasyFrame.__init__(self, title = "Testing a Deck Display") self.setSize(350, 200) self.deck = Deck() self.card = self.deck.deal() self.image = PhotoImage(file = self.card.fileName) self.cardImageLabel = self.addLabel("", row = 0, column = 0) self.cardImageLabel["image"] = self.image self.cardNameLabel = self.addLabel(row = 1, column = 0, text = self.card) self.button = self.addButton(row = 0, column = 1, text = "Next Card", command = self.nextCard) self.button = self.addButton(row = 1, column = 1, text = "Shuffle", command = self.shuffleDeck) self.button = self.addButton(row = 2, column = 1, text = "New Deck", command = self.newDeck) def nextCard(self): """Deals a card from the deck and displays it, or displays the back side if empty.""" if len(self.deck) == 0: self.image = PhotoImage(file = Card.BACK_NAME) self.cardNameLabel["text"] = 'Empty' else: self.card = self.deck.deal() self.image = PhotoImage(file = self.card.fileName) self.cardNameLabel["text"] = self.card self.cardImageLabel["image"] = self.image def shuffleDeck(self): """Shuffles the existing deck of cards.""" self.deck.shuffle() def newDeck(self): """Creates a new Deck object, assigns it to the window's deck, and updates the card images appropriately.""" self.deck = Deck()
class Rules(Game): """Rules for the game of 500""" def __init__(self): super(Rules, self).__init__() self.deckStyle = 'French' self.deck = Deck(self.deckStyle) print self.deck self.playerLimit = [4] self.gameLimit = 0 self.roundLimit = 0 self.handLimit = 0 def deck(self): for cards in [(0,2),(1,2),(2,2),(3,2),(0,3),(1,3),(2,3),(3,3),(0,4),(1,4)]: card = Card(self.deckStyle, cards[0], cards[1]) self.deck.remove(card) def dealing(self, players): for player in range(self.playerLimit): return player
def setup(self, decks, games): ## Call shuffle deck = Deck().deck for game in range(0, games): # deal player_cards = [] dealer_cards = [] for card in range(0,2): player_cards.append(deck.pop()) dealer_cards.append(deck.pop()) # call player logic player_score = self.player_logic(player_cards, deck, dealer_cards[0]) dealer_score = self.dealer_logic(dealer_cards, deck) for card in player_cards: print card for card in dealer_cards: print card print "Player score {0}".format(player_score) print "Dealer score {0}".format(dealer_score) if player_score > 21: print "Dealer Wins :(" else: if dealer_score > 21: print "PLAYER WINS!! :D" else: if player_score > dealer_score: print "PLAYER WINS!! :D" else: print "Dealer Wins :(" if game % 5 == 0: print "reshuffle!"