本文整理汇总了Python中Deck类的典型用法代码示例。如果您正苦于以下问题:Python Deck类的具体用法?Python Deck怎么用?Python Deck使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Deck类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
class Golf_relaxed:
def __init__(self):
self.deck = Deck()
self.deckA = pygame.sprite.LayeredDirty()
self.deckB = pygame.sprite.LayeredDirty()
self.col1 = pygame.sprite.LayeredDirty()
self.col2 = pygame.sprite.LayeredDirty()
self.col3 = pygame.sprite.LayeredDirty()
self.col4 = pygame.sprite.LayeredDirty()
self.col5 = pygame.sprite.LayeredDirty()
self.col6 = pygame.sprite.LayeredDirty()
self.col7 = pygame.sprite.LayeredDirty()
self.set_up_game()
def set_up_game(self):
for i in range(0,17):
self.deckA.add(self.deck.get())
for i in range(0,5):
self.col1.add(self.deck.get())
self.col2.add(self.deck.get())
self.col3.add(self.deck.get())
self.col4.add(self.deck.get())
self.col5.add(self.deck.get())
self.col6.add(self.deck.get())
self.col7.add(self.deck.get())
self.deckB.add(self.deck.get())
示例2: test_05_shuffle
def test_05_shuffle(self):
d1 = Deck()
d2 = Deck()
d1.shuffle()
self.assertFalse(same_cards(d1,d2), "deck wasn't shuffled")
d1.sort()
self.assertTrue(same_cards(d1,d2), "deck wasn't sorted")
示例3: __init__
class Dealer:
def __init__(self):
self.deck = Deck(False)
def shuffleDeck(self):
self.deck = Deck(False)
self.deck.shuffle()
self.deck.shuffle()
self.deck.shuffle()
self.deck.shuffle()
示例4: test_shuffle
def test_shuffle():
newdeck = Deck()
beforeshuffle = []
for card in newdeck:
beforeshuffle.append(card)
newdeck.shuffle()
sameplace = 0
index = 0
for card in newdeck:
if card.card_value == beforeshuffle[index].card_value:
sameplace += 1
index += 1
assert sameplace < newdeck.size/3
示例5: __init__
def __init__(self):
self.isPlaying = True
self.boardRows = 4
self.boardCols = 10
#Stokkur leiksins
self.deck = Deck(52)
self.deck.shuffleCards()
#2D array of cards in the board, initialized as None
self.board = self.initBoard()
self.dealToBoard()
#Cards in the heap
self.heap = [self.deck.cards.pop()]
#Breyta sem heldur utan um stig
self.score = 0
#Breyta sem byrjar ad taka tima
self.start_time = time.time()
#Lokatimi leiks
self.finaltime = 0.0
#Breyta sem heldur utanum 'moves'
self.moves = 0
示例6: __init__
def __init__(self, numPlayers, maxSimulationDepth):
self._players = []
self._currentPlayerIndex = 0
self._deck = Deck()
self._cardDrawManager = CardDrawManager(self)
print "==========="
self._deck.printCards()
for playerIndex in range(numPlayers):
player = Player(self, playerIndex)
self._players.append(player)
for drawIndex in range(InitialDrawCount):
self._cardDrawManager.handleDrawFor(player)
for player in self._players:
print player
print "============="
self._progress = {}
for suit in SUITS:
self._progress[suit] = 0
self._hintTokens = InitialHintTokens
self._deathTokens = InitialDeathTokens
self._maxSimulationDepth = maxSimulationDepth
示例7: __init__
def __init__(self):
self.board = [] #cards on the board(hand)
self.on = True
self.deck = Deck() #the deck
self.deck.shuffle()
for i in range(0,4):
self.board.append(self.deck.draw())
self.beginDisplay()
self.redisplay()
示例8: deck_entropy
def deck_entropy(deck_1, deck_2 = Deck.construct_standard_deck()):
total=0
for i, card in enumerate(deck_1):
diff = 0
for j, compare in enumerate(deck_2):
if(card==compare):
diff == i-j
if(diff<0):
diff*=(-1)
total+=diff
return total
示例9: main
def main():
size = int(sys.argv[1])
me = Deck(range(1,size+1))
print("initial state:")
me.debugprint()
for i in range(15):
me.shuffle()
print("---")
print(" below is the", i,"th iteration:")
me.debugprint()
示例10: dealSomeHands
def dealSomeHands():
# Generate the initial deck and shuffle it.
d = Deck()
d.shuffle()
# Find out from the user how many hands to generate.
while True:
# Run this while loop until we get a legal (positive
# integer) answer from the user.
nStr = input("How many hands should I deal? ")
if not nStr.isdigit():
print (" Positive number required. Try again!")
else:
n = int( nStr ); break
# Generate n hands.
for i in range( n ):
# If there are not enough cards left in the deck
# to deal a hand, generate and shuffle a new deck.
if ( len(d) < 5 ):
print("\nDealing a new deck.")
d = Deck()
d.shuffle()
# Generate a new hand, print it, and evaluate it.
h = Hand(d)
print("\n\tHand drawn (", i + 1, "): ", sep="")
print(h)
print( "\t -", h.evaluateHand())
示例11: start
def start():
new_deck1 = copy.deepcopy(Deck.deck())
new_dealer1 = 0
new_hand1 = 0
ace_dealer1 = 0
ace_hand1 = 0
print()
card_d = int(input("What card should the dealer start with? "))
print()
card_d = new_deck1[card_d-1]
print(card_d[0])
new_dealer1 += card_d[1]
if card_d[1] == 11:
ace_dealer1 += 1
print()
cards_h = input("What cards should the player start with? ").split(" ")
card_h = []
for card in cards_h:
card_h.append(int(card))
print()
card_h0 = new_deck1[card_h[0]-1]
card_h1 = new_deck1[card_h[1]-1]
new_deck1.remove(card_d)
new_deck1.remove(card_h0)
new_deck1.remove(card_h1)
new_hand1 += card_h0[1]
new_hand1 += card_h1[1]
if card_h0[1] == 11:
ace_hand1 += 1
if card_h1[1] == 11:
ace_hand1 += 1
print(card_h0[0])
print(card_h1[0])
print()
print("The dealer has", new_dealer1)
print("You have", new_hand1)
print()
return new_deck1, new_dealer1, new_hand1, ace_dealer1, ace_hand1
示例12: __init__
def __init__(self, playerName):
'''
Initializes the game by
- shuffling the deck
- initializing a player1 (with given playerName) and dealer object (both are Player objects)
'''
self.gamedeck = Deck()
self.gamedeck.reset()
self.gamedeck.shuffle()
self.playerName = playerName
self.user = Player(self.playerName)
self.dealer = Player("Dealer")
示例13: test_06_hands
def test_06_hands(self):
d = Deck()
h = d.deal(5)
self.assertEqual(5, len(h), "hand doesn't have 5 cards")
self.assertEqual(47, len(d), "hand wasn't removed from deck")
d.restore(h)
self.assertEqual(52, len(d), "had wasn't put back in deck")
d.sort()
self.assertTrue(same_cards(d, Deck()), "restored deck incomplete")
示例14: deal
def deal():
'''
resets game, deals 4 cards face down, flips 3 to begin (1 dealer, 2 player)
'''
global dealer_hand_display
global player_hand_display
global dealer_hand
global player_hand
global global_deck
# resets global variables and shuffles deck, creating new game
dealer_hand = []
player_hand = []
global_deck = Deck()
global_deck.shuffle()
current_bet.config(state=NORMAL)
for i in range(2):
dealer_hand.append(global_deck.nextcard())
player_hand.append(global_deck.nextcard())
for i in range(2,6):
dealer_hand_display[i].display('blank')
player_hand_display[i].display('blank')
player_hand_display[0].display('front', player_hand[0].ID)
player_hand_display[1].display('front', player_hand[1].ID)
dealer_hand_display[0].display('back')
dealer_hand_display[1].display('front', dealer_hand[1].ID)
# extra credit, checks for "Blackjack"
if (check_blackjack(dealer_hand)) or (check_blackjack(player_hand)):
dealer_hand_display[0].display('front', dealer_hand[0].ID)
if (check_blackjack(dealer_hand)):
win_process('dealer')
elif (check_blackjack(player_hand)):
win_process('player')
示例15: deal
def deal():
"""Generates a new round. Deals a hand to the dealer and player.
Checks if either hand is a BlackJack"""
global outcome, in_play, dealer, player, deck, score, total_games
if total_games != 0:
outcome = ""
if in_play:
outcome = "Player dealed again, lost a point. "
score -= 1
in_play = False
dealer = Hand()
player = Hand()
deck = Deck()
deck.shuffle()
dealer.add_card(deck.deal_card())
dealer.add_card(deck.deal_card())
player.add_card(deck.deal_card())
player.add_card(deck.deal_card())
in_play = True
outcome += "New Game! Hit or Stand?"
if in_play and player.get_value() == 21:
stand()
if in_play and dealer.get_value() == 21:
stand()