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


Python Store.buy方法代码示例

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


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

示例1: test_buy

# 需要导入模块: from store import Store [as 别名]
# 或者: from store.Store import buy [as 别名]
 def test_buy(self):
     store = Store(2)
     count = 8
     while count > 0:
         buy_res = store.buy("PROVINCE")
         count -= 1
         self.assertEqual(store.base_inventory["PROVINCE"], count)
         self.assertEqual(buy_res, "PROVINCE")
     self.assertEqual(store.buy("PROVINCE"), None)
     self.assertEqual(store.buy("PROVINCE"), None)
     self.assertEqual(store.base_inventory["PROVINCE"], 0)
开发者ID:jhorowitz16,项目名称:dominion,代码行数:13,代码来源:storetest.py

示例2: __init__

# 需要导入模块: from store import Store [as 别名]
# 或者: from store.Store import buy [as 别名]
class Game:

    # default switches is only mid game
    def __init__(self, switches=(0, 100)):
        # initialize the starting deck here instead
        self.deck = Deck()
        self.turn = 0
        self.deck.fullPrint(self.turn)


        self.earlyBuy = priorityBuy(Card.money_types + ['LABORATORY'])
        self.midBuy = priorityBuy(Card.money_types + ['LABORATORY'] + ['PROVINCE'])
        self.lateBuy = priorityBuy(Card.victory_types)

        self.switches = switches

        self.store = Store()

        # self.earlyBuy = priorityBuy(Card.money_types)
        # self.midBuy = priorityBuy(Card.money_types + ['PROVINCE'])
        # self.lateBuy = self.midBuy


        if ASSERTS:
            assert self.midBuy(1) == ''
            assert self.earlyBuy(3) == 'SILVER'
            assert self.earlyBuy(5) == 'LABORATORY'
            assert self.earlyBuy(6) == 'GOLD'
            assert self.earlyBuy(8) == 'GOLD'

            assert self.midBuy(1) == ''
            assert self.midBuy(3) == 'SILVER'
            assert self.midBuy(5) == 'LABORATORY'
            assert self.midBuy(6) == 'GOLD'
            assert self.midBuy(8) == 'PROVINCE'

            assert self.lateBuy(1) == ''
            assert self.lateBuy(3) == 'ESTATE'
            # assert self.lateBuy(5) == 'DUCHYzz' # test to fail
            assert self.lateBuy(6) == 'DUCHY'
            assert self.lateBuy(8) == 'PROVINCE'

    def buyCardType(self, newCard):
        """
        same as the old self.deck.addCardType(newCard)
        but ... also remove the corresponding card from the Store

        if the store buy fails,
            then will return None, otherwise the card
        """

        if not self.store.buy(newCard):
            return None
        return self.deck.addCardType(newCard)



    # ABC
    # Action
    # Buy
    # Collect
    def takeTurn(self):
        return_info = {} # for playing around with events - to get feedback in main

        self.turn += 1
        self.deck.drawHand()
        self.deck.fullPrint(self.turn) # hand right after drawing it
        return_info['money'] = self.deck.calcHandMoney()
        return_info['turn'] = self.turn
        return_info['vp'] = self.deck.total_vp

        stats = self.simpleCalcPlay()
        dp(stats)
        # self.moneyBuy(stats['money'], True)
        self.phaseBuys(stats['money']) # before turn 8, early game, before turn 10, mid game
        self.deck.cleanUp()

        return return_info

    def takeTurnProv(self):
        """
        take money, and provinces
        """
        money =  self.deck.calcHandMoney()

        result = self.moneyBuyWithStore(money, True)
        if result != "GAMEOVER":
            dp("take turn prov END GAME")
        return result




    # smart buy - switches is a tuple signaling when to switch strategies
    # ex - (5, 10) - before turn 5 early game, before turn 10 mid game, then late game (all VPs)
    # goal - find the optimal constants
    def phaseBuys(self, money):
        # init idea
        # early game - no vps no matter what
        # mid game - best buy, including provinces
#.........这里部分代码省略.........
开发者ID:jhorowitz16,项目名称:dominion,代码行数:103,代码来源:game.py


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