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


Python Hand.add_card方法代码示例

本文整理汇总了Python中hand.Hand.add_card方法的典型用法代码示例。如果您正苦于以下问题:Python Hand.add_card方法的具体用法?Python Hand.add_card怎么用?Python Hand.add_card使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hand.Hand的用法示例。


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

示例1: main

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import add_card [as 别名]
def main():
    """ Reads the input from stdin. Outputs to stdout. """

    trump = sys.stdin.readline().strip()
    my_hand = Hand(trump[0].lower())

    line = 0
    while line < 5:
        card = sys.stdin.readline()
        my_hand.add_card(card[0], card[1])
        line += 1

    my_hand.sort_hand()

    print(trump)
    print(my_hand)
开发者ID:kylegalloway,项目名称:Euchre-Hands,代码行数:18,代码来源:euchre_hands.py

示例2: deal_initial_hands

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import add_card [as 别名]
    def deal_initial_hands(self):
        """Deals hands for all players in the game.  Deal two cards to each bet
        box starting from the dealer's left, followed by one for the dealer.
        Note that this is NOT hole card play, where another card is dealt face
        down so that the game can end immediately if the dealer has a
        blackjack."""
        num_cards = 2
        for player in self.players:
            new_hand = Hand()
            for i in range(num_cards):
                new_card = self.draw_card()
                new_hand.add_card(new_card)
            player.assign_hand(new_hand)
            UI.deal_hand(player, new_hand)

        dealer_hand = Hand([self.draw_card()])
        self.dealer.assign_hand(dealer_hand)
开发者ID:danielmoniz,项目名称:blackjack,代码行数:19,代码来源:game.py

示例3: Player

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import add_card [as 别名]
class Player(object):
    def __init__(self, chips=100):
        self.chips = chips
        self.hand = Hand()

    def _subtract_chips(self, amt):
        if self.chips >= amt:
            self.chips -= amt
        else:
            raise StandardError("Not enough chips")

    def clear_hand(self):
        self.hand.clear()

    def bet(self, amt):
        self._subtract_chips(amt)

    def add_card(self, card):
        self.hand.add_card(card)
开发者ID:swanson,项目名称:py-card-lib,代码行数:21,代码来源:player.py

示例4: test_add_card

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import add_card [as 别名]
 def test_add_card(self):
     hand = Hand()
     card = Card()
     hand.add_card(card)
     cards_in_hand = hand.get_cards()
     self.assertEquals(len(cards_in_hand), 1)
开发者ID:raptorinsurance,项目名称:hanabiClone,代码行数:8,代码来源:test_hand.py

示例5: TestHand

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import add_card [as 别名]
class TestHand(unittest.TestCase):
    """
        Tests the functionality of the Hand class.
        //TODO combine this with current functional tests, rewrite functional tests.
    """

    def setUp(self):
        self.hand = Hand("Diamonds")

    def tearDown(self):
        self.hand = None

    def test_can_set_trump(self):
        """ Tests the ability to set the trump of a hand. """
        self.assertEqual(self.hand.get_trump(), "Diamonds")

    def test_can_sort_normal_hand(self):
        """ Tests the ability to sort a hand that has no trumps or bowers. """
        self.hand.add_card("T", "s")
        self.hand.add_card("Q", "s")
        self.hand.add_card("J", "s")
        self.hand.add_card("K", "s")
        self.hand.add_card("A", "s")

        self.hand.sort_hand()

        self.assertEqual(str(self.hand), "As\nKs\nQs\nJs\nTs")

    def test_can_sort_trump_hand(self):
        """ Tests the ability to sort a hand that has all trumps (and high bower). """
        self.hand.add_card("T", "d")
        self.hand.add_card("Q", "d")
        self.hand.add_card("J", "d")
        self.hand.add_card("K", "d")
        self.hand.add_card("A", "d")

        self.hand.sort_hand()

        self.assertEqual(str(self.hand), "Jd\nAd\nKd\nQd\nTd")

    def test_can_sort_mixed_hand(self):
        """ Tests the ability to sort a hand that is mixed and includes both bowers. """
        self.hand.add_card("T", "d")
        self.hand.add_card("Q", "c")
        self.hand.add_card("J", "h")
        self.hand.add_card("J", "d")
        self.hand.add_card("A", "d")

        self.hand.sort_hand()

        self.assertEqual(str(self.hand), "Jd\nJh\nAd\nTd\nQc")
开发者ID:kylegalloway,项目名称:Euchre-Hands,代码行数:53,代码来源:unit_tests.py

示例6: Dealer

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import add_card [as 别名]
class Dealer(object):

	def __init__(self):
		self.hand = Hand()

	def deal_card(self, card_table):
		card = card_table.shoe.get_next_card()
		for chair in card_table.chairs:
			chair.player.observe_card(card)
		return card

	def deal_round(self, card_table):
		for _ in range(2):
			for chair in card_table.chairs:
				if chair.hands[0]['bet'] is not "bankrupt":
					chair.hands[0]['hand'].add_card(self.deal_card(card_table))
				else:
					chair.active = False
			for chair in card_table.chairs:
				if chair.active:
					self.hand.add_card(self.deal_card(card_table))
					break

	def hit_dealer(self, card_table):
		while self.hand.is_soft():
			if self.hand.total < 18:
				self.hand.add_card(self.deal_card(card_table))
			else:
				break
		while self.hand.total < 17:
			self.hand.add_card(self.deal_card(card_table))

	def pay_player(self, hand, chair):
		chair.player.bankroll += hand['bet'] * 2

	def pay_player_blackjack(self, chair, blackjack_payout):
		bet = chair.hands[0]['bet'] + chair.hands[0]['bet'] * blackjack_payout
		chair.player.bankroll += bet

	def refund_player(self, hand, chair):
		chair.player.bankroll += hand['bet']

	def resolve_round(self, card_table):
		for chair in card_table.chairs:
			if chair.active:
				self.hit_dealer(card_table)
				break
		for chair in card_table.chairs:
			if chair.active:
				if self.hand.is_busted():
					for hand in chair.hands:
						if hand['hand'].is_busted() is False:
							self.pay_player(hand, chair)
				else:
					for hand in chair.hands:
						if self.hand.total < hand['hand'].total:
							self.pay_player(hand, chair)
						elif self.hand.total is hand['hand'].total:
							self.refund_player(hand, chair)

	def showing(self):
		return self.hand.cards[0].get_value()
开发者ID:andyrockenbach,项目名称:Projects,代码行数:64,代码来源:dealer.py


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