本文整理汇总了Python中rules.Rules.attack方法的典型用法代码示例。如果您正苦于以下问题:Python Rules.attack方法的具体用法?Python Rules.attack怎么用?Python Rules.attack使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rules.Rules
的用法示例。
在下文中一共展示了Rules.attack方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from rules import Rules [as 别名]
# 或者: from rules.Rules import attack [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
#.........这里部分代码省略.........