本文整理汇总了Python中rules.Rules.addUnits方法的典型用法代码示例。如果您正苦于以下问题:Python Rules.addUnits方法的具体用法?Python Rules.addUnits怎么用?Python Rules.addUnits使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rules.Rules
的用法示例。
在下文中一共展示了Rules.addUnits方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from rules import Rules [as 别名]
# 或者: from rules.Rules import addUnits [as 别名]
#.........这里部分代码省略.........
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
if type(country) != type('string') and type(country) != type(u'string'):
return False
if country not in self.countries:
return False
if not self.isOwned(country, player):
return False
if type(howMany) != type(1):
return False
if howMany>self.reinforcementsToPlace[player]:
return False
if howMany < 0:
return False
if self.rules.addUnits(country, howMany):
self.reinforcementsToPlace[player]=self.reinforcementsToPlace[player]-howMany
self.updateTurn()
return True
else:
return False
def player_attack(self,fromCountry,toCountry,howMany,player):
if self.whosTurn != player:
#raise Exception, 'player error'
return False
if self.turnStage != 'attacks':
#raise Exception, 'its not in the attack stage'
return False
if type(fromCountry)!=type('string') and type(fromCountry) != type(u'string'):
#raise Exception, 'from country is not a string'
return False
if type(toCountry)!=type('string') and type(fromCountry) != type(u'string'):
#raise Exception, 'to country is not a string'
return False
if type(player)!=type('string') and type(player) != type(u'string'):
#raise Exception, 'player is not a string'
return False
if type(howMany)!=type(1):
#raise Exception, 'how many is not a number'
return False
if not fromCountry in self.countries:
#raise Exception, 'from country is not a country'
return False
if not toCountry in self.countries:
#raise Exception, 'to country is not a country'
return False
if not player in self.players: