本文整理汇总了Python中Deck.Deck类的典型用法代码示例。如果您正苦于以下问题:Python Deck类的具体用法?Python Deck怎么用?Python Deck使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Deck类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: battle
def battle():
print('\n#<====== Playing a Game of War ======>#\n')
## Creating p1Score, p2Score, ties variables.
p1Score = 0
p2Score = 0
ties = 0
## Creating two hands to hold cards (that are dealt for each player)
h1 = []
h2 = []
## Creating a new deck for the cards
d = Deck()
## Shuffling the new deck
d.shuffle()
## Using a loop to deal cards to the two players.
for i in range(len(d.cards)):
if i % 2 == 0:
h1.append(d.deal())
elif i % 2 == 1:
h2.append(d.deal())
i += 1
## printing each player's hands
print('\n#<====== Player 1\'s Hand: ======>#\n')
for card in h1:
print(card)
print('\n#<====== Player 2\'s Hand: ======>#\n')
for card in h2:
print(card)
print('\n#<====== Now its time for WAR!!! ======>#\n')
示例2: prob_two_pairs
def prob_two_pairs(N=100000):
M = 0 # no. of successes
for exp in xrange(N):
deck = Deck()
hand = deck.hand(n=5)
M += (same_rank(hand, 2) == 2)
return float(M) / N
示例3: __init__
def __init__(self, *args, **kwargs):
platform = pyglet.window.get_platform()
display = platform.get_default_display()
screen = display.get_default_screen()
template = pyglet.gl.Config(double_buffer=True)
config = screen.get_best_config(template)
context = config.create_context(None)
window.Window.__init__(self, resizable=True, width=WINWIDTH, height=WINHEIGHT, caption="REZD:" + str(VERSION), context=context)
self.baseDeck = Deck() # used to lookup cards basically a reference instead of using a database. Basically don't remove / add cards
self.baseDeck.populate('assets/cardlist.xml')
self.newdeck = Deck()
self.selectedCard = None
self.runnerbaselist = []
self.corpbaselist = []
for card in self.baseDeck.deck:
if card.playertype == "Runner":
self.runnerbaselist.append(card.name)
else:
self.corpbaselist.append(card.name)
self.runnerbaselist.sort()
self.corpbaselist.sort()
# kytten stuff
self.theme = kytten.Theme(os.path.join(os.getcwd(), 'theme'), override={
"gui_color": [64, 128, 255, 255],
"font_size": 14
})
self.theme2 = kytten.Theme(self.theme, override={
"gui_color": [61, 111, 255, 255],
"font_size": 12
})
示例4: DeckTest
class DeckTest(unittest.TestCase):
def setUp(self):
self.deck = Deck()
def test_createDeck(self):
self.assertEqual(52, self.deck.getNumOfCards())
def test_shuffle(self):
testDeck = self.deck.getAllCards()
compareDeck = []
for card in testDeck:
compareDeck.append(card)
numOfSameCards = 0
for x in range(0, 52):
if compareDeck[x] == testDeck[x]:
numOfSameCards += 1
self.assertEqual(52, numOfSameCards)
self.deck.shuffle()
numOfSameCards = 0
for x in range(0, 52):
if compareDeck[x] == testDeck[x]:
numOfSameCards += 1
self.assertNotEqual(52, numOfSameCards)
def test_getNextCard(self):
newDeck = Deck()
for x in range(0, 52):
newDeck.getNextCard()
with self.assertRaises((NameError)):
newDeck.getNextCard()
示例5: test
def test():
""" Simple test program for card dragging. """
from Deck import Deck
pygame.init()
screen = pygame.display.set_mode((640, 480))
deck = Deck()
handler = CardDraggingEventHandler(deck)
while True:
pygame.time.wait(30)
for event in pygame.event.get():
if event.type == pygame.QUIT:
return
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
sys.exit()
else:
handler.handle_card_dragging(event)
screen.fill((0x00, 0xb0, 0x00))
deck.draw(screen)
pygame.display.flip()
示例6: playGame
def playGame(self):
while self.newGame != False:
self.newGame = False
print("Welcome to Bender's Totally Legit and Not Rigged at All Blackjack Table.")
print("You're not a cop, are you? You have to tell me if you're a cop...")
self.getPlayers()
print("Welcome",self.player.name)
self.player.startingCash()
print(self.player.name, "has $",self.player.cash,"available")
deck = Deck()
dealer = Dealer()
while self.replayGame != False:
if len(deck.currentDeck) <= 10:
house = deck.newDeck()
round = Round(self)
results = Results(self)
score = Scoreboard(self)
wager = score.placeBet(self.player.cash)
if self.newGame == True:
break
round.startingHands(self.player, dealer, deck, house)
round.takeAction(self.player, dealer, deck, house)
if self.player.score <= 21 and self.player.score > 0:
round.checkDealerHand(self.player, dealer, deck, house)
results.determineWinner(self.player, dealer)
self.player.cash = score.updateCash(self.player.cash, wager)
print(self.player.name, "has $", self.player.cash, "available")
replay = KeepPlaying()
replay.replayGame(self.player, dealer)
self.replayGame = replay.playAgain
if self.newGame == False:
print("I don't need you. I'll build my own casino. With Blackjack... and hookers... Awww, forget it.")
elif self.newGame == True:
print("Oops, you're broke! ¯\_(ツ)_/¯")
print("Come back when you have some money to lose. (\/)(;,,;)(\/)")
示例7: prob_fourofakind
def prob_fourofakind(N=100000):
M = 0 # no. of successes
for exp in xrange(N):
deck = Deck()
hand = deck.hand(n=5)
M += (same_rank(hand, 4) == 1)
return float(M) / N
示例8: prob_same_suit
def prob_same_suit(N=100000):
M = 0 # no. of successes
for exp in xrange(N):
deck = Deck()
hand = deck.hand(n=5)
for suit in same_suit(hand):
M += (same_suit(hand)[suit] in [4, 5])
return float(M) / N
示例9: playBJ
def playBJ(self):
deck = Deck(self.game_deck_num)
deck.shuffleDeck()
in_hand = True
#print deck.printDeck(self.game_deck_num * 52)
player_card1 = deck.dealCard(in_hand)
dealer_card1 = deck.dealCard(in_hand)
player_card2 = deck.dealCard(in_hand)
dealer_card2 = deck.dealCard(in_hand)
示例10: updateRatingsAI
def updateRatingsAI(self, table, setFound, the_time):
'''AI was faster, so all sets involved are actually harder
than we thought, ie increase their rating
Please call whenever an AI finds a set
'''
allSets = Deck.allSets(table)
for the_set in allSets:
try:
self.ratingList[Deck.idOfSet(the_set)] += 50
except:
self.ratingList[Deck.idOfSet(the_set)] = 1550
self.dumpData()
示例11: __initializeDeck
def __initializeDeck(self):
# Initialize discard columns
self.__discardPiles = [
Deck(),
Deck(),
Deck(),
Deck()
]
deck = Deck()
deck.buildFullDeck()
deck.shuffle()
self.__deck = deck
示例12: __init__
def __init__(self, numPlayers=1, numAI = 3):
"""
basic set up for a game where:
numPlayers = the total number of human players
numAI = the number of the total players that are AI
"""
self.totPlayers = numPlayers + numAI
#checking that there are atleast 2 players
if (self.totPlayers) < 2:
raise Exception('need atleast 2 players to play the game')
self.deck = Deck()
self.numPlayers = numPlayers
self.numAI = numAI
self.winners = []
#setting up the players
self.players = []
[self.players.append(Player(len(self.players), game=self, AI = len(self.players) >= numPlayers)) for i in range(numPlayers + numAI)]
for i in range(len(self.players)):
self.players[i].setPrev(self.players[i-1])
self.players[i].setNext(self.players[(i + 1) % len(self.players)])
示例13: __init__
def __init__(self, num_players=1, num_decks=6):
self.num_decks = num_decks
self.dealer = Dealer()
self.bot = Bot('Bot')
self.players = []
self.busted = []
self.stand = []
self.move = 0
self.dealer_done = False
self.bot_moves = []
for i in xrange(0,num_players):
self.players.append(Player('Player'+str(i+1)))
self.players.append(self.bot)
self.deck = Deck(num_decks)
self.bot_deck = self.deck.deck * 1
for player in self.players:
player.make_bet()
if player.name == 'Bot':
player.add(self.bot_deck.pop())
player.add(self.bot_deck.pop())
self.bot_deck.pop()
self.bot_deck.pop()
else:
player.add(self.deck.draw())
player.add(self.deck.draw())
self.dealer.add(self.deck.draw())
self.dealer.add(self.deck.draw())
self.rules = RulesEngine(self.dealer, self.players)
示例14: __init__
def __init__(self):
self.moves = ["hit","stand","double","split"]
self.deck = Deck()
self.player = Player()
self.player_hand = []
self.player_hand.append(Hand())
self.dealer_hand = Hand()
示例15: __init__
def __init__(self, table, message_handler=None):
"""players should be array of players to be seated.
deal must be the player who is the current dealer. If None, the
lowest seated player will be the dealer.
message handler must be a MessageHandler instance or None."""
self.table = table
self.message_handler = message_handler
#
# Private state not available to players
#
self._deck = Deck()
self._deck.shuffle()
active_players = self.table.get_active_players()
# Create main pot to start with
self.pot = Pot(contending_players = active_players)
# Create initial hands
for player in active_players:
player.new_hand()
# Record of betting rounds
self.betting_rounds = []