From: <dil...@us...> - 2013-07-04 20:28:27
|
Revision: 6223 http://sourceforge.net/p/freeorion/code/6223 Author: dilvish-fo Date: 2013-07-04 20:28:22 +0000 (Thu, 04 Jul 2013) Log Message: ----------- - AI mods, increasing safety margin for considering concentration camps Modified Paths: -------------- trunk/FreeOrion/default/AI/AIstate.py trunk/FreeOrion/default/AI/ColonisationAI.py trunk/FreeOrion/default/AI/FleetUtilsAI.py trunk/FreeOrion/default/AI/MilitaryAI.py trunk/FreeOrion/default/AI/ProductionAI.py trunk/FreeOrion/default/AI/ResourcesAI.py Modified: trunk/FreeOrion/default/AI/AIstate.py =================================================================== --- trunk/FreeOrion/default/AI/AIstate.py 2013-07-04 01:05:53 UTC (rev 6222) +++ trunk/FreeOrion/default/AI/AIstate.py 2013-07-04 20:28:22 UTC (rev 6223) @@ -160,9 +160,11 @@ self.fleetStatus[fleetID]['sysID']= newLoc self.fleetStatus[fleetID]['nships']= len(fleet.shipIDs) if movedFleets: - print "(moved_fleet, oldSys, newSys): %s"%movedFleets + #print "(moved_fleet, oldSys, newSys): %s"%movedFleets + pass else: - print "no moved_fleets this turn" + #print "no moved_fleets this turn" + pass def deleteFleetInfo(self, fleetID, sysID=-1): for systemID in [sid for sid in [sysID, self.fleetStatus.get(fleetID, {}).get('sysID', -1)] if sid != -1]: @@ -182,12 +184,12 @@ if sysIDList is None: sysIDList = sorted( universe.systemIDs )# will normally look at this, the list of all known systems #assess fleet and planet threats - print "----------------------------------------------" - print "System Threat Assessments" - for sysID in sysIDList: - sysStatus = self.systemStatus.get(sysID, {}) - system = universe.getSystem(sysID) - print "System %4d ( %12s ) : %s"%(sysID, (system and system.name) or "unknown", sysStatus) + #print "----------------------------------------------" + #print "System Threat Assessments" + #for sysID in sysIDList: + #sysStatus = self.systemStatus.get(sysID, {}) + #system = universe.getSystem(sysID) + #print "System %4d ( %12s ) : %s"%(sysID, (system and system.name) or "unknown", sysStatus) def assessPlanetThreat(self, pid, sightingAge=0): sightingAge+=1#play it safe @@ -273,13 +275,13 @@ enemyHealth = sum( [rating.get('health', 0) for rating in enemyRatings]) enemyRating = enemyAttack * enemyHealth if fleetsLostBySystem.get(sysID, []) != []: - print " Assessing threats on turn %d ; noting that fleets were just lost in system %d , enemy fleets were %s seen as of turn %d, of which %s survived"%( - currentTurn, sysID, ["not", ""][sawEnemiesAtSystem.get(sysID, False)], partialVisTurn, localEnemyFleetIDs) + #print " Assessing threats on turn %d ; noting that fleets were just lost in system %d , enemy fleets were %s seen as of turn %d, of which %s survived"%( + # currentTurn, sysID, ["not", ""][sawEnemiesAtSystem.get(sysID, False)], partialVisTurn, localEnemyFleetIDs) lostFleetAttack = sum( [rating.get('attack', 0) for rating in fleetsLostBySystem.get(sysID, {}) ] ) lostFleetHealth = sum( [rating.get('health', 0) for rating in fleetsLostBySystem.get(sysID, {} ) ] ) lostFleetRating= lostFleetAttack * lostFleetHealth if (not system) or partialVisTurn==-9999: - print "Have never had partial vis for system %d ( %s ) -- basing threat assessment on old info and lost ships"%(sysID, sysStatus.get('name', "name unknown")) + #print "Have never had partial vis for system %d ( %s ) -- basing threat assessment on old info and lost ships"%(sysID, sysStatus.get('name', "name unknown")) sysStatus['planetThreat'] = 0 sysStatus['fleetThreat'] = int( max(enemyRating, 0.98*sysStatus.get('fleetThreat', 0) , 1.1*lostFleetRating) ) sysStatus['monsterThreat']=0 @@ -309,7 +311,7 @@ lostFleetRating=0 if not partialVisTurn == currentTurn: #(universe.getVisibility(sysID, self.empireID) >= fo.visibility.partial): - print "Stale visibility for system %d ( %s ) -- last seen %d, current Turn %d -- basing threat assessment on old info and lost ships"%(sysID, sysStatus.get('name', "name unknown"), partialVisTurn, currentTurn) + #print "Stale visibility for system %d ( %s ) -- last seen %d, current Turn %d -- basing threat assessment on old info and lost ships"%(sysID, sysStatus.get('name', "name unknown"), partialVisTurn, currentTurn) sysStatus['fleetThreat'] = int( max(enemyRating, 0.98*sysStatus.get('fleetThreat', 0), 1.1*lostFleetRating) ) sysStatus['totalThreat'] = (pattack + enemyAttack + sysStatus.get('monsterThreat', 0)**0.5) * (phealth + enemyHealth + sysStatus.get('monsterThreat', 0)**0.5) else: #system considered visible #TODO: reevaluate as visibility rules change @@ -567,7 +569,7 @@ "removes a fleet ID/role pair" if fleetID in self.__fleetRoleByID: - print "Removed role for fleet ID: " + str(fleetID) + #print "Removed role for fleet ID: " + str(fleetID) del self.__fleetRoleByID[fleetID] return @@ -610,7 +612,7 @@ if unaccountedFleets: print "Fleets unaccounted for in Empire Records: ", unaccountedFleets print "-----------" - print "statusList %s"%[self.fleetStatus[fid] for fid in sorted( self.fleetStatus.keys() ) ] + #print "statusList %s"%[self.fleetStatus[fid] for fid in sorted( self.fleetStatus.keys() ) ] print "-----------" minThreatRating = {'overall':MinThreat, 'attack':MinThreat**0.5, 'health':MinThreat**0.5} for fleetID in fleetList: @@ -638,7 +640,7 @@ fleetsLostBySystem.setdefault(oldSysID, []).append( minThreatRating ) sys=universe.getSystem(sysID) sysName=(sys and sys.name) or "unknown" - print "Fleet %d with role %s was used up, lost or destroyed at sys (%d) %s"%(fleetID, self.__fleetRoleByID[fleetID], sysID, sysName) #perhaps diff message for successful colony fleets + #print "Fleet %d with role %s was used up, lost or destroyed at sys (%d) %s"%(fleetID, self.__fleetRoleByID[fleetID], sysID, sysName) #perhaps diff message for successful colony fleets if fleetID in self.__fleetRoleByID: del self.__fleetRoleByID[fleetID] @@ -659,8 +661,8 @@ sys2Name= 'starlane' else: sys2Name = (sys2 and sys2.name ) or "unknown" - print "Fleet %d (%s) oldRating: %6d | newRating %6d | at system %d (%s) | next system %d (%s)"%(fleetID, fleet.name, rating.get('overall', 0), newRating.get('overall', 0), - fleet.systemID, sys1Name, fleet.nextSystemID, sys2Name) + #print "Fleet %d (%s) oldRating: %6d | newRating %6d | at system %d (%s) | next system %d (%s)"%(fleetID, fleet.name, rating.get('overall', 0), newRating.get('overall', 0), + # fleet.systemID, sys1Name, fleet.nextSystemID, sys2Name) status['rating'] = newRating if nextSysID !=-1: status['sysID'] = nextSysID Modified: trunk/FreeOrion/default/AI/ColonisationAI.py =================================================================== --- trunk/FreeOrion/default/AI/ColonisationAI.py 2013-07-04 01:05:53 UTC (rev 6222) +++ trunk/FreeOrion/default/AI/ColonisationAI.py 2013-07-04 20:28:22 UTC (rev 6223) @@ -45,6 +45,12 @@ "gaia": [ 0, 3, 3, 3, 3 ], } +nestValMap = { + "SNOWFLAKE_NEST_SPECIAL": 5, + "KRAKEN_NEST_SPECIAL":10, + "JUGGERNAUT_NEST_SPECIAL":20, + } + def dictFromMap(map): return dict( [ (el.key(), el.data() ) for el in map ] ) def resetCAIGlobals(): @@ -223,8 +229,9 @@ if pID not in oldPopCtrs: if (AIFocusType.FOCUS_MINING in planet.availableFoci): fo.issueChangeFocusOrder(pID, AIFocusType.FOCUS_MINING) - print "Changing focus of newly acquired planet ID %d : %s to mining "%(pID, planet.name ) - empireSpecies.setdefault(pSpecName, []).append(pID) + print "Changing focus of newly acquired planet ID %d : %s to mining "%(pID, planet.name ) #stale code left as an example; Mining no longer an option + if planet.currentMeterValue(fo.meterType.population)>0 : + empireSpecies.setdefault(pSpecName, []).append(pID) print "\n"+"Empire species roster:" for specName in empireSpecies: thisSpec=fo.getSpecies(specName) @@ -587,9 +594,11 @@ if (missionType == AIFleetMissionType.FLEET_MISSION_OUTPOST ): for special in planetSpecials: + nestVal = 0 if "_NEST_" in special: - retval+=5*discountMultiplier*backupFactor # get an outpost on the nest quick - detail.append( "%s %.1f"%(special, discountMultiplier*5*backupFactor ) ) + nestVal = nestValMap.get(special, 5) * discountMultiplier*backupFactor # get an outpost on the nest quick + retval+=nestVal + detail.append( "%s %.1f"%(special, nestVal ) ) if ( planet.size == fo.planetSize.asteroids ): if (empire.getTechStatus("PRO_MICROGRAV_MAN") == fo.techStatus.complete ): if system: @@ -1002,7 +1011,7 @@ if thisPlanetID in alreadyTargeted: continue thisPlanet = universe.getPlanet(thisPlanetID) - print "checking pool %s against target %s current owner %s targetSpec %s"%(fleetPool, thisPlanet.name, thisPlanet.owner, thisTarget) + #print "checking pool %s against target %s current owner %s targetSpec %s"%(fleetPool, thisPlanet.name, thisPlanet.owner, thisTarget) thisSysID = thisPlanet.systemID if (foAI.foAIstate.systemStatus.setdefault(thisSysID, {}).setdefault('monsterThreat', 0) > 2000) or (fo.currentTurn() <20 and foAI.foAIstate.systemStatus[thisSysID]['monsterThreat'] > 200): print "Skipping colonization of system %s due to Big Monster, threat %d"%(PlanetUtilsAI.sysNameIDs([thisSysID]), foAI.foAIstate.systemStatus[thisSysID]['monsterThreat']) Modified: trunk/FreeOrion/default/AI/FleetUtilsAI.py =================================================================== --- trunk/FreeOrion/default/AI/FleetUtilsAI.py 2013-07-04 01:05:53 UTC (rev 6222) +++ trunk/FreeOrion/default/AI/FleetUtilsAI.py 2013-07-04 20:28:22 UTC (rev 6223) @@ -195,20 +195,23 @@ transferredRating += thisRating transferredAttack += stats['attack'] transferredHealth += ( stats['structure'] + stats['shields'] ) - print "\t\t\t\t *** attempting transfer of ship %4d, formerly of fleet %4d, into fleet %4d with result %d; %s"%(shipID, fleetA_ID, fleetB_ID, thisSuccess, [" context is %s"%context, ""][context==""]) + else: + print "\t\t\t\t *** attempted transfer of ship %4d, formerly of fleet %4d, into fleet %4d with result %d; %s"%(shipID, fleetA_ID, fleetB_ID, thisSuccess, [" context is %s"%context, ""][context==""]) success = success and thisSuccess if needRating !=0 and needRating <= transferredAttack*transferredHealth: #transferredRating: break fleetA = universe.getFleet(fleetA_ID) if (not fleetA) or fleetA.empty or fleetA_ID in universe.destroyedObjectIDs(fo.empireID()): - print "\t\t\t\t\tdeleting fleet info for old fleet %d after transfers into fleet %d"%(fleetA_ID, fleetB_ID) + #print "\t\t\t\t\tdeleting fleet info for old fleet %d after transfers into fleet %d"%(fleetA_ID, fleetB_ID) foAI.foAIstate.deleteFleetInfo(fleetA_ID) else: newARating = foAI.foAIstate.updateFleetRating(fleetA_ID) if success : #and ( newARating==remainingRating) : - print "\t\t\t\t\t\t\%d rating from fleet %d successfully transferred to fleet %d, leaving %d"%(transferredAttack*transferredHealth, fleetA_ID, fleetB_ID, newARating['overall']) + #print "\t\t\t\t\t\t\%d rating from fleet %d successfully transferred to fleet %d, leaving %d"%(transferredAttack*transferredHealth, fleetA_ID, fleetB_ID, newARating['overall']) + pass else: - print "\t\t\t\t\t\t transfer of %d rating from fleet %d to fleet %d was attempted but appears to have had problems, leaving %d"%(transferredAttack*transferredHealth, fleetA_ID, fleetB_ID, newARating['overall']) + #print "\t\t\t\t\t\t transfer of %d rating from fleet %d to fleet %d was attempted but appears to have had problems, leaving %d"%(transferredAttack*transferredHealth, fleetA_ID, fleetB_ID, newARating['overall']) + pass foAI.foAIstate.updateFleetRating(fleetB_ID) return transferredAttack*transferredHealth, transferredAttack, transferredHealth @@ -324,8 +327,8 @@ selectedRole= AIFleetMissionType.FLEET_MISSION_MILITARY else: selectedRole= AIShipRoleType.SHIP_ROLE_INVALID - print "fleetID %d : primary fleet mission type %d: '%s' ; found ship roles %s : %s ; rating %d"%(fleetID,selectedRole, __AIFleetMissionTypeNames.name(selectedRole), - shipRoles, [ "%s: %d "%(__AIShipRoleTypeNames.name(rtype), rnum) for rtype, rnum in shipRoles.items()] , foAI.foAIstate.getRating(fleetID).get('overall', 0)) + #print "fleetID %d : primary fleet mission type %d: '%s' ; found ship roles %s : %s ; rating %d"%(fleetID,selectedRole, __AIFleetMissionTypeNames.name(selectedRole), + # shipRoles, [ "%s: %d "%(__AIShipRoleTypeNames.name(rtype), rnum) for rtype, rnum in shipRoles.items()] , foAI.foAIstate.getRating(fleetID).get('overall', 0)) return selectedRole def assessShipDesignRole(design): @@ -350,10 +353,10 @@ if design.starlaneSpeed == 0: string1 = "Ship Design %s has partslist %s"%(design.name(False), [part for part in design.parts]) if len(design.parts)==0 or design.parts[0] in [ "SH_DEFENSE_GRID", "SH_DEFLECTOR" , "SH_MULTISPEC" ] or (len(design.parts)==1 and design.parts[0]==''): - print string1, "-- classifying as Base Defense" + #print string1, "-- classifying as Base Defense" return AIShipRoleType.SHIP_ROLE_BASE_DEFENSE else: - print string1, "-- classifying as Invalid" + #print string1, "-- classifying as Invalid" return AIShipRoleType.SHIP_ROLE_INVALID stats = foAI.foAIstate.getDesignStats(design) Modified: trunk/FreeOrion/default/AI/MilitaryAI.py =================================================================== --- trunk/FreeOrion/default/AI/MilitaryAI.py 2013-07-04 01:05:53 UTC (rev 6222) +++ trunk/FreeOrion/default/AI/MilitaryAI.py 2013-07-04 20:28:22 UTC (rev 6223) @@ -16,6 +16,7 @@ minMilAllocations = {} totMilRating=0 milShips=0 +verboseMilReporting=False def tryAgain(milFleetIDs, tryReset=False, round=""): for fid in milFleetIDs: @@ -173,16 +174,18 @@ allocationGroups.setdefault('capitol', []).append( ( capitalSysID, newAlloc, True, 2*capitalThreat) ) remainingMilRating -= newAlloc if "Main" in round or newAlloc >0: - print "Empire Capital System: (%d) %s -- threat : %d, military allocation: existing: %d ; new: %d"%(capitalSysID, universe.getSystem(capitalSysID).name , capitalThreat, alreadyAssignedRating[capitalSysID], newAlloc) - print "-----------------" + if verboseMilReporting: + print "Empire Capital System: (%d) %s -- threat : %d, military allocation: existing: %d ; new: %d"%(capitalSysID, universe.getSystem(capitalSysID).name , capitalThreat, alreadyAssignedRating[capitalSysID], newAlloc) + print "-----------------" #================================ #--------Empire Occupied Systems ---------- empirePlanetIDs = PlanetUtilsAI.getOwnedPlanetsByEmpire(universe.planetIDs, empireID) empireOccupiedSystemIDs = list( set(PlanetUtilsAI.getSystems(empirePlanetIDs)) - set([capitalSysID] ) ) if "Main" in round: - print "Empire-Occupied Systems: %s"%( [ "| %d %s |"%(eoSysID, universe.getSystem(eoSysID).name) for eoSysID in empireOccupiedSystemIDs ] ) - print "-----------------" + if verboseMilReporting: + print "Empire-Occupied Systems: %s"%( [ "| %d %s |"%(eoSysID, universe.getSystem(eoSysID).name) for eoSysID in empireOccupiedSystemIDs ] ) + print "-----------------" newAlloc=0 if len( empireOccupiedSystemIDs ) > 0: ocSysTotThreat = [ ( oSID, threatBias +safetyFactor*sum( [ foAI.foAIstate.systemStatus.get(oSID, {}).get(thrtKey, 0) for thrtKey in ['totalThreat', 'neighborThreat']] )) @@ -206,18 +209,21 @@ remainingMilRating -= thisAlloc ocSysAlloc += thisAlloc if "Main" in round or thisAlloc >0: - print "Provincial Occupied system %4d ( %10s ) has local threat %8d ; existing military allocation %d and new allocation %8d"%(sid, universe.getSystem(sid).name, thrt, curAlloc, thisAlloc) + if verboseMilReporting: + print "Provincial Occupied system %4d ( %10s ) has local threat %8d ; existing military allocation %d and new allocation %8d"%(sid, universe.getSystem(sid).name, thrt, curAlloc, thisAlloc) if "Main" in round or newAlloc >0: - print "Provincial Empire-Occupied Sytems under total threat: %d -- total mil allocation: existing %d ; new: %d"%(totocSysThreat, totCurAlloc, ocSysAlloc ) - print "-----------------" + if verboseMilReporting: + print "Provincial Empire-Occupied Sytems under total threat: %d -- total mil allocation: existing %d ; new: %d"%(totocSysThreat, totCurAlloc, ocSysAlloc ) + print "-----------------" #================================ #--------Top Targeted Systems ---------- #TODO: do native invasions highest priority otherTargetedSystemIDs = topTargetSystems if "Main" in round: - print "Top Colony and Invasion Targeted Systems : %s"%( [ "| %d %s |"%(sysID, universe.getSystem(sysID).name) for sysID in otherTargetedSystemIDs ] ) - print "-----------------" + if verboseMilReporting: + print "Top Colony and Invasion Targeted Systems : %s"%( [ "| %d %s |"%(sysID, universe.getSystem(sysID).name) for sysID in otherTargetedSystemIDs ] ) + print "-----------------" # for these, calc local threat only, no neighbor threat, but use a multiplier for fleet safety newAlloc=0 if len( otherTargetedSystemIDs ) > 0: @@ -240,19 +246,22 @@ remainingMilRating -= thisAlloc otSysAlloc += thisAlloc if "Main" in round or thisAlloc >0: - print "Targeted system %4d ( %10s ) has local threat %8d ; existing military allocation %d and new allocation %8d"%(sid, universe.getSystem(sid).name, thrt, curAlloc, thisAlloc) + if verboseMilReporting: + print "Targeted system %4d ( %10s ) has local threat %8d ; existing military allocation %d and new allocation %8d"%(sid, universe.getSystem(sid).name, thrt, curAlloc, thisAlloc) if "Main" in round or newAlloc >0: - print "-----------------" - print "Top Colony and Invasion Targeted Systems under total threat: %d -- total mil allocation-- existing: %d ; new: %d"%(tototSysThreat, totCurAlloc, otSysAlloc ) - print "-----------------" + if verboseMilReporting: + print "-----------------" + print "Top Colony and Invasion Targeted Systems under total threat: %d -- total mil allocation-- existing: %d ; new: %d"%(tototSysThreat, totCurAlloc, otSysAlloc ) + print "-----------------" #================================ #--------Targeted Systems ---------- #TODO: do native invasions highest priority otherTargetedSystemIDs = [sysID for sysID in set( PlanetUtilsAI.getSystems(AIstate.opponentPlanetIDs)) if sysID not in topTargetSystems] if "Main" in round: - print "Other Invasion Targeted Systems : %s"%( [ "| %d %s |"%(sysID, universe.getSystem(sysID).name) for sysID in otherTargetedSystemIDs ] ) - print "-----------------" + if verboseMilReporting: + print "Other Invasion Targeted Systems : %s"%( [ "| %d %s |"%(sysID, universe.getSystem(sysID).name) for sysID in otherTargetedSystemIDs ] ) + print "-----------------" # for these, calc local threat only, no neighbor threat, but use a multiplier for fleet safety newAlloc=0 if len( otherTargetedSystemIDs ) > 0: @@ -275,16 +284,19 @@ remainingMilRating -= thisAlloc otSysAlloc += thisAlloc if "Main" in round or thisAlloc >0: - print "Targeted system %4d ( %10s ) has local threat %8d ; existing military allocation %d and new allocation %8d"%(sid, universe.getSystem(sid).name, thrt, curAlloc, thisAlloc) + if verboseMilReporting: + print "Targeted system %4d ( %10s ) has local threat %8d ; existing military allocation %d and new allocation %8d"%(sid, universe.getSystem(sid).name, thrt, curAlloc, thisAlloc) if "Main" in round or newAlloc >0: - print "-----------------" - print "Invasion Targeted Systems under total threat: %d -- total mil allocation-- existing: %d ; new: %d"%(tototSysThreat, totCurAlloc, otSysAlloc ) - print "-----------------" + if verboseMilReporting: + print "-----------------" + print "Invasion Targeted Systems under total threat: %d -- total mil allocation-- existing: %d ; new: %d"%(tototSysThreat, totCurAlloc, otSysAlloc ) + print "-----------------" otherTargetedSystemIDs = [sysID for sysID in list(set(AIstate.colonyTargetedSystemIDs + AIstate.outpostTargetedSystemIDs)) if sysID not in topTargetSystems] if "Main" in round: - print "Other Targeted Systems : %s"%( [ "| %d %s |"%(sysID, universe.getSystem(sysID).name) for sysID in otherTargetedSystemIDs ] ) - print "-----------------" + if verboseMilReporting: + print "Other Targeted Systems : %s"%( [ "| %d %s |"%(sysID, universe.getSystem(sysID).name) for sysID in otherTargetedSystemIDs ] ) + print "-----------------" if len( otherTargetedSystemIDs ) > 0: otSysAlloc = 0 otSysThreat = [ ( oSID, safetyFactor*(threatBias +foAI.foAIstate.systemStatus.get(oSID, {}).get('totalThreat', 0)+0.5*foAI.foAIstate.systemStatus.get(oSID, {}).get('neighborThreat', 0) ) ) for oSID in otherTargetedSystemIDs ] @@ -306,11 +318,13 @@ remainingMilRating -= thisAlloc otSysAlloc += thisAlloc if "Main" in round or thisAlloc >0: - print "Targeted system %4d ( %10s ) has local threat %8d ; existing military allocation %d and new allocation %8d"%(sid, universe.getSystem(sid).name, thrt, curAlloc, thisAlloc) + if verboseMilReporting: + print "Targeted system %4d ( %10s ) has local threat %8d ; existing military allocation %d and new allocation %8d"%(sid, universe.getSystem(sid).name, thrt, curAlloc, thisAlloc) if "Main" in round or newAlloc >0: - print "-----------------" - print "Other Targeted Systems under total threat: %d -- total mil allocation-- existing: %d ; new: %d"%(tototSysThreat, totCurAlloc, otSysAlloc ) - print "-----------------" + if verboseMilReporting: + print "-----------------" + print "Other Targeted Systems under total threat: %d -- total mil allocation-- existing: %d ; new: %d"%(tototSysThreat, totCurAlloc, otSysAlloc ) + print "-----------------" otherTargetedSystemIDs = [] targetableIDs = ColonisationAI.annexableSystemIDs.union( empire.fleetSupplyableSystemIDs ) @@ -324,8 +338,9 @@ break if "Main" in round: - print "Blockade Targeted Systems : %s"%( [ "| %d %s |"%(sysID, universe.getSystem(sysID).name) for sysID in otherTargetedSystemIDs ] ) - print "-----------------" + if verboseMilReporting: + print "Blockade Targeted Systems : %s"%( [ "| %d %s |"%(sysID, universe.getSystem(sysID).name) for sysID in otherTargetedSystemIDs ] ) + print "-----------------" if len( otherTargetedSystemIDs ) > 0: otSysAlloc = 0 otSysThreat = [ ( oSID, threatBias +safetyFactor*(foAI.foAIstate.systemStatus.get(oSID, {}).get('totalThreat', 0)+ 0.5*foAI.foAIstate.systemStatus.get(oSID, {}).get('neighborThreat', 0) ) ) for oSID in otherTargetedSystemIDs ] @@ -347,20 +362,23 @@ remainingMilRating -= thisAlloc otSysAlloc += thisAlloc if "Main" in round or thisAlloc >0: - print "Blockade Targeted system %4d ( %10s ) has local threat %8d ; existing military allocation %d and new allocation %8d"%(sid, universe.getSystem(sid).name, thrt, curAlloc, thisAlloc) + if verboseMilReporting: + print "Blockade Targeted system %4d ( %10s ) has local threat %8d ; existing military allocation %d and new allocation %8d"%(sid, universe.getSystem(sid).name, thrt, curAlloc, thisAlloc) if "Main" in round or newAlloc >0: - print "-----------------" - print "Blockade Targeted Systems under total threat: %d -- total mil allocation-- existing: %d ; new: %d"%(tototSysThreat, totCurAlloc, otSysAlloc ) - print "-----------------" + if verboseMilReporting: + print "-----------------" + print "Blockade Targeted Systems under total threat: %d -- total mil allocation-- existing: %d ; new: %d"%(tototSysThreat, totCurAlloc, otSysAlloc ) + print "-----------------" currentMilSystems = [sid for sid, alloc, takeAny, mm in allocations ] interiorIDs = list( foAI.foAIstate.expInteriorSystemIDs) interiorTargets1 = (targetableIDs.union(interiorIDs)).difference( currentMilSystems ) interiorTargets = [sid for sid in interiorTargets1 if ( (threatBias + foAI.foAIstate.systemStatus.get(sid, {}).get('totalThreat', 0) >0.8*alreadyAssignedRating[sid] ) ) ] if "Main" in round: - print "" - print "Other Empire-Proximal Systems : %s"%( [ "| %d %s |"%(sysID, universe.getSystem(sysID).name) for sysID in interiorTargets1 ] ) - print "-----------------" + if verboseMilReporting: + print "" + print "Other Empire-Proximal Systems : %s"%( [ "| %d %s |"%(sysID, universe.getSystem(sysID).name) for sysID in interiorTargets1 ] ) + print "-----------------" # for these, calc fleet threat only, no neighbor threat, but use a multiplier for fleet safety newAlloc=0 if len(interiorTargets) >0: @@ -383,24 +401,28 @@ remainingMilRating -= thisAlloc otSysAlloc += thisAlloc if "Main" in round or thisAlloc >0: - print "Other interior system %4d ( %10s ) has local threat %8d ; existing military allocation %d and new allocation %8d"%(sid, universe.getSystem(sid).name, thrt, curAlloc, thisAlloc) + if verboseMilReporting: + print "Other interior system %4d ( %10s ) has local threat %8d ; existing military allocation %d and new allocation %8d"%(sid, universe.getSystem(sid).name, thrt, curAlloc, thisAlloc) if "Main" in round or newAlloc >0: + if verboseMilReporting: + print "-----------------" + print "Other Interior Systems under total threat: %d -- total mil allocation-- existing: %d ; new: %d"%(tototSysThreat, totCurAlloc, otSysAlloc ) + print "-----------------" + elif "Main" in round: + if verboseMilReporting: print "-----------------" - print "Other Interior Systems under total threat: %d -- total mil allocation-- existing: %d ; new: %d"%(tototSysThreat, totCurAlloc, otSysAlloc ) + print "No Other Interior Systems with fleet threat " print "-----------------" - elif "Main" in round: - print "-----------------" - print "No Other Interior Systems with fleet threat " - print "-----------------" monsterDens=[] #exploTargetIDs, _ = ExplorationAI.getCurrentExplorationInfo(verbose=False) exploTargetIDs=[] if "Main" in round: - print "" - print "Exploration-targeted Systems: %s"%( [ "| %d %s |"%(sysID, universe.getSystem(sysID).name) for sysID in exploTargetIDs ] ) - print "-----------------" + if verboseMilReporting: + print "" + print "Exploration-targeted Systems: %s"%( [ "| %d %s |"%(sysID, universe.getSystem(sysID).name) for sysID in exploTargetIDs ] ) + print "-----------------" # for these, calc fleet threat only, no neighbor threat, but use a multiplier for fleet safety newAlloc=0 if len(exploTargetIDs) > 0: @@ -427,11 +449,13 @@ remainingMilRating -= thisAlloc otSysAlloc += thisAlloc if "Main" in round or thisAlloc >0: - print "Exploration-targeted %4d ( %10s ) has local threat %8d ; existing military allocation %d and new allocation %8d"%(sid, universe.getSystem(sid).name, thrt, curAlloc, thisAlloc) + if verboseMilReporting: + print "Exploration-targeted %4d ( %10s ) has local threat %8d ; existing military allocation %d and new allocation %8d"%(sid, universe.getSystem(sid).name, thrt, curAlloc, thisAlloc) if "Main" in round or newAlloc >0: - print "-----------------" - print "Exploration-targeted s under total threat: %d -- total mil allocation-- existing: %d ; new: %d"%(tototSysThreat, totCurAlloc, otSysAlloc ) - print "-----------------" + if verboseMilReporting: + print "-----------------" + print "Exploration-targeted s under total threat: %d -- total mil allocation-- existing: %d ; new: %d"%(tototSysThreat, totCurAlloc, otSysAlloc ) + print "-----------------" visibleSystemIDs = foAI.foAIstate.visInteriorSystemIDs.keys() + foAI.foAIstate. visBorderSystemIDs.keys() accessibleSystemIDs = [sysID for sysID in visibleSystemIDs if universe.systemsConnected(sysID, homeSystemID, empireID) ] @@ -439,9 +463,10 @@ borderTargets1 = [sid for sid in accessibleSystemIDs if ( ( sid not in currentMilSystems )) ] borderTargets = [sid for sid in borderTargets1 if ( ( threatBias +foAI.foAIstate.systemStatus.get(sid, {}).get('fleetThreat', 0) + foAI.foAIstate.systemStatus.get(sid, {}).get('planetThreat', 0) > 0.8*alreadyAssignedRating[sid] )) ] if "Main" in round: - print "" - print "Empire-Accessible Systems not yet allocated military: %s"%( [ "| %d %s |"%(sysID, universe.getSystem(sysID) and universe.getSystem(sysID).name) for sysID in borderTargets1 ] ) - print "-----------------" + if verboseMilReporting: + print "" + print "Empire-Accessible Systems not yet allocated military: %s"%( [ "| %d %s |"%(sysID, universe.getSystem(sysID) and universe.getSystem(sysID).name) for sysID in borderTargets1 ] ) + print "-----------------" # for these, calc fleet threat only, no neighbor threat, but use a multiplier for fleet safety newAlloc=0 if len(borderTargets) > 0: @@ -464,21 +489,25 @@ remainingMilRating -= thisAlloc otSysAlloc += thisAlloc if "Main" in round or thisAlloc >0: - print "Other Empire-Accessible system %4d ( %10s ) has local biased threat %8d ; existing military allocation %d and new allocation %8d"%(sid, universe.getSystem(sid).name, thrt, curAlloc, thisAlloc) + if verboseMilReporting: + print "Other Empire-Accessible system %4d ( %10s ) has local biased threat %8d ; existing military allocation %d and new allocation %8d"%(sid, universe.getSystem(sid).name, thrt, curAlloc, thisAlloc) if "Main" in round or newAlloc >0: + if verboseMilReporting: + print "-----------------" + print "Other Empire-Accessible Systems under total biased threat: %d -- total mil allocation-- existing: %d ; new: %d"%(tototSysThreat, totCurAlloc, otSysAlloc ) + print "-----------------" + elif "Main" in round: + if verboseMilReporting: print "-----------------" - print "Other Empire-Accessible Systems under total biased threat: %d -- total mil allocation-- existing: %d ; new: %d"%(tototSysThreat, totCurAlloc, otSysAlloc ) + print "No Other Empire-Accessible Systems with biased local threat " print "-----------------" - elif "Main" in round: - print "-----------------" - print "No Other Empire-Accessible Systems with biased local threat " - print "-----------------" #monster den treatment probably unnecessary now if "Main" in round: - print "" - print "Big-Monster Dens: %s"%( [ "| %d %s |"%(sysID, universe.getSystem(sysID).name) for sysID in monsterDens ] ) - print "-----------------" + if verboseMilReporting: + print "" + print "Big-Monster Dens: %s"%( [ "| %d %s |"%(sysID, universe.getSystem(sysID).name) for sysID in monsterDens ] ) + print "-----------------" # for these, calc fleet threat only, no neighbor threat, but use a multiplier for fleet safety newAlloc=0 if len(monsterDens) > 0: @@ -496,9 +525,11 @@ remainingMilRating -= thisAlloc otSysAlloc += thisAlloc if "Main" in round or thisAlloc >0: - print "Monster Den %4d ( %10s ) has local threat %8d ; existing military allocation %d and new allocation %8d"%(sid, universe.getSystem(sid).name, thrt, curAlloc, thisAlloc) + if verboseMilReporting: + print "Monster Den %4d ( %10s ) has local threat %8d ; existing military allocation %d and new allocation %8d"%(sid, universe.getSystem(sid).name, thrt, curAlloc, thisAlloc) if "Main" in round or newAlloc >0: - print "-----------------" + if verboseMilReporting: + print "-----------------" if remainingMilRating <=6: @@ -525,7 +556,8 @@ if "Main" in round: MilitaryAllocations = newAllocations minMilAllocations = dict( [ (sid, alloc) for sid, alloc, takeAny, mm in allocations ] ) - print "------------------------------\nFinal %s Round Military Allocations: %s \n-----------------------"%(round, dict( [ (sid, alloc) for sid, alloc, minalloc, takeAny in newAllocations ] ) ) + if verboseMilReporting or "Main" in round: + print "------------------------------\nFinal %s Round Military Allocations: %s \n-----------------------"%(round, dict( [ (sid, alloc) for sid, alloc, minalloc, takeAny in newAllocations ] ) ) # export military systems for other AI modules if "Main" in round: @@ -646,7 +678,8 @@ if theseFleets == []: if foundFleets==[] or not ( FleetUtilsAI.statsMeetReqs( foundStats, {'rating':minalloc}) or takeAny): if doingMain: - print "NO available/suitable military allocation for system %d ( %s ) -- requested allocation %8d, found available rating %8d in fleets %s"%(sysID, universe.getSystem(sysID).name, minalloc, foundStats.get('rating', 0), foundFleets) + if verboseMilReporting: + print "NO available/suitable military allocation for system %d ( %s ) -- requested allocation %8d, found available rating %8d in fleets %s"%(sysID, universe.getSystem(sysID).name, minalloc, foundStats.get('rating', 0), foundFleets) availMilFleetIDs.update(foundFleets) continue else: @@ -654,12 +687,12 @@ #rating = sum( map(lambda x: foAI.foAIstate.rateFleet(x), foundFleets ) ) ratings = map(lambda x: foAI.foAIstate.rateFleet(x), foundFleets ) rating = sum([fr.get('attack', 0) for fr in ratings]) * sum([fr.get('health', 0) for fr in ratings]) - if doingMain: + if doingMain and verboseMilReporting: if rating < minMilAllocations.get(sysID, 0): print "PARTIAL military allocation for system %d ( %s ) -- requested allocation %8d -- got %8d with fleets %s"%(sysID, universe.getSystem(sysID).name, minalloc, rating, theseFleets) else: print "FULL MIN military allocation for system %d ( %s ) -- requested allocation %8d -- got %8d with fleets %s "%(sysID, universe.getSystem(sysID).name, minMilAllocations.get(sysID, 0) , rating, theseFleets) - elif doingMain: + elif doingMain and verboseMilReporting: print "FULL+ military allocation for system %d ( %s ) -- requested allocation %8d, got %8d with fleets %s"%(sysID, universe.getSystem(sysID).name, alloc, foundStats.get('rating', 0), theseFleets) aiTarget = AITarget.AITarget(AITargetType.TARGET_SYSTEM, sysID) for fleetID in theseFleets: Modified: trunk/FreeOrion/default/AI/ProductionAI.py =================================================================== --- trunk/FreeOrion/default/AI/ProductionAI.py 2013-07-04 01:05:53 UTC (rev 6222) +++ trunk/FreeOrion/default/AI/ProductionAI.py 2013-07-04 20:28:22 UTC (rev 6223) @@ -1042,28 +1042,55 @@ print "Requeueing %s to front of build queue, with result %d"%(bldName, res) break #only initiate max of one new build per turn + colonyShipMap={} + for fid in FleetUtilsAI.getEmpireFleetIDsByRole( EnumsAI.AIFleetMissionType.FLEET_MISSION_COLONISATION): + fleet = universe.getFleet(fid) + if not fleet: continue + for shipID in fleet.shipIDs: + thisShip=universe.getShip(shipID) + if thisShip and (foAI.foAIstate.getShipRole(thisShip.design.id) ==EnumsAI.AIShipRoleType.SHIP_ROLE_CIVILIAN_COLONISATION): + colonyShipMap.setdefault( thisShip.speciesName, []).append(1) + bldName = "BLD_CONC_CAMP" + verboseCamp = False bldType = fo.getBuildingType(bldName) for pid in AIstate.popCtrIDs: planet=universe.getPlanet(pid) if not planet: continue + canBuildCamp = bldType.canBeProduced(empire.empireID, pid) tPop = planet.currentMeterValue(fo.meterType.targetPopulation) tInd=planet.currentMeterValue(fo.meterType.targetIndustry) cInd=planet.currentMeterValue(fo.meterType.industry) cPop = planet.currentMeterValue(fo.meterType.population) - if (cPop <= 32) or (cPop < 0.8*tPop) or ( (planet.speciesName not in ColonisationAI.empireColonizers) and cPop < 50 ): #check even if not aggressive, etc, just in case acquired planet with a ConcCamp on it + popDisqualified = (cPop <= 32) or (cPop < 0.8*tPop) + checkedCamp=False + builtCamp=False + thisSpec = planet.speciesName + safetyMarginMet = ( (thisSpec in ColonisationAI.empireColonizers and ( len(ColonisationAI.empireSpecies.get(thisSpec, [])+colonyShipMap.get(thisSpec, []))>=2 )) or (cPop >= 50 )) + if popDisqualified or not safetyMarginMet : #check even if not aggressive, etc, just in case acquired planet with a ConcCamp on it + if canBuildCamp: + if popDisqualified: + if verboseCamp: + print "Conc Camp disqualified at %s due to low pop: current %.1f target: %.1f"%(planet.name, cPop, tPop) + else: + if verboseCamp: + print "Conc Camp disqualified at %s due to safety margin; species %s, colonizing planets %s, with %d colony ships"%(planet.name, planet.speciesName, ColonisationAI.empireSpecies.get(planet.speciesName, []), len(colonyShipMap.get(planet.speciesName, []))) for bldg in planet.buildingIDs: if universe.getObject(bldg).buildingTypeName == bldName: res=fo.issueScrapOrder( bldg) print "Tried scrapping %s at planet %s, got result %d"%(bldName, planet.name, res) - elif foAI.foAIstate.aggression>fo.aggression.typical and empire.buildingTypeAvailable(bldName) and (tPop >= 36) : + elif foAI.foAIstate.aggression>fo.aggression.typical and canBuildCamp and (tPop >= 36): + checkedCamp=True if (planet.focus== EnumsAI.AIFocusType.FOCUS_GROWTH) or ("COMPUTRONIUM_SPECIAL" in planet.specials): #continue pass # now that focus setting takes these into account, probably works ok to have conc camp queuedBldLocs = [element.locationID for element in productionQueue if (element.name==bldName) ] - if (cPop >=0.95*tPop) and( (planet.speciesName in ColonisationAI.empireColonizers) or cPop >= 50 ):# - if pid not in queuedBldLocs and bldType.canBeProduced(empire.empireID, pid):#TODO: verify that canBeProduced() checks for prexistence of a barring building + if (cPop <0.95*tPop):# + if verboseCamp: + print "Conc Camp disqualified at %s due to pop: current %.1f target: %.1f"%(planet.name, cPop, tPop) + else: + if pid not in queuedBldLocs: if planet.focus in [ EnumsAI.AIFocusType.FOCUS_INDUSTRY ]: if cInd >= tInd+cPop: continue @@ -1077,11 +1104,14 @@ universe.updateMeterEstimates([pid]) continue res=fo.issueEnqueueBuildingProductionOrder(bldName, pid) + builtCamp = res print "Enqueueing %s at planet %d (%s) , with result %d"%(bldName, pid, universe.getPlanet(pid).name, res) if res: queuedBldLocs.append(pid) res=fo.issueRequeueProductionOrder(productionQueue.size -1, 0) # move to front - + if verboseCamp: + print "conc camp status at %s : checkedCamp: %s, builtCamp: %s"%( planet.name, canBuildCamp, builtCamp) + bldName = "BLD_SCANNING_FACILITY" if empire.buildingTypeAvailable(bldName): bldType = fo.getBuildingType(bldName) @@ -1313,7 +1343,7 @@ del localPriorities[priority] #must be missing a shipyard -- TODO build a shipyard if necessary continue bestShips[priority] = [bestShip, bestDesign, buildChoices ] - print "bestShips[%s] = %s \t locs from %s"%( EnumsAI.AIPriorityNames[priority], bestShips[priority] , pSet) + print "bestShips[%s] = %s \t locs from %s"%( EnumsAI.AIPriorityNames[priority], bestDesign.name(False) , pSet) if len(localPriorities)==0: print "Alert!! need shipyards in systemSet ", PlanetUtilsAI.sysNameIDs(set(PlanetUtilsAI.getSystems( sorted(pSet)))) Modified: trunk/FreeOrion/default/AI/ResourcesAI.py =================================================================== --- trunk/FreeOrion/default/AI/ResourcesAI.py 2013-07-04 01:05:53 UTC (rev 6222) +++ trunk/FreeOrion/default/AI/ResourcesAI.py 2013-07-04 20:28:22 UTC (rev 6223) @@ -27,6 +27,7 @@ GFocus = AIFocusType.FOCUS_GROWTH useGrowth = True +limitAssessments = False lastFociCheck=[0] @@ -146,7 +147,7 @@ empireID = empire.empireID currentTurn = fo.currentTurn() freq = min(3, ( max(5, currentTurn-120) )/4.0)**(1.0/3) - if ( abs(currentTurn - lastFociCheck[0] ) <1.5*freq) and ( random() < 1.0/freq ) : + if limitAssessments and ( abs(currentTurn - lastFociCheck[0] ) <1.5*freq) and ( random() < 1.0/freq ) : timer = 6*[time()] else: lastFociCheck[0]=currentTurn @@ -211,6 +212,7 @@ if result == 1: universe.updateMeterEstimates(empirePlanetIDs) if curFocus == RFocus or result==1: + print "%s focus of planet %s (%d) (with Computronium Moon) at Research Focus"%( ["set", "left" ][ curFocus == RFocus ] , planetMap[pid].name, pid) if pid in empirePlanetIDs: del empirePlanetIDs[ empirePlanetIDs.index( pid ) ] elif ( ([bld.buildingTypeName for bld in map( universe.getObject, planet.buildingIDs) if bld.buildingTypeName in @@ -232,6 +234,7 @@ print ("Error: Failed setting %s for Concentration Camp planet %s (%d) with species %s and current focus %s, but new planet copy shows %s"% ( newFoci[pid], planetMap[pid].name, pid, planetMap[pid].speciesName, planetMap[pid].focus, newplanet.focus )) if curFocus == IFocus or result==1: + print "%s focus of planet %s (%d) (with Concentration Camps/Remnants) at Industry Focus"%( ["set", "left" ][ curFocus == IFocus ] , planetMap[pid].name, pid) if pid in empirePlanetIDs: del empirePlanetIDs[ empirePlanetIDs.index( pid ) ] @@ -260,7 +263,7 @@ CI, CR = currentOutput[pid][ IFocus], currentOutput[pid][ RFocus] #if AI is aggressive+, and this planet in range where temporary Research focus can get an additional RP at cost of 1 PP, and still need some RP, then do it if True and (foAI.foAIstate.aggression >= fo.aggression.aggressive): - if (CR<=RR-1) and ( (CR-IR) >= (II-CI) ) and (priorityRatio > 0.8* ( (CR+1)/ max(0.001, CI -1))): + if ( CI > II ) or ( (CR<=RR-1) and ( (CR-IR) >= (II-CI) ) and (priorityRatio > 0.8* ( (CR+1)/ max(0.001, CI -1)))): curTargetPP += CI -1 # curTargetRP += CR+1 newFoci[pid] = RFocus |