本文整理汇总了Python中stacks.stack函数的典型用法代码示例。如果您正苦于以下问题:Python stack函数的具体用法?Python stack怎么用?Python stack使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了stack函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
self.fulldeck = stacks.stack()
self.fulldeck.populate("Full Deck")
self.emptystack = stacks.stack()
self.teststack = stacks.stack()
self.workstack = stacks.stack()
self.goodstack = stacks.stack()
示例2: testAB
def testAB(self):
'''Flush_testAB: Two cards different suits should return nothing'''
teststack = stacks.stack()
teststack.add(card(1,1))
teststack.add(card(2,2))
result = hands.toMakeFlush(teststack)
self.assertEqual(result,stacks.stack())
示例3: toMakeStraight
def toMakeStraight(cards):
if not isinstance(cards,stacks.stack):
raise NotImplementedError, "toMakeStraight only works on stacks"
rset = stacks.stack()
exclude = stacks.stack()
rset.populate("Full Deck")
if (len(cards) < 1): #No cards played yet - anything will work
return rset
if (len(cards) > 4): #Five cards played - nothing else will work
rset.clear()
return rset
if len(cards) == 1 and list(cards)[0].rank() == 1: #Special case for single ace
rset.clear()
for rank in range(10,14)+range(2,6):
rset.populate("Rank",rank)
return rset
if len(cards) == 4 and len(toMakeRoyalFlush(cards)) != 0:
exclude = toMakeRoyalFlush(cards)
invalid = set([-3,-2,-1,0,15,16,17,18])
grouped = groups(cards)
wset = stacks.stack()
maxgroup = max([len(v) for v in grouped]) #Calculates the number of cards in the rank with the most cards
if maxgroup > 1: #If there's more than one in the maxgroup, can't continue to make a straight
rset.clear()
return rset
if len(cards) == 4: #Could bump into a straight flush
flushed = flushes(cards)
maxflush = max([len(v) for v in flushed])
if maxflush >= 4:
for card in cards: wset.populate("Suit",card)
#Calculate max and min rank
ranks = [group[0].rank() for group in grouped if len(group) != 0]
mn = min(ranks)
mx = max(ranks)
ranks.sort()
if 1 in ranks:
spanlo = abs(1-max(ranks))
spanhi = abs(ranks[1]-14)
if min(spanhi,spanlo) == spanlo:
mx = max(ranks)
mn = 1
else:
mx = 14
mn = ranks[1]
span = abs(mx-mn)
else:
span = abs(min(ranks)-max(ranks))
if span > 4: #No good - cards we have are too far apart
rset.clear()
return rset
rset.clear()
adj = 4-span
for rank in set(range(mn-adj,mx+adj+1)).difference(invalid):
rset.populate("Rank",rank)
for card in cards:
wset.populate("Rank",card.rank())
return rset.difference(wset).difference(exclude)
示例4: testAAA
def testAAA(self):
'''Pair_testAAA: Should return nothing (more than a pair)'''
teststack = stacks.stack()
teststack.add(card(1,1))
teststack.add(card(1,2))
teststack.add(card(1,3))
result = hands.toMakePair(teststack)
self.assertEqual(result,stacks.stack())
示例5: testABC
def testABC(self):
'''FourOAK_testABC: Should return nothing'''
teststack = stacks.stack()
teststack.add(card(1,1))
teststack.add(card(2,1))
teststack.add(card(3,1))
result = hands.toMakeFourOAK(teststack)
self.assertEqual(result,stacks.stack())
示例6: testNonRFCards
def testNonRFCards(self):
'''RoyalFlush_testNonRFCards: Should return nothing since a 2-9 can't make a royal flush'''
teststack = stacks.stack()
for rank in range(2,10):
for suit in range(1,5):
teststack.clear()
teststack.add(card(rank,suit))
result = hands.toMakeRoyalFlush(teststack)
self.assertEqual(result,stacks.stack())
示例7: testA
def testA(self):
'''Pair_testA: Should return full deck except A'''
teststack = stacks.stack()
teststack.add(card(1,1))
result = hands.toMakePair(teststack)
workstack = stacks.stack()
workstack.populate("Full Deck")
workstack = workstack.difference([card(1,1)])
self.assertEqual(result,workstack)
示例8: testAABB
def testAABB(self):
'''ThreeOAK_testAABB: Should return nothing (anything from either rank makes a full house)'''
teststack = stacks.stack()
teststack.add(card(1,1))
teststack.add(card(1,2))
teststack.add(card(2,1))
teststack.add(card(2,2))
result = hands.toMakeThreeOAK(teststack)
self.assertEqual(result,stacks.stack())
示例9: testFourCardRF
def testFourCardRF(self):
'''RoyalFlush_testFourcardRF: Should return the one remaining royal flush card'''
teststack = stacks.stack()
teststack.populate("Face Cards",1)
teststack.add(card(10,1))
result = hands.toMakeRoyalFlush(teststack)
goodstack = stacks.stack()
goodstack.add(card(1,1))
self.assertEqual(result,goodstack)
示例10: testABCD
def testABCD(self):
'''FullHouse_testABCD: Should return nothing'''
teststack = stacks.stack()
teststack.add(card(1,1))
teststack.add(card(2,1))
teststack.add(card(3,1))
teststack.add(card(4,1))
result = hands.toMakeFullHouse(teststack)
self.assertEqual(result,stacks.stack())
示例11: testAAAA
def testAAAA(self):
'''ThreeOAK_testAAAA: Should return nothing'''
teststack = stacks.stack()
teststack.add(card(1,1))
teststack.add(card(1,2))
teststack.add(card(1,3))
teststack.add(card(1,4))
result = hands.toMakeThreeOAK(teststack)
self.assertEqual(result,stacks.stack())
示例12: testAAAB
def testAAAB(self):
'''TwoPair_testAAAB: Should return nothing'''
teststack = stacks.stack()
teststack.add(card(1,1))
teststack.add(card(1,2))
teststack.add(card(1,3))
teststack.add(card(2,1))
result = hands.toMakeTwoPair(teststack)
self.assertEqual(result,stacks.stack())
示例13: testFive
def testFive(self):
'''Pair_testFive: Should return nothing'''
teststack = stacks.stack()
teststack.add(card(1,1))
teststack.add(card(2,2))
teststack.add(card(3,3))
teststack.add(card(4,4))
teststack.add(card(5,5))
result = hands.toMakePair(teststack)
self.assertEqual(result,stacks.stack())
示例14: testAA
def testAA(self):
'''Pair_testAA: Should return full deck minus cards in A rank'''
teststack = stacks.stack()
teststack.add(card(1,1))
teststack.add(card(1,2))
result = hands.toMakePair(teststack)
workstack = stacks.stack()
workstack.populate("Full Deck")
workstack = workstack.difference([card(1,1),card(1,2),card(1,3),card(1,4)])
self.assertEqual(result,workstack)
示例15: testAAB
def testAAB(self):
'''ThreeOAK_testAAB: Should return all cards except input'''
teststack = stacks.stack()
teststack.add(card(1,1))
teststack.add(card(1,2))
teststack.add(card(2,1))
result = hands.toMakeThreeOAK(teststack)
workstack = stacks.stack()
workstack.populate("Full Deck")
workstack = workstack.difference(teststack)
self.assertEqual(result,workstack)