def __init__(self, players: List[Player]): self.deck = pyCardDeck.Deck() self.deck.load_standard_deck() self.players = players self.scores = {} self.add_deck = pyCardDeck.Deck() #new object used for add deck. self.add_deck.load_standard_deck() num = randint(6, 8) for i in range(num - 1): self.deck.add_many(self.add_deck) #total pack of cards for i in range(num): self.deck.draw print("Created a game with {} players.and{}pack of cards".format( len(self.players), num))
def __init__(self, players: List[Player]): self.deck = pyCardDeck.Deck(cards=generate_deck(), name='Poker deck', reshuffle=False) self.players = players self.table_cards = [] print("Created a table with {} players".format(len(self.players)))
def __init__(self, players: List[Player]): self.deck = pyCardDeck.Deck() self.deck.load_standard_deck() self.players = players self.scores = {} print("Game has been created with {} players.".format(len( self.players)))
def __init__(self, players: List[Player]): self.deck = pyCardDeck.Deck( cards=generate_deck()*6, #since 6 decks of cards are in spanish 21 name='Spanish21 deck', reshuffle=False)) self.players = players self.scores = {} print("Created a game with {} players.".format(len(self.players)))
def __init__(self, players): self.players = list(range(1, players)) self.deck = pyCardDeck.Deck(cards=generate_initial_deck(), name='Poker Game', reshuffle=False) self.table_cards = [] self.hand = [] print("This is a poker table with {} players".format(players))
def __init__(self, players: list): self.deck = pyCardDeck.Deck() self.players = players self.prepare_cards() self.deal_to_players() self.add_defuses() self.add_explodes() while len(self.players) > 1: self.play()
def __init__(self, persons: List[Person]): self.d = pyCardDeck.Deck() self.d.load_standard_deck() for i in range(44) bur = self.deck.draw() if bur == 10: self.deck.discard(bur) self.persons = persons self.scores = {} print("Lets play a game with {} pppl.".format(len(self.persons)))
def __init__(self, players: List[Player]): self.deck = pyCardDeck.Deck() self.deck.load_standard_deck() for i in range(52) burned = self.deck.draw() if burned == 10: self.deck.discard(burned) self.players = players self.scores = {} print("Created a game with {} players.".format(len(self.players)))
def __init__(self, players, deck): self.players = players self.deck = pyCardDeck.Deck(deck) self.deck.shuffle() self.deal_cards() top_card = self.deck.draw() if top_card.color == "choose ": top_card.color = "red " #for simplicity, completely arbitrary self.discard = top_card self.plus_cards = 0 self.discarded = []
def __init__(self, **kwargs): self.name = kwargs.get("name", "My Tarot Deck") self.suits = kwargs.get("suits", ["Cups", "Wands", "Swords", "Pentacles"]) self.values = kwargs.get("values", ["Ace"] + [str(x) for x in range(2, 11)] + ["Page", "Knight", "Queen", "King"]) self.cards = [] for suit in self.suits: for value in self.values: self.cards.append("{} of {}".format(value, suit)) self.deck = pyCardDeck.Deck(cards=self.cards, name=self.name, reshuffle=False)
def __init__(self, players: list, verbose: bool = True): self.verbose = verbose self.deck = pyCardDeck.Deck() self.players = players self.prepare_cards() self.deck.shuffle() self.deal_to_players() self.add_defuses() self.add_explodes() self.deck.shuffle() self.last_card = None #print([c.name for c in self.deck]) while 1 < len(self.players) < len(self.deck): self.play() if self.verbose: print('The winner is', self.players[0].name)
def create_even_decks(): deck = pyCardDeck.Deck() deck.load_standard_deck() ranks = [2, 3, 4, 5, 6, 7, 8, 9, 10, "J", "Q", "K"] suits = ["Spades", "Diamonds", "Clubs", "Hearts"] index = 0 hand1 = [] hand2 = [] for r in ranks: index += 1 for suit in suits: card = Spades.create_card(suit, r) if index % 2 == 0: hand1.append(card) else: hand2.append(card) return [hand1, hand2]
def __init__(self): init() # colorama self.deck = pyCardDeck.Deck() self.deck.load_standard_deck() self.deck.shuffle() self.foundations = {} self.foundations["Hearts"] = [] self.foundations["Clubs"] = [] self.foundations["Diamonds"] = [] self.foundations["Spades"] = [] self.tableau = [] self.numHiddenTableau = [] for i in range(7): self.tableau.append([]) self.numHiddenTableau.append(i) for i in range(7): for j in range(i, 7): self.tableau[j].append(self.deck.draw()) self.hand = [] self.discard = [] self.ranks = { "A": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7, "8": 8, "9": 9, "10": 10, "J": 11, "Q": 12, "K": 13 } self.shortSuit = { "Hearts": "H", "Clubs": "C", "Diamonds": "D", "Spades": "S" }
def __init__(self, players: List[Agent], verbose=False, simple_scoring=False, even_decks=False): """ :param players: List of Agents to play a simulated game :param verbose: will print out satements on game acitojns :param simple_scoring: If true will just score based on who wins the most tricks """ self.deck = pyCardDeck.Deck() self.deck.load_standard_deck() self.players = players self.bets = Spades.initialize_player_dict(players) self.scores = Spades.initialize_player_dict(players) self.verbose = verbose self.initial_state = True self.player_won_last_hand = None self.board = {} self.order_played = {} self.final_scores = Spades.initialize_player_dict(players) self.simple_scoring = simple_scoring self.even_decks = even_decks Spades.assert_unique_index(players)
def __init__(self, players: List[Player]): self.deck = pyCardDeck.Deck(cards=generate_Card(), name="five cards draw") self.players = players self.deck.shuffle() print("Created a table with {} players".format(len(self.players)))
def take_turn(self): if self.deck.cards_left < 10: self.deck = pyCardDeck.Deck(discarded).shuffle() self.discarded = [] print("\nDISCARD PILE") print(self.discard) time.sleep(2) colors = ["red ", "yellow ", "green ", "blue "] player = self.players[0] valid_plays = [card for card in player.cards if Card.is_valid_play(card, self.discard)] if valid_plays == []: card_drawn = self.deck.draw() print(player.name + " drew a card.\n") time.sleep(1) if Card.is_valid_play(card_drawn, self.discard): player.cards.append(card_drawn) valid_plays.append(card_drawn) else: if Card.is_adder(self.discard): self.discard.played = True for _ in range(self.plus_cards): player.cards.append(self.deck.draw()) if self.plus_cards > 0: print(player.name + " had to draw " + str(self.plus_cards) + " cards!") time.sleep(2) self.plus_cards = 0 self.shift_players() return if player.is_computer: card = valid_plays[randint(0, len(valid_plays) - 1)] if card.color == "choose ": card.color = colors[randint(0, 3)] else: print("\nYOUR HAND") Player.print_cards(player) index = input("\nPlay a card by typing a number between 1 and the number of cards in your hand: ").strip() while not isinstance(int(index), int): index = input("\nThat wasn't a valid number. Try again: ").strip() index = int(index) - 1 card = player.cards[index] while card not in valid_plays: index = int((input("\nSorry, that's not a valid play. Try again: ")).strip()) - 1 card = player.cards[index] if card.color == "choose ": print("What's the next color?") letter = (input("Type r for red, y for yellow, g for green, or b for blue: ")).strip() for color in colors: if letter == color[0]: # "red ", "yellow ", "blue ", "green " card.color = color if Card.is_adder(card): for i in range(int(card.value[4])): # "plus2 " or "plus4 " at index 4 gives num of cards self.plus_cards += 1 print("\n" + player.name + " played a " + "\n") print(card) self.discarded.append(self.discard) self.discard = card player.cards.remove(card) self.effect()
def __init__(self, person: List[Person]): self.d = pyCardDeck.Deck() self.d.load_standard_deck() self.person = persons self.score = {} print("lets make a game with {} people.".format(len(self.persons)))
from typing import List from pyCardDeck.cards import PokerCard class Game: def __init__(self, name_g: str): self.hand = [] self.name_g = name def __str__(self): return self.name_g class BlackjackGame: def __init__(self, games: List[Game]) self.deck = pyCardDeck.Deck() self.deck.load_standard_deck() self.games = game self.points = {} print("Created a game with {} players.".format(len(self.games))) def blackjack(self): """ The main blackjack game sequence. Each player takes an entire turn before moving on. """ print("Starting...") print("Shuffling...")
def __init__(self, players: List[Player]): self.deck = pyCardDeck.Deck() self.deck.load_standard_deck() self.players = players self.scores = {} print(f"Created a game with {self.players} players.")
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ This is an example of pyCardDeck, it's not meant to be complete poker script, but rather a showcase of pyCardDeck's usage. """ import pyCardDeck import random import requests arena_deck = pyCardDeck.Deck(reshuffle=False, name="Awesome arena deck!") rarity = {"Common": 100, "Rare": 50, "Epic": 15, "Legendary": 1} def card_choice() -> list: """ Picks a rarity, then lets you make a choice :return: List with the card information """ pick_rarity = random.choice([k for k in rarity for _ in range(rarity[k])]) # This api doesn't provide an easy way to get class and rarity filter at the same time # and I'm too lazy to look for another, reminder: this is an example cards = requests.get( "https://omgvamp-hearthstone-v1.p.mashape.com/cards/qualities/{}". format(pick_rarity), headers={ "X-Mashape-Key": "GkQg9DFiZWmshWn6oYqlfXXlXeK9p1QuB6QjsngIi1sHnJiJqv" }).json()
def main(): print("...Initialize State") state = GameState() # order order = [0, 1, 2, 3] for i in range(0, 1): print("...Round " + str(i)) # initialize in initial order ai_list = [SpadesAI(x) for x in range(0, 4)] # initialize deck deck = pyCardDeck.Deck() deck.load_standard_deck() print("...Loading and Shuffling Deck") # shuffle deck.shuffle() # deal hands print("...Dealing Hands") for ai in ai_list: # 12 cards in each hand for counter in range(0, 13): ai.hand.append(deck.draw()) # from here on out, we follow the order # get bets for p_number in order: print("...Player " + str(p_number) + " betting") state.bets[p_number] = ai_list[p_number].bet(state) # 7 plays per player in a round for play in range(0, 13): print("...Play " + str(play)) # every player does a play for counter in range(0, 4): to_play_num = order[counter] print("...Player " + str(to_play_num) + " playing") card_played = ai_list[to_play_num].play(state) print("...Played " + str(card_played)) # if this is the first play, we set the trump if counter == 0: state.trump_card = card_played print("...Trump is " + str(state.trump_card.suit)) # update the state based on the card played state.played_cards.append(card_played) state.played[to_play_num] = card_played # figure out who won # rotate order to the winner winner_num = state.find_play_winner() # reset the round state.reset_play() # Rotate while (order[0] != winner_num): out_of = order.pop(0) order.append(out_of) assert len(state.played_cards) == 52 # reset the play state.reset_round()
'8': 'Eight', '9': 'Nine', '10': 'Ten', 'Jack': 'Jack', 'Q': 'Queen', 'K': 'King' } for shape in shapes: for i, j in ranks.items(): cards.append((shape, j)) #cards.append(i) #cards.append(j) return (cards) deck = myDeck.Deck(Deck_initial_stage()) def Draw(): """ cards are drawn to the players one at a time """ for i in range(5): for players in player_lst: deck.shuffle() players.append(deck.draw()) print(player_lst) Draw() player1 = player_lst[0]
def __init__(self, players: List[Player]): self.dome = pyCardDeck.Deck() self.dome.load_standard_deck() self.players = players self.scores = {} print("Created a game with {} players.".format(len(self.players)))
def __init__(self, players: List[Player]): self.deck = pyCardDeck.Deck(cards=generate_deck(), name="Poker deck", reshuffle=False) self.players = players print(f"Created a table with {len(self.players)} players")