當前位置: 首頁>>代碼示例>>Python>>正文


Python Deck.move_cards方法代碼示例

本文整理匯總了Python中cards.Deck.move_cards方法的典型用法代碼示例。如果您正苦於以下問題:Python Deck.move_cards方法的具體用法?Python Deck.move_cards怎麽用?Python Deck.move_cards使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cards.Deck的用法示例。


在下文中一共展示了Deck.move_cards方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Table

# 需要導入模塊: from cards import Deck [as 別名]
# 或者: from cards.Deck import move_cards [as 別名]
class Table(object):

    def __init__(self, minimum=1, maximum=500, payout=1, hit_soft_17=True, 
                 insurance_allowed=True, insurance_payout=2,
                 num_decks=6, reshuffle_each_hand=True,
                 blackjack_payout=1.5, max_split_hands=3, 
                 surrender_allowed=True, hit_split_ace=False,
                 resplit_aces=False, split_A10_is_blackjack=False,
                 double_after_split=False, double_after_hit= False):
        # Establish table rules
        self.min = minimum if minimum > 0 else 1
        self.standard_bet = self.min
        self.max = maximum if maximum > minimum else 500
        self.payout = payout if payout > 0 else 1
        self.hit_soft_17 = hit_soft_17
        self.insurance_allowed = insurance_allowed
        self.insurance_payout = insurance_payout if insurance_payout > 0 else 2
        self.num_decks = num_decks if num_decks > 0 else 6
        self.reshuffle_each_hand = reshuffle_each_hand
        self.blackjack_payout = blackjack_payout if blackjack_payout > 0 else 1.5
        self.max_split_hands = max_split_hands if max_split_hands >= 2 else 3
        self.surrender_allowed = surrender_allowed
        self.hit_split_ace = hit_split_ace
        self.resplit_aces = resplit_aces
        self.split_A10_is_blackjack = split_A10_is_blackjack
        self.double_after_split = double_after_split
        self.double_after_hit = double_after_hit
        
        # Initialize necessary variables
        if debug:
            print "Established table"
        self.init_deck()
        self.dealer_hand = Hand("Dealer")
           
    def init_deck(self):
        self.deck = Deck(self.num_decks)
        self.deck.shuffle()

    def buy_in(self, name, chips, bet_method, play_method):
        if debug:
            print name + " bought into the table with $" + str(chips)
        self.player_name = name
        self.player_chips = chips
        self.player_hands = [Hand(name)]
        self.player_surrendered = False
        self.bets = []
        self.win_streak = 0
        self.in_play = [False]
        self.bet_method = bet_method
        self.play_method = play_method
        self.doubled = [False]

    def add_funds(self, chips):
        self.player_chips = self.player_chips + chips

    def __str__(self):
        if len(self.dealer_hand.cards) > 0:
            ret = "Dealer is showing: " + str(self.dealer_hand.cards[0]) + "\n"
            for h in range(len(self.player_hands)):
                ret = ret + str(self.player_hands[h]) + " w/ value " + str(hand_value(self.player_hands[h])) + " and $" + str(self.bets[h]) + " bet"
            return ret
        else:
            return "Waiting for hand to be dealt\n"

    def deal(self):
        if self.reshuffle_each_hand or self.deck.cards_left() < 4:
            # if debug:
                # print "Shuffling decks"
            self.init_deck()
        # if debug:
            # print "Dealing"
        self.deck.move_cards(self.dealer_hand, 2)
        self.deck.move_cards(self.player_hands[0], 2)
        self.player_hands[0].sort()
        self.in_play[0] = True

    def get_bets(self):
        bet = self.bet_method(self.player_chips)
        if bet == "rebet":
            self.place_bet(self.standard_bet)
        else:
            while not self.place_bet(bet):
                bet = self.bet_method()
                if bet == "rebet":
                    self.place_bet(self.standard_bet)

    def place_bet(self, bet):
        if bet < self.min:
            if debug:
                print "Must bet at least the minimum: " + str(self.min)
            return False
        elif bet > self.max:
            if debug:
                print "Must bet less than the maximum: " + str(self.max)
            return False
        elif bet > self.player_chips:
            if debug:
                print "Don't have funds to place bet. Current chip count: " + str(self.player_chips)
            return False
        else:
#.........這裏部分代碼省略.........
開發者ID:zkrasner,項目名稱:blackjack_sim,代碼行數:103,代碼來源:blackjack_sim.py


注:本文中的cards.Deck.move_cards方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。