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


Python Rules.isOwned方法代码示例

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


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

示例1: __init__

# 需要导入模块: from rules import Rules [as 别名]
# 或者: from rules.Rules import isOwned [as 别名]
class Game:
    """Represents the current state of a risk game

    Includes full specification of the map, rules, players and current game state.
    Includes the NAME ONLY of the graphical map file, along with coordinates of territories on this map."""
    def __init__(self,nodeNetwork=None, players={}, bonuses=[], mapString=None, coordinates=None, mapFile=None, settingsMap={}):
        self.mapFile = mapFile
        self.coordinates = coordinates
        self.rules = Rules(map=nodeNetwork, players=players)
        self.whosTurn = self.rules.players[0]
        self.turnStage = 'reinforce'
        self.reinforcementsToPlace = {}
        self.lastAttack = None
        self.fortifies = 1
        if 'fortifies' in settingsMap:
            self.fortifies = int(settingsMap['fortifies'])
        self.fortifiesLeft = self.fortifies
        self.bonuses=bonuses
        for player in self.rules.players:
            self.reinforcementsToPlace[player]=0
        self.reinforced = False
        if not mapString and not (coordinates and mapFile):
            print "this game has no pretty visualization available"
        self.mapString = mapString
        self.settingsMap = settingsMap
        self.fog = False
        if 'fog' in self.settingsMap:
            self.fog = self.settingsMap['fog']
        self.selectionList = []
        self.showAttackResult = False
        self.justMadeFreeMove = False

    def _giveReinforcements(self):
        if self.reinforced == True:
            return False
        else:
            self.reinforced = True
            self.reinforcementsToPlace[self.whosTurn]=self.getDeservedReinforcements(self.whosTurn)

    def player_getFortifiesLeft(self,player):
        """Returns 0 if not the current players turn, otherwise the number of fortifying moves left in the turn"""
        if self.whosTurn != player:
            return 0
        else:
            return self.fortifiesLeft

    def updateTurn(self):
        if self.whosTurn not in self.playersAlive and self.turnStage != 'fortify': # lose condition
            self.turnStage = 'fortify'
            self.fortifiesLeft = 0
            self.updateTurn()
        if len(self.playersAlive) == 1 and self.playersAlive[0] == self.whosTurn:
            self.turnStage = 'reinforce'  # win condition
            self.reinforcementsToPlace[self.whosTurn] = 1
        elif self.turnStage == 'reinforce' and self.reinforcementsToPlace[self.whosTurn]==0:
                self.turnStage = 'attacks'
        elif (self.turnStage == 'fortify' and self.fortifiesLeft == 0) or self.whosTurn not in self.playersAlive:
            players = self.players  # begin new turn
            for i in range(len(players)):
                if self.whosTurn == players[i]:
                    self.whosTurn = players[(i+1)%len(players)]
                    self.reinforcementsToPlace[self.whosTurn] = self.getDeservedReinforcements(self.whosTurn)
                    self.fortifiesLeft = self.fortifies
                    self.turnStage = 'reinforce'
                    self.selectionList = []
                    self.lastAttack = None
                    self.justMadeFreeMove = False
                    self.updateTurn()
                    break

    def getDeservedReinforcements(self,player):
        count = 0
        countriesPerTroop = 3
        if 'countriesPerTroop' in self.settingsMap:
            countriesPerTroop = int(self.settingsMap['countriesPerTroop'])
        countries = self.countries
        for country in countries:
            if self.isOwned(country, player):
                count +=1
        for bonus in self.bonuses:
            deserveBonus = True
            for country in bonus[0:-1]:
                if not self.isOwned(country,player):
                    deserveBonus = False
            if deserveBonus:
                count+=(countriesPerTroop*int(bonus[-1]))
        return max(int(count/countriesPerTroop),3)


    def player_reinforce(self,country,howMany,player):
        pass
        # check for correct turn, right time, have reinforcements, etc.
        if type(player) != type('string') and type(player) != type(u'string'):
            return False
        if self.whosTurn != player:
            return False
        if self.turnStage != 'reinforce':
            return False
        if self.reinforcementsToPlace[player]<=0:
            return False
#.........这里部分代码省略.........
开发者ID:thomasballinger,项目名称:Utok,代码行数:103,代码来源:game.py


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