本文整理汇总了Python中CombatRatingsAI.get_empire_standard_fighter方法的典型用法代码示例。如果您正苦于以下问题:Python CombatRatingsAI.get_empire_standard_fighter方法的具体用法?Python CombatRatingsAI.get_empire_standard_fighter怎么用?Python CombatRatingsAI.get_empire_standard_fighter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CombatRatingsAI
的用法示例。
在下文中一共展示了CombatRatingsAI.get_empire_standard_fighter方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __clean_fleet_roles
# 需要导入模块: import CombatRatingsAI [as 别名]
# 或者: from CombatRatingsAI import get_empire_standard_fighter [as 别名]
def __clean_fleet_roles(self, just_resumed=False):
"""Removes fleetRoles if a fleet has been lost, and update fleet Ratings."""
universe = fo.getUniverse()
current_empire_fleets = FleetUtilsAI.get_empire_fleet_ids()
self.shipCount = 0
destroyed_object_ids = universe.destroyedObjectIDs(fo.empireID())
fleet_table = Table([
Text('Fleet'), Float('Rating'), Float('Troops'),
Text('Location'), Text('Destination')],
table_name="Fleet Summary Turn %d" % fo.currentTurn()
)
# need to loop over a copy as entries are deleted in loop
for fleet_id in list(self.__fleetRoleByID):
fleet_status = self.fleetStatus.setdefault(fleet_id, {})
rating = CombatRatingsAI.get_fleet_rating(fleet_id, self.get_standard_enemy())
old_sys_id = fleet_status.get('sysID', -2) # TODO: Introduce helper function instead
fleet = universe.getFleet(fleet_id)
if fleet:
sys_id = fleet.systemID
if old_sys_id in [-2, -1]:
old_sys_id = sys_id
fleet_status['nships'] = len(fleet.shipIDs) # TODO: Introduce helper function instead
self.shipCount += fleet_status['nships']
else:
# can still retrieve a fleet object even if fleet was just destroyed, so shouldn't get here
# however,this has been observed happening, and is the reason a fleet check was added a few lines below.
# Not at all sure how this came about, but was throwing off threat assessments
sys_id = old_sys_id
# check if fleet is destroyed and if so, delete stored information
if fleet_id not in current_empire_fleets: # or fleet.empty:
# TODO(Morlic): Is this condition really correct? Seems like should actually be in destroyed object ids
if (fleet and self.__fleetRoleByID.get(fleet_id, -1) != -1 and
fleet_id not in destroyed_object_ids and
any(ship_id not in destroyed_object_ids for ship_id in fleet.shipIDs)):
if not just_resumed:
fleetsLostBySystem.setdefault(old_sys_id, []).append(max(rating, MilitaryAI.MinThreat))
self.delete_fleet_info(fleet_id)
continue
# if reached here, the fleet does still exist
this_sys = universe.getSystem(sys_id)
next_sys = universe.getSystem(fleet.nextSystemID)
fleet_table.add_row([
fleet,
rating,
FleetUtilsAI.count_troops_in_fleet(fleet_id),
this_sys or 'starlane',
next_sys or '-',
])
fleet_status['rating'] = rating
if next_sys:
fleet_status['sysID'] = next_sys.id
elif this_sys:
fleet_status['sysID'] = this_sys.id
else:
error("Fleet %s has no valid system." % fleet)
info(fleet_table)
# Next string used in charts. Don't modify it!
print "Empire Ship Count: ", self.shipCount
print "Empire standard fighter summary: ", CombatRatingsAI.get_empire_standard_fighter().get_stats()
print "------------------------"
示例2: __clean_fleet_roles
# 需要导入模块: import CombatRatingsAI [as 别名]
# 或者: from CombatRatingsAI import get_empire_standard_fighter [as 别名]
def __clean_fleet_roles(self, just_resumed=False):
"""Removes fleetRoles if a fleet has been lost, and update fleet Ratings."""
for sys_id in self.systemStatus:
self.systemStatus[sys_id]['myFleetRating'] = 0
self.systemStatus[sys_id]['myFleetRatingVsPlanets'] = 0
universe = fo.getUniverse()
ok_fleets = FleetUtilsAI.get_empire_fleet_ids()
fleet_list = sorted(list(self.__fleetRoleByID))
ship_count = 0
destroyed_object_ids = universe.destroyedObjectIDs(fo.empireID())
fleet_table = Table([
Text('Fleet'), Float('Rating'), Float('Troops'),
Text('Location'), Text('Destination')],
table_name="Fleet Summary Turn %d" % fo.currentTurn()
)
for fleet_id in fleet_list:
status = self.fleetStatus.setdefault(fleet_id, {})
rating = CombatRatingsAI.get_fleet_rating(fleet_id, self.get_standard_enemy())
troops = FleetUtilsAI.count_troops_in_fleet(fleet_id)
old_sys_id = status.get('sysID', -2)
fleet = universe.getFleet(fleet_id)
if fleet:
sys_id = fleet.systemID
if old_sys_id in [-2, -1]:
old_sys_id = sys_id
status['nships'] = len(fleet.shipIDs)
ship_count += status['nships']
else:
sys_id = old_sys_id # can still retrieve a fleet object even if fleet was just destroyed, so shouldn't get here
# however,this has been observed happening, and is the reason a fleet check was added a few lines below.
# Not at all sure how this came about, but was throwing off threat assessments
if fleet_id not in ok_fleets: # or fleet.empty:
if (fleet and self.__fleetRoleByID.get(fleet_id, -1) != -1 and fleet_id not in destroyed_object_ids and
[ship_id for ship_id in fleet.shipIDs if ship_id not in destroyed_object_ids]):
if not just_resumed:
fleetsLostBySystem.setdefault(old_sys_id, []).append(max(rating, MilitaryAI.MinThreat))
if fleet_id in self.__fleetRoleByID:
del self.__fleetRoleByID[fleet_id]
if fleet_id in self.__aiMissionsByFleetID:
del self.__aiMissionsByFleetID[fleet_id]
if fleet_id in self.fleetStatus:
del self.fleetStatus[fleet_id]
continue
else: # fleet in ok fleets
this_sys = universe.getSystem(sys_id)
next_sys = universe.getSystem(fleet.nextSystemID)
fleet_table.add_row(
[
fleet,
rating,
troops,
this_sys or 'starlane',
next_sys or '-',
])
status['rating'] = rating
if next_sys:
status['sysID'] = next_sys.id
elif this_sys:
status['sysID'] = this_sys.id
else:
main_mission = self.get_fleet_mission(fleet_id)
main_mission_type = (main_mission.getAIMissionTypes() + [-1])[0]
if main_mission_type != -1:
targets = main_mission.getAITargets(main_mission_type)
if targets:
m_mt0 = targets[0]
if isinstance(m_mt0.target_type, System):
status['sysID'] = m_mt0.target.id # hmm, but might still be a fair ways from here
fleet_table.print_table()
self.shipCount = ship_count
# Next string used in charts. Don't modify it!
print "Empire Ship Count: ", ship_count
print "Empire standard fighter summary: ", CombatRatingsAI.get_empire_standard_fighter().get_stats()
print "------------------------"
示例3: __update_system_status
# 需要导入模块: import CombatRatingsAI [as 别名]
# 或者: from CombatRatingsAI import get_empire_standard_fighter [as 别名]
def __update_system_status(self):
print 10 * "=", "Updating System Threats", 10 * "="
universe = fo.getUniverse()
empire = fo.getEmpire()
empire_id = fo.empireID()
destroyed_object_ids = universe.destroyedObjectIDs(empire_id)
supply_unobstructed_systems = set(empire.supplyUnobstructedSystems)
min_hidden_attack = 4
min_hidden_health = 8
observed_empires = self.misc.setdefault("observed_empires", set())
# TODO: Variables that are recalculated each turn from scratch should not be stored in AIstate
# clear previous game state
for sys_id in self.systemStatus:
self.systemStatus[sys_id]['enemy_ship_count'] = 0
self.systemStatus[sys_id]['myFleetRating'] = 0
self.systemStatus[sys_id]['myFleetRatingVsPlanets'] = 0
# for use in debugging
verbose = False
# assess enemy fleets that may have been momentarily visible
enemies_by_system = {}
my_fleets_by_system = {}
fleet_spot_position = {}
current_turn = fo.currentTurn()
for fleet_id in universe.fleetIDs:
fleet = universe.getFleet(fleet_id)
if not fleet or fleet.empty:
self.delete_fleet_info(fleet_id) # this is safe even if fleet wasn't mine
continue
# TODO: check if currently in system and blockaded before accepting destination as location
this_system_id = fleet.nextSystemID if fleet.nextSystemID != INVALID_ID else fleet.systemID
dead_fleet = fleet_id in destroyed_object_ids
if dead_fleet:
self.delete_fleet_info(fleet_id)
if fleet.ownedBy(empire_id):
if not dead_fleet:
my_fleets_by_system.setdefault(this_system_id, []).append(fleet_id)
fleet_spot_position.setdefault(fleet.systemID, []).append(fleet_id)
continue
# TODO: consider checking death of individual ships. If ships had been moved from this fleet
# into another fleet, we might have witnessed their death in that other fleet but if this fleet
# had not been seen since before that transfer then the ships might also still be listed here.
if dead_fleet:
continue
# we are only interested in immediately recent data
if get_partial_visibility_turn(fleet_id) < (current_turn - 1):
continue
sys_status = self.systemStatus.setdefault(this_system_id, {})
sys_status['enemy_ship_count'] = sys_status.get('enemy_ship_count', 0) + len(fleet.shipIDs)
enemies_by_system.setdefault(this_system_id, []).append(fleet_id)
if not fleet.unowned:
self.misc.setdefault('enemies_sighted', {}).setdefault(current_turn, []).append(fleet_id)
observed_empires.add(fleet.owner)
# assess fleet and planet threats & my local fleets
for sys_id in universe.systemIDs:
sys_status = self.systemStatus.setdefault(sys_id, {})
system = universe.getSystem(sys_id)
if verbose:
print "AIState threat evaluation for %s" % system
# update fleets
sys_status['myfleets'] = my_fleets_by_system.get(sys_id, [])
sys_status['myFleetsAccessible'] = fleet_spot_position.get(sys_id, [])
local_enemy_fleet_ids = enemies_by_system.get(sys_id, [])
sys_status['localEnemyFleetIDs'] = local_enemy_fleet_ids
if system:
sys_status['name'] = system.name
# update threats
monster_ratings = [] # immobile
enemy_ratings = [] # owned & mobile
mob_ratings = [] # mobile & unowned
mobile_fleets = [] # mobile and either owned or unowned
for fid in local_enemy_fleet_ids:
fleet = universe.getFleet(fid) # ensured to exist
fleet_rating = CombatRatingsAI.get_fleet_rating(
fid, enemy_stats=CombatRatingsAI.get_empire_standard_fighter())
if fleet.speed == 0:
monster_ratings.append(fleet_rating)
if verbose:
print "\t immobile enemy fleet %s has rating %.1f" % (fleet, fleet_rating)
continue
if verbose:
print "\t mobile enemy fleet %s has rating %.1f" % (fleet, fleet_rating)
mobile_fleets.append(fid)
if fleet.unowned:
mob_ratings.append(fleet_rating)
else:
enemy_ratings.append(fleet_rating)
enemy_rating = CombatRatingsAI.combine_ratings_list(enemy_ratings)
monster_rating = CombatRatingsAI.combine_ratings_list(monster_ratings)
#.........这里部分代码省略.........
示例4: update_system_status
# 需要导入模块: import CombatRatingsAI [as 别名]
# 或者: from CombatRatingsAI import get_empire_standard_fighter [as 别名]
def update_system_status(self):
print 10 * "=", "Updating System Threats", 10 * "="
universe = fo.getUniverse()
empire = fo.getEmpire()
empire_id = fo.empireID()
destroyed_object_ids = universe.destroyedObjectIDs(empire_id)
supply_unobstructed_systems = set(empire.supplyUnobstructedSystems)
min_hidden_attack = 4
min_hidden_health = 8
system_id_list = universe.systemIDs # will normally look at this, the list of all known systems
# for use in debugging
verbose = False
# assess enemy fleets that may have been momentarily visible
cur_e_fighters = {CombatRatingsAI.default_ship_stats().get_stats(hashable=True): [0]} # start with a dummy entry
old_e_fighters = {CombatRatingsAI.default_ship_stats().get_stats(hashable=True): [0]} # start with a dummy entry
enemy_fleet_ids = []
enemies_by_system = {}
my_fleets_by_system = {}
fleet_spot_position = {}
saw_enemies_at_system = {}
my_milship_rating = MilitaryAI.cur_best_mil_ship_rating()
current_turn = fo.currentTurn()
for fleet_id in universe.fleetIDs:
fleet = universe.getFleet(fleet_id)
if fleet is None:
continue
if not fleet.empty:
# TODO: check if currently in system and blockaded before accepting destination as location
this_system_id = (fleet.nextSystemID != INVALID_ID and fleet.nextSystemID) or fleet.systemID
if fleet.ownedBy(empire_id):
if fleet_id not in destroyed_object_ids:
my_fleets_by_system.setdefault(this_system_id, []).append(fleet_id)
fleet_spot_position.setdefault(fleet.systemID, []).append(fleet_id)
else:
dead_fleet = fleet_id in destroyed_object_ids
if not fleet.ownedBy(-1) and (fleet.hasArmedShips or fleet.hasFighterShips):
ship_stats = CombatRatingsAI.FleetCombatStats(fleet_id).get_ship_stats(hashable=True)
e_f_dict = [cur_e_fighters, old_e_fighters][dead_fleet] # track old/dead enemy fighters for rating assessments in case not enough current info
for stats in ship_stats:
attacks = stats[0]
if attacks:
e_f_dict.setdefault(stats, [0])[0] += 1
partial_vis_turn = universe.getVisibilityTurnsMap(fleet_id, empire_id).get(fo.visibility.partial, -9999)
if not dead_fleet:
# TODO: consider checking death of individual ships. If ships had been moved from this fleet
# into another fleet, we might have witnessed their death in that other fleet but if this fleet
# had not been seen since before that transfer then the ships might also still be listed here.
sys_status = self.systemStatus.setdefault(this_system_id, {})
sys_status['enemy_ship_count'] = sys_status.get('enemy_ship_count', 0) + len(fleet.shipIDs)
if partial_vis_turn >= current_turn - 1: # only interested in immediately recent data
saw_enemies_at_system[fleet.systemID] = True
enemy_fleet_ids.append(fleet_id)
enemies_by_system.setdefault(this_system_id, []).append(fleet_id)
if not fleet.ownedBy(-1):
self.misc.setdefault('enemies_sighted', {}).setdefault(current_turn, []).append(fleet_id)
rating = CombatRatingsAI.get_fleet_rating(fleet_id, enemy_stats=CombatRatingsAI.get_empire_standard_fighter())
if rating > 0.25 * my_milship_rating:
self.misc.setdefault('dangerous_enemies_sighted', {}).setdefault(current_turn, []).append(fleet_id)
e_f_dict = [cur_e_fighters, old_e_fighters][len(cur_e_fighters) == 1]
std_fighter = sorted([(v, k) for k, v in e_f_dict.items()])[-1][1]
self.__empire_standard_enemy = std_fighter
self.empire_standard_enemy_rating = self.get_standard_enemy().get_rating()
# TODO: If no current information available, rate against own fighters
# assess fleet and planet threats & my local fleets
for sys_id in system_id_list:
sys_status = self.systemStatus.setdefault(sys_id, {})
system = universe.getSystem(sys_id)
if verbose:
print "AIState threat evaluation for %s" % system
# update fleets
sys_status['myfleets'] = my_fleets_by_system.get(sys_id, [])
sys_status['myFleetsAccessible'] = fleet_spot_position.get(sys_id, [])
local_enemy_fleet_ids = enemies_by_system.get(sys_id, [])
sys_status['localEnemyFleetIDs'] = local_enemy_fleet_ids
if system:
sys_status['name'] = system.name
for fid in system.fleetIDs:
if fid in destroyed_object_ids: # TODO: double check are these checks/deletes necessary?
self.delete_fleet_info(fid) # this is safe even if fleet wasn't mine
continue
fleet = universe.getFleet(fid)
if not fleet or fleet.empty:
self.delete_fleet_info(fid) # this is safe even if fleet wasn't mine
continue
# update threats
sys_vis_dict = universe.getVisibilityTurnsMap(sys_id, fo.empireID())
partial_vis_turn = sys_vis_dict.get(fo.visibility.partial, -9999)
mob_ratings = [] # for mobile unowned monster fleets
lost_fleet_rating = 0
enemy_ratings = []
monster_ratings = []
mobile_fleets = []
for fid in local_enemy_fleet_ids:
fleet = universe.getFleet(fid)
if not fleet:
continue
#.........这里部分代码省略.........