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


Python Deck.size方法代码示例

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


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

示例1: playwar

# 需要导入模块: from Deck import Deck [as 别名]
# 或者: from Deck.Deck import size [as 别名]
def playwar():
    deck = Deck()
    deck.shuffle()
    n = deck.size()
    playerHand = Hand()
    compHand = Hand()

    deck.moveCards(playerHand, (n//2))
    deck.moveCards(compHand, (n//2))
    # playerHand.sort()
    # compHand.sort()
    print ("Cards in computer hand: ")
    print(compHand)
    print("Cards in player hands: ")
    print(playerHand)
    nowPlay(playerHand, compHand)
开发者ID:mbhushan,项目名称:ps-algods-py,代码行数:18,代码来源:WarCardGame.py

示例2: Deck

# 需要导入模块: from Deck import Deck [as 别名]
# 或者: from Deck.Deck import size [as 别名]
'''
Tests generation of a full 52 card Deck and that cards are
sorted by rank and then by suit within rank
'''

from Deck import Deck

d = Deck()
print 'Deck size:',d.size()
d.shuffle()
print '\nBefore sort:'
print d

d.sort()

print 'After sort:'
print d
开发者ID:danielcorin,项目名称:Hearts,代码行数:19,代码来源:DeckTest.py

示例3: __init__

# 需要导入模块: from Deck import Deck [as 别名]
# 或者: from Deck.Deck import size [as 别名]
class Hearts:
	def __init__(self):
		
		self.roundNum = 0
		self.trickNum = 0 # initialization value such that first round is round 0
		self.dealer = -1 # so that first dealer is 0
		self.passes = [1, -1, 2, 0] # left, right, across, no pass
		self.currentTrick = Trick()
		self.trickWinner = -1
		self.heartsBroken = False
		self.losingPlayer = None
		self.passingCards = [[], [], [], []]


		# Make four players

		self.players = [Player("Danny"), Player("Desmond"), Player("Ben"), Player("Tyler")]
		
		'''
		Player physical locations:
		Game runs clockwise

			p3
		p2		p4
			p1

		'''

		# Generate a full deck of cards and shuffle it
		self.newRound()

	def handleScoring(self):
		p, highestScore = None, 0
		print "\nScores:\n"
		for player in self.players:
			print player.name + ": " + str(player.score)
			if player.score > highestScore:
				p = player
				highestScore = player.score
			self.losingPlayer = p

		

	def newRound(self):
		self.deck = Deck()
		self.deck.shuffle()
		self.roundNum += 1
		self.trickNum = 0
		self.trickWinner = -1
		self.heartsBroken = False
		self.dealer = (self.dealer + 1) % len(self.players)
		self.dealCards()
		self.currentTrick = Trick()
		self.passingCards = [[], [], [], []]
		for p in self.players:
			p.discardTricks()

	def getFirstTrickStarter(self):
		for i,p in enumerate(self.players):
			if p.hand.contains2ofclubs:
				self.trickWinner = i

	def dealCards(self):
		i = 0
		while(self.deck.size() > 0):
			self.players[i % len(self.players)].addCard(self.deck.deal())
			i += 1


	def evaluateTrick(self):
		self.trickWinner = self.currentTrick.winner
		p = self.players[self.trickWinner]
		p.trickWon(self.currentTrick)
		self.printCurrentTrick()
		print p.name + " won the trick."
		# print 'Making new trick'
		self.currentTrick = Trick()
		print self.currentTrick.suit
		

	def passCards(self, index):
		print self.printPassingCards()
		passTo = self.passes[self.trickNum] # how far to pass cards
		passTo = (index + passTo) % len(self.players) # the index to which cards are passed
		while len(self.passingCards[passTo]) < cardsToPass: # pass three cards
			passCard = None
			while passCard is None: # make sure string passed is valid
				passCard = self.players[index].play(option='pass')
				if passCard is not None:
					# remove card from player hand and add to passed cards
					self.passingCards[passTo].append(passCard)
					self.players[index].removeCard(passCard)

	def distributePassedCards(self):
		for i,passed in enumerate(self.passingCards):
			for card in passed:
				self.players[i].addCard(card)
		self.passingCards = [[], [], [], []]


#.........这里部分代码省略.........
开发者ID:danielcorin,项目名称:Hearts,代码行数:103,代码来源:Hearts.py


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