当前位置: 首页>>代码示例>>Python>>正文


Python cards.Deck类代码示例

本文整理汇总了Python中cards.Deck的典型用法代码示例。如果您正苦于以下问题:Python Deck类的具体用法?Python Deck怎么用?Python Deck使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Deck类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: war

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
开发者ID:joeylmaalouf,项目名称:misc,代码行数:7,代码来源:games.py

示例2: test_3elements

 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]))
开发者ID:denversc,项目名称:cards,代码行数:7,代码来源:test_Deck.py

示例3: test_deck_length1

 def test_deck_length1(self):
     x = Deck()
     card = Card("a", "b")
     x[:] = [card]
     actual = x.draw()
     self.assertEqual(actual, card)
     self.assertListEqual(x, [])
开发者ID:denversc,项目名称:cards,代码行数:7,代码来源:test_Deck.py

示例4: test_shuffle

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"
    
开发者ID:charlieRode,项目名称:deck_o_cards,代码行数:6,代码来源:test_cards.py

示例5: DeckTest

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)
开发者ID:dennyb87,项目名称:pycity,代码行数:33,代码来源:cards_test.py

示例6: test_2elements

 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]))
开发者ID:denversc,项目名称:cards,代码行数:7,代码来源:test_Deck.py

示例7: test_deck_length2

 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])
开发者ID:denversc,项目名称:cards,代码行数:8,代码来源:test_Deck.py

示例8: test_deck_full

 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)
开发者ID:denversc,项目名称:cards,代码行数:8,代码来源:test_Deck.py

示例9: test_full

 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))
开发者ID:denversc,项目名称:cards,代码行数:8,代码来源:test_Deck.py

示例10: __init__

  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
开发者ID:andromeda-gal63,项目名称:CardGames,代码行数:12,代码来源:cardGame1.py

示例11: __init__

 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
开发者ID:jdiller,项目名称:gaps,代码行数:13,代码来源:tableau.py

示例12: CardDemo

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"] = ""
开发者ID:gregpuzzles1,项目名称:Sandbox,代码行数:49,代码来源:carddemo.py

示例13: pop_card

	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()
开发者ID:lekanovic,项目名称:BlackJack,代码行数:7,代码来源:blackjack.py

示例14: __init__

 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
开发者ID:ekelly,项目名称:PyEuchre,代码行数:16,代码来源:game.py

示例15: __init__

	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()]
开发者ID:cowpig,项目名称:grater_experiment,代码行数:30,代码来源:game_models.py


注:本文中的cards.Deck类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。