本文整理匯總了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
#.........這裏部分代碼省略.........