def test_shuffle_then_order_mysort_full_deck(self): d1 = cards.Deck() d2 = cards.Deck() d2.shuffle_deck() d2.quick_sort_deck() self.assertEqual(d1, d2, "Shuffled deck did not reorder on order() call")
def deal_cards(self): # Build the deck and shuffle it print "Deal: " + str(self.deck) self.deck = c.Deck() self.deck.shuffle() print "Deal2: " + str(self.deck) # Extra deck used for holding discarded cards self.deck2 = c.Deck() del self.deck2.cards[:] # Deal the cards to the players self.phenny.say("The dealer begins dealing...") p.deal(self.deck, self.num_cards) for uid in p.in_game: self.phenny.write(('NOTICE', p.players[uid].name + " Your Hand: %s" % p.players[uid].hand)) p.in_game = p.in_game[::-1] self.phenny.say("The dealer has dealt each player " + str(self.num_cards) + " cards.") self.betting_stage = 1 if self.stakes != "free": self.betting_round() else: self.draw_round()
def main(): # Welcome message print_welcome_msg() # Setup global variables play_with_holecards = False player_money = 100 ndecks = 2 nround = 0 # Setup Deck bdeck = cards.Deck(ndecks) # Start round loop while player_money > 0: print("Round " + str(nround)) print("You have " + str(player_money) + " chips.") if bdeck.number_cards_left < 8: bdeck = cards.Deck(ndecks) if want_another_round(): win, bet = play_round(bdeck, player_money, play_with_holecards) if win: player_money += bet else: player_money -= bet nround += 1 else: print("You left the table with " + str(player_money) + " chips.") return print("You lost the game.") return
def assertPoints(suits, ranks, isCrib, points): cards = [] for i in range(len(suits)): cards.append(cds.Card(suits[i], ranks[i])) hand = cds.Deck(cards[:4]) face = cds.Deck([cards[-1]]) calculatedPoints, pointString = Cribbage.points(hand, face, isCrib) if calculatedPoints != points: print(pointString) assert calculatedPoints == points
def setup(): ''' paramaters: None returns a tuple of: - a foundation (list of 4 empty lists) - a tableau (a list of 7 lists, each sublist contains 3 cards, and the first two cards of each list should be set to hidden) - a stock contains a list of 31 cards. (after dealing 21 cards to tableau) ''' fdation = [[], [], [], []] #Sets foundation, tableau and stock to empty lists tableau = [] stock = [] Deck = cards.Deck() #Creates our deck of cards Deck.shuffle() #Shuffle the deck for i in range( 7 ): #Create 7 lists of 3 cards each, first 2 of each list are hidden a = Deck.deal() b = Deck.deal() c = Deck.deal() a.set_hidden() b.set_hidden() tableau.append([a, b, c]) for c in range(31): #"Deal" the remaining cards into the stock list c = Deck.deal() stock.append(c) return fdation, tableau, stock
def setup(): """ paramaters: None returns: - a foundation (list of 4 empty lists) - cell (list of 4 empty lists) - a tableau (a list of 8 lists, the dealt cards) """ game_deck = cards.Deck() game_deck.shuffle() # Initialize tableau, foundation, and cell tableau = [[], [], [], [], [], [], [], []] foundation = [[], [], [], []] cell = [[], [], [], []] # Create the tableau with eight columns, four of 7 cards, four of 6 column = 0 while not game_deck.is_empty(): tableau[column].append(game_deck.deal()) column += 1 if column % 8 == 0: # Resets to column 0 after column 8 column = 0 return foundation, tableau, cell
def setup_game(): """ The game setup function. It has 4 cells, 4 foundations, and 8 tableaus. All of these are currently empty. This function populates the tableaus from a standard card deck. Tableaus: All cards are dealt out from left to right (meaning from tableau 1 to 8). Thus we will end up with 7 cards in tableaus 1 through 4, and 6 cards in tableaus 5 through 8 (52/8 = 6 with remainder 4). This function will return a tuple: (cells, foundations, tableaus) """ #You must use this deck for the entire game. #We are using our cards.py file, so use the Deck class from it. stock = cards.Deck() #The game piles are here, you must use these. cells = [[], [], [], []] #list of 4 lists foundations = [[], [], [], []] #list of 4 lists tableaus = [[], [], [], [], [], [], [], []] #list of 8 lists """ YOUR SETUP CODE GOES HERE """ stock.shuffle() count = 0 for i in range(52): dealt = stock.deal() if count > 7: count = 0 tableaus[count].append(dealt) count += 1 else: tableaus[count].append(dealt) count += 1 return cells, foundations, tableaus
def test_deal_card(self): d1 = cards.Deck() d1.shuffle() c1 = d1.deal_card() self.assertEqual(len(d1.cards), 51) self.assertNotIn(c1, d1.cards)
def setup(): """ paramaters: None (deck can be created within this function) returns: - a foundation (list of 4 empty lists) - cell (list of 4 empty lists) - a tableau (a list of 8 lists, the dealt cards) """ my_deck = cards.Deck() my_deck.shuffle() foundation = [[], [], [], []] cell = [[], [], [], []] tableau = [[], [], [], [], [], [], [], []] for i in range(6): tableau[0].append(my_deck.deal()) tableau[1].append(my_deck.deal()) tableau[2].append(my_deck.deal()) tableau[3].append(my_deck.deal()) tableau[4].append(my_deck.deal()) tableau[5].append(my_deck.deal()) tableau[6].append(my_deck.deal()) tableau[7].append(my_deck.deal()) tableau[0].append(my_deck.deal()) tableau[1].append(my_deck.deal()) tableau[2].append(my_deck.deal()) tableau[3].append(my_deck.deal()) return foundation,tableau,cell
def start(self, num_players, wallet_amt, ante_amt): ''' Instructs the server to set up a game of poker with the given number of players and to give each player the specified amount of money to start. This is the only command available in the server at start-up. Once called, the server moves into a state of waiting for the remaining players to join. num_players: int - Number of players in the game. Min: 2, Max: 5 wallet_amt: int - Initial amount of money in each player's wallet. Basically, the buy in amount. Min: 5 ante_amt: int - The amount each player needs to ante per round. ''' self.num_players = num_players self.wallet_amt = wallet_amt self.ante_amt = ante_amt self.deck = cards.Deck() self.players = dict() self.final_hands = dict() self.next_id = 1 # incremented when players join self.bets = BetInfo() self.turn_id = 1 # ID of the player who's turn it is self.folded_ids = set( ) # IDs of players who have folded during betting self.left_ids = set() self.card_val = {} # record the number of cards for each player
def main(argv): # Parse command line arguments addr = get_cmd_args(argv) # Setup server sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bind(addr) sock.listen() print('Server started, waiting for player.') players = [] players.append(player.Player(1)) players.append(player.Player(2)) # Wait for `start` from a player and set-up game conn = wait_for_start(sock, players) print(players) #Initiate deck deck = cards.Deck() # Deal the cards handle_deal(players, deck, conn) # Get the landlord landlord = handle_landlord(players, deck, conn) # Game play game_play(players, landlord, conn)
def setup_game(): """ The game setup function. It has 4 cells, 4 foundations, and 8 tableaus. All of these are currently empty. This function populates the tableaus from a standard card deck. Tableaus: All cards are dealt out from left to right (meaning from tableau 1 to 8). Thus we will end up with 7 cards in tableaus 1 through 4, and 6 cards in tableaus 5 through 8 (52/8 = 6 with remainder 4). This function will return a tuple: (cells, foundations, tableaus) """ #You must use this deck for the entire game. #We are using our cards.py file, so use the Deck class from it. stock = cards.Deck() # takes cards from deck stock.shuffle() # shuffle cards every time setup_game() function is called #The game piles are here, you must use these. cells = [[], [], [], []] #list of 4 lists foundations = [[], [], [], []] #list of 4 lists tableaus = [[], [], [], [], [], [], [], []] #list of 8 lists """ YOUR SETUP CODE GOES HERE """ while len(stock) > 0: # deals the deck into tableaus for item in tableaus: item.append(stock.deal()) if len(stock) == 0: break return cells, foundations, tableaus
def setup_game(): """ The game setup function. It has 4 cells, 4 foundations, and 8 tableaus. All of these are currently empty. This function populates the tableaus from a standard card deck. Tableaus: All cards are dealt out from left to right (meaning from tableau 1 to 8). Thus we will end up with 7 cards in tableaus 1 through 4, and 6 cards in tableaus 5 through 8 (52/8 = 6 with remainder 4). This function will return a tuple: (cells, foundations, tableaus) """ stock = cards.Deck() #initilize the deck # stock.shuffle() #shuffles the deck cells = [[], [], [], []] #list of 4 lists foundations = [[], [], [], []] #list of 4 lists tableaus = [[], [], [], [], [], [], [], []] #list of 8 lists """ YOUR SETUP CODE GOES HERE """ while len(stock) != 0: #loops while the deck is not empty for item in tableaus: item.append(stock.deal()) #adds a card to each tableau from left to right until there are no cards left if len(stock) == 0: #stops when the deck is empty break return cells, foundations, tableaus #returns 3 lists of lists
def setup_game(): """ The game setup function. It has 4 cells, 4 foundations, and 8 tableaus. All of these are currently empty. This function populates the tableaus from a standard card deck. Tableaus: All cards are dealt out from left to right (meaning from tableau 1 to 8). Thus we will end up with 7 cards in tableaus 1 through 4, and 6 cards in tableaus 5 through 8 (52/8 = 6 with remainder 4). This function will return a tuple: (cells, foundations, tableaus) """ #You must use this deck for the entire game. #We are using our cards.py file, so use the Deck class from it. stock = cards.Deck() stock.shuffle() #The game piles are here, you must use these. cells = [[], [], [], []] #list of 4 lists foundations = [[], [], [], []] #list of 4 lists tableaus = [[], [], [], [], [], [], [], []] #list of 8 lists """ YOUR SETUP CODE GOES HERE """ # counter initialized at 1 # card_count = 1 for j in range(7): for i in range(8): if card_count < 53: #deals cards left to right # tableaus[i].append(stock.deal()) # one added to card count ( to change rows ) # card_count += 1 return cells, foundations, tableaus
def setup_game(): """ The game setup function. It has 4 cells, 4 foundations, and 8 tableaus. All of these are currently empty. This function populates the tableaus from a standard card deck. Tableaus: All cards are dealt out from left to right (meaning from tableau 1 to 8). Thus we will end up with 7 cards in tableaus 1 through 4, and 6 cards in tableaus 5 through 8 (52/8 = 6 with remainder 4). This function will return a tuple: (cells, foundations, tableaus) """ stock = cards.Deck() cells = [[], [], [], []] #list of 4 lists foundations = [[], [], [], []] #list of 4 lists tableaus = [[], [], [], [], [], [], [], []] #list of 8 lists n = 0 #start on left tableau #deals card and then moves right a tableau while len(stock) > 0: tableaus[n].append(stock.deal()) n += 1 #returns back to first tableau if n == 8: n -= 8 return cells, foundations, tableaus
def start(): the_deck = cards.Deck() the_deck.shuffle() print( "===== shuffled deck =====" ) the_deck.display() return the_deck
def deal(self, deck=None): self.deck = deck or cards.Deck() self.pot = 0 self.upcards = [] self.winners = None self.dealer_button = self.nextfrom(self.dealer_button) for ps in self.players: ps.hand = cards.Hand() ps.folded = False ps.bet_this_round = 0 ps.played_this_round = False self.total_bet_this_round = 0 self.callback('deal') # deal two cards to each player for i in range(len(self.players) * 2): # start with the dealer button and rotate r = self.nextfrom(self.dealer_button, i + 1) self.players[r].hand.append(self.deck.deal()) # play the blinds self.next_to_act = self.nextfrom(self.dealer_button) self.playing_blinds = True self.putmoneyin(self.small_blind, is_small_blind=True) self.putmoneyin(self.big_blind, is_big_blind=True) self.playing_blinds = False self.callback('next_to_act', self.next_to_act, self.big_blind)
def play(pool_size=10, variant='rostov'): """ """ # Initialize new game pool_closed = False pls = [players.Player(ai=True), players.Player(ai=True), players.Player()] d = cards.Deck() first = W turn = W # Play while not pool_closed: # TODO: change to keep track of score hands, blind = d.deal() for i in range(3): # Deal in proper order: from first hand onwards pls[(i + turn) % 3].set_hand(hands[i]) # Bidding bidding = True bids = [None, None, None] while bidding: if not pls[turn].ai: draw_table( first=first, bidding=True, bids=bids, # blind=blind, hands=[pls[W].ncards(), pls[E].ncards(), pls[S].hand]) pls[turn].make_bid(turn, bids) turn = (turn + 1) % 3
def __init__(self, game_id, players, waiting_room, starting_number_of_cards=50): """ :param game_id: The ID of the game. :param players: A dict of players with the key as player id and the player name as the value. :param waiting_room: The waiting room that the game was made in. :param starting_number_of_cards: The number of cards each player starts with. """ self.game_id = game_id self.waiting_room = waiting_room self.starting_number_of_cards = starting_number_of_cards self.players = [] self.observers = [] # setting up cards self.deck = cards.Deck(self) self.played_cards = CardCollection() self.deck.add_random_cards_to(self.played_cards, 1, dynamic_weights=False) self.planning_pile = CardCollection() self.pickup = 0 # setup players and turn system if len(players) < 2: print("WARNING: 2 or more players are needed to make the game work properly") for player in players: new_player = Player(self, players[player], player) self.players.append(new_player) new_player.add_new_cards(self.starting_number_of_cards, False) self.player_turn_index = random.randint(0, len(self.players) - 1) self.turn = self.players[self.player_turn_index] self.turn.start_turn() self.direction = 1 # 1 or -1 self.iterate_turn_by = 1
def init_game(): ''' That function has no parameters. It creates and initializes the stock, tableau, and foundation, and then returns them as a tuple, in that order. Return a tuple (stock, tableau, foundation) for a new game, where - stock is a shuffled deck minus the 4 cards dealt to the tableau - foundation is an empty list - tableau is a list of lists, each containing one of the dealt cards ''' # call cards class Deck function to initialize the sotck stock = cards.Deck() stock.shuffle() # call shuffle function to shuffle the stock # initialize the lists foundation = [] tableau1 = [] tableau2 = [] tableau3 = [] tableau4 = [] # deal the card and initialize the tableau tableau1.append(stock.deal()) tableau2.append(stock.deal()) tableau3.append(stock.deal()) tableau4.append(stock.deal()) # store tableaus in the list tableau tableau = [tableau1, tableau2, tableau3, tableau4] return (stock, tableau, foundation)
def setup_game(): """ The game setup function, it has 4 foundation piles, 7 tableau piles, 1 stock and 1 waste pile. All of them are currently empty. This function populates the tableau and the stock pile from a standard card deck. 7 Tableau: There will be one card in the first pile, two cards in the second, three in the third, and so on. The top card in each pile is dealt face up, all others are face down. Total 28 cards. Stock: All the cards left on the deck (52 - 28 = 24 cards) will go into the stock pile. Waste: Initially, the top card from the stock will be moved into the waste for play. Therefore, the waste will have 1 card and the stock will be left with 23 cards at the initial set-up. This function will return a tuple: (foundation, tableau, stock, waste) """ # you must use this deck for the entire game. # the stock works best as a 'deck' so initialize it as a 'deck' stock = cards.Deck() # the game piles are here, you must use these. foundation = [[], [], [], []] # list of 4 lists tableau = [[], [], [], [], [], [], []] # list of 7 lists waste = [] # one list # your setup code goes here #pass # stub; delete and replace it with your code tableau.append(stock.deal()) return foundation, tableau, stock, waste
def playCheck(self): #Resets Player knowledge currentPlayer = self.players[self.currentTurn] currentPlayer.passOptions = [] currentPlayer.negateOptions = [] currentPlayer.options = cards.Deck().cards #Checks each rule and which cards they use for erule in self.ruleList: for ecard in erule.usesCards: #If pile card has an associated effect if (self.pile[0].value == ecard.value and self.pile[0].suit == ecard.suit): #Effect executed strategy = Effects.Strategy(self, erule) newOptions = strategy.run() #Set union operation builder = [] for old in currentPlayer.options: for opt in newOptions: if (opt.value == old.value and opt.suit == old.suit): builder.append(old) currentPlayer.options = builder currentPlayer.passOptions.extend(erule.passes) currentPlayer.negateOptions.extend(erule.negates)
def setup_game(): """ The game setup function. It has 4 cells, 4 foundations, and 8 tableaus. All of these are currently empty. This function populates the tableaus from a standard card deck. Tableaus: All cards are dealt out from left to right (meaning from tableau 1 to 8). Thus we will end up with 7 cards in tableaus 1 through 4, and 6 cards in tableaus 5 through 8 (52/8 = 6 with remainder 4). This function will return a tuple: (cells, foundations, tableaus) """ # You must use this deck for the entire game. # We are using our cards.py file, so use the Deck class from it. stock = cards.Deck() stock.shuffle() # The game piles are here, you must use these. cells = [[], [], [], []] # list of 4 lists foundations = [[], [], [], []] # list of 4 lists tableaus = [[], [], [], [], [], [], [], []] # list of 8 lists hand = stock.__str__().replace(' ', '') hand = hand.split(',') """ YOUR SETUP CODE GOES HERE """ stock.shuffle() for x in range(len(hand)): tableaus[int(x % 8)].append(hand[x]) return cells, foundations, tableaus
def play(): if playing: deck = cards.Deck() comp = player.Player() human = player.Player() bet = place_the_bet(human) print("Your bet is {}".format(bet)) deal(comp, human, deck) print("Your {}".format(human.show_first_deal())) print("Computer's {}".format(comp.show_first_deal_private())) if push(human, comp): print("The game tied") replay(human, comp) if (check_for_bust(human) == 3): print("You lose the game") replay(human, comp) elif (check_for_bust(human) == 2): print("You won the game") replay(human, comp) while playing: players_play(human, comp, deck, bet) if playing: comps_play(human, comp, deck, bet)
def create_deck(json): deck_list = [] for c in json: card = cards.MonsterCard(c.get('name'), c.get('id'), c.get('atk'), c.get('defn'), c.get('level')) deck_list.append(card) deck = cards.Deck(deck_list, shuffle=False) return deck
def test_repr(self): deck = cards.Deck() deckrep = repr(deck) cardstrings1 = [rank+suit for rank, suit in zip(deckrep[::2], deckrep[1::2])] cardstrings2 = [repr(x) for x in deck[:]] self.assertEqual(cardstrings1, cardstrings2)
def create_stacked_deck(hands_wanted_strings, upcards_wanted_string): # create an actual deck to pull the cards from; this is so that we don't # duplicate cards, and end up with the correct number of cards in the # deck. unused_cards = cards.Deck(shuffle=False) hands_wanted = [] for s in hands_wanted_strings: h = cards.Hand(s) hands_wanted.append(h) for c in h: unused_cards.popcard(c.rank, c.suit) upcards_wanted = cards.Hand(upcards_wanted_string) for c in upcards_wanted: unused_cards.popcard(c.rank, c.suit) newdeck = cards.Deck(deckcount=0) def addcard(c=None): if c: newdeck.append(c) else: # deal something out of unused_cards c = unused_cards.pop() newdeck.append(c) for hand in hands_wanted: addcard(hand[0]) for hand in hands_wanted: addcard(hand[1]) # burn, flop, burn, turn, burn, river. addcard() for i in range(3): addcard(upcards_wanted.pop()) addcard() addcard(upcards_wanted.pop()) addcard() addcard(upcards_wanted.pop()) # add the remaining cards from the deck while len(unused_cards): addcard(unused_cards.deal()) return newdeck
def __init__(self, uid=None): self.hand = [] self.options = cards.Deck().cards self.passOptions = [] self.negateOptions = [] self.played = True #Assigned dynamically self.uid = uid
def __init__(self): self.board = game_board.Interface() self.win = self.board.getWindow() self.deck = cards.Deck() self.king_deck = cards.KingDeck() self.king_deck.shuffle() self.user_hand = cards.Hand() self.computer_hand = cards.Hand()
def __init__(self): self.deck = cards.Deck() self.deck.populate() self.deck.shuffle() self.deck.stack() #for grading self.players = [] self.dealer_hand = cards.Hand() self.start()