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


Python Deck.copy方法代码示例

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


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

示例1: Simulator

# 需要导入模块: from Deck import Deck [as 别名]
# 或者: from Deck.Deck import copy [as 别名]

#.........这里部分代码省略.........
        self.predefined_hands = predefined_hands
        if self.HighRankerClass is not None:
            self.high_ranker = self.HighRankerClass()
        else:
            self.high_ranker = None
        if self.LowRankerClass is not None:
            self.low_ranker = self.LowRankerClass()
        else:
            self.low_ranker = None
        self.board = None
        if issubclass(self.HandClass, CommunityCardHand):
            if predefined_board is None:
                BoardClass = self.HandClass.boardClass
                self.board = BoardClass()
            else:
                # Todo: verify board is of appropriate class
                self.board = predefined_board
        elif predefined_board is not None:
            raise InvalidBoardException("Given HandClass does not support a Board")
        self.deck = Deck()
        
    @classmethod
    def getMaxHands(cls):
        """Return the maximum number of hands that can be dealt"""
	cards_per_hand = cls.HandClass.maxCards
        cards_in_deck = 52
        if issubclass(cls.HandClass, CommunityCardHand):
            cards_in_deck -= cls.HandClass.boardClass.maxCards
	return int(cards_in_deck/cards_per_hand)

    def get_predefined_hands(self):
        """Return array of predefined hands or None if none predefined."""
        return self.predefined_hands

    def simulate_games(self,
                       number_of_games = 100,
                       callback=None, callbackArg=None,
                       stats=None):
        """Simulate a bunch of games with starting hands. Returns
	a array with number of wins for each hand.

        Returns a Stats instance with the statistics from the games. If a
        stats instance is passed in, the same one, augmented, will be
        returned.

        callback should be a function that takes the form:
        callback(game, result, *callbackarg)
        """
        assertInstance(number_of_games, int)
        if stats is None:
            stats = Stats(number_of_hands = self.number_of_hands)
	while number_of_games > 0:
	    result = self.simulate_game()
            stats.record_game(result)
	    if callback is not None:
                args = [self, result]
                if callbackArg is not None:
                    args.append(callbackArg)
                callback(*args)
            number_of_games -= 1
        return stats

    def simulate_game(self):
	# Make a copy of deck, hands and board
	deck = self.deck.copy()
	deck.shuffle()
	hands = Hands()
        # Deal out predefined hands
        if self.predefined_hands is not None:
            for hand in self.predefined_hands:
                if isinstance(hand, HandGenerator):
                    hands.addHand(hand.generateHand(deck = deck))
                else:
                    hands.addHand(hand.copy())
                    deck.removeCards(hand)
	# If we have less than numHands, fill it out
	while len(hands) < self.number_of_hands:
	    hands.addHand(self.HandClass())
	if self.board is None:
	    board = None
	else:
	    board = self.board.copy()
	# Fill out hands and board
	deck.dealHands(hands)
	if board is not None:
	    # Deal board
	    deck.dealHands(board)
	    for hand in hands:
		hand.setBoard(board)
        result = Result(hands, board=board)
	# Find winning hands
	if self.high_ranker is not None:
	    (high_winners, bestHighRank) = self.high_ranker.bestHand(hands)
            result.high_winners = high_winners
            result.winning_high_rank = bestHighRank
	if self.low_ranker is not None:
	    (low_winners, bestLowRank) = self.low_ranker.bestHand(hands)
            result.low_winners = low_winners
            result.winning_low_rank = bestLowRank
        return result
开发者ID:von,项目名称:pyPoker,代码行数:104,代码来源:PokerGame.py


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