• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python stacks.stack函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中stacks.stack函数的典型用法代码示例。如果您正苦于以下问题:Python stack函数的具体用法?Python stack怎么用?Python stack使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了stack函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()
开发者ID:nastevens,项目名称:sandbox,代码行数:7,代码来源:hands_tomake_ut.py


示例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())
开发者ID:nastevens,项目名称:sandbox,代码行数:7,代码来源:hands_tomake_ut.py


示例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)
开发者ID:nastevens,项目名称:sandbox,代码行数:60,代码来源:hands.py


示例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())
开发者ID:nastevens,项目名称:sandbox,代码行数:8,代码来源:hands_tomake_ut.py


示例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())
开发者ID:nastevens,项目名称:sandbox,代码行数:8,代码来源:hands_tomake_ut.py


示例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())     
开发者ID:nastevens,项目名称:sandbox,代码行数:9,代码来源:hands_tomake_ut.py


示例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)
开发者ID:nastevens,项目名称:sandbox,代码行数:9,代码来源:hands_tomake_ut.py


示例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())
开发者ID:nastevens,项目名称:sandbox,代码行数:9,代码来源:hands_tomake_ut.py


示例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)
开发者ID:nastevens,项目名称:sandbox,代码行数:9,代码来源:hands_tomake_ut.py


示例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())
开发者ID:nastevens,项目名称:sandbox,代码行数:9,代码来源:hands_tomake_ut.py


示例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())
开发者ID:nastevens,项目名称:sandbox,代码行数:9,代码来源:hands_tomake_ut.py


示例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())
开发者ID:nastevens,项目名称:sandbox,代码行数:9,代码来源:hands_tomake_ut.py


示例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())
开发者ID:nastevens,项目名称:sandbox,代码行数:10,代码来源:hands_tomake_ut.py


示例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)
开发者ID:nastevens,项目名称:sandbox,代码行数:10,代码来源:hands_tomake_ut.py


示例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)
开发者ID:nastevens,项目名称:sandbox,代码行数:11,代码来源:hands_tomake_ut.py


示例16: testAABC

 def testAABC(self):
     '''twoPair_testAABC: Should return cards in B or C's ranks except B or C'''
     teststack = stacks.stack()
     teststack.add(card(1,1))
     teststack.add(card(1,2))
     teststack.add(card(2,1))
     teststack.add(card(3,1))
     result = hands.toMakeTwoPair(teststack)
     workstack = stacks.stack()
     workstack.populate("Rank",card(2,1))
     workstack.populate("Rank",card(3,1))
     self.assertEqual(result,workstack.difference(teststack))
开发者ID:nastevens,项目名称:sandbox,代码行数:12,代码来源:hands_tomake_ut.py


示例17: testFourCardOutsideStraightFlush

 def testFourCardOutsideStraightFlush(self):
     '''Flush_testFourCardOutsideStraightFlush: Four of same suit in a straight should return 
     all in suit except outside card(s)'''
     teststack = stacks.stack()
     teststack.add(card(3,1))
     teststack.add(card(4,1))
     teststack.add(card(5,1))
     teststack.add(card(6,1))
     result = hands.toMakeFlush(teststack)
     workstack = stacks.stack()
     workstack.populate("Suit",1)
     workstack = workstack.difference([card(2,1),card(3,1),card(4,1),card(5,1),card(6,1),card(7,1)])
     self.assertEqual(result,workstack)
开发者ID:nastevens,项目名称:sandbox,代码行数:13,代码来源:hands_tomake_ut.py


示例18: testFourCardRoyalFlush

 def testFourCardRoyalFlush(self):
     '''Flush_testFourCardRoyalFlush: Four of same suit that are in 10-J-Q-K-A should 
     return all in suit except one that completes the royal flush'''
     teststack = stacks.stack()
     teststack.add(card(1,1))
     teststack.add(card(10,1))
     teststack.add(card(11,1))
     teststack.add(card(12,1))
     result = hands.toMakeFlush(teststack)
     workstack = stacks.stack()
     workstack.populate("Suit",1)
     workstack = workstack.difference([card(1,1),card(10,1),card(11,1),card(12,1),card(13,1)])
     self.assertEqual(result,workstack)
开发者ID:nastevens,项目名称:sandbox,代码行数:13,代码来源:hands_tomake_ut.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.get_text函数代码示例发布时间:2022-05-27
下一篇:
Python model.DBSession类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap