AI Debugging in UI interface.

Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.

Moderator: Committer

Message
Author
User avatar
Dilvish
AI Lead and Programmer Emeritus
Posts: 4768
Joined: Sat Sep 22, 2012 6:25 pm

Re: AI Debugging in UI interface.

#16 Post by Dilvish »

following up on my previous post, I exposed INVALID_GAME_TURN as fo.INVALID_GAME_TURN (but see note below re sitreps)
Cjkjvfnby wrote:And other issue with hullType.slots
ok, this is fixed now as well. As an example for this and NumSitReps, the python code

Code: Select all

    print "Number of SitReps this turn: ", empire.numSitReps(fo.currentTurn())
    print "Total number of SitReps so far: ", empire.numSitReps(fo.INVALID_GAME_TURN)
    testHull = fo.getHullType("SH_STANDARD")
    slot_types = fo.shipSlotType
    print "Test hull %s; total slots: %d, slots by type: %s" % (testHull.name, testHull.numSlots, [testHull.numSlotsOfSlotType(s_type) for s_type in [slot_types.external, slot_types.internal, slot_types.core]])
    slot_vec = testHull.slots
    print "TestHull slots vector: %s, contains %s" % ( slot_vec, [slot_type for slot_type in slot_vec])
yields

Code: Select all

2015-01-22 17:37:37,598 DEBUG AI : Number of SitReps this turn:  2
2015-01-22 17:37:37,598 DEBUG AI : Total number of SitReps so far:  24
2015-01-22 17:37:37,598 DEBUG AI : Test hull SH_STANDARD; total slots: 4, slots by type: [3, 1, 0]
2015-01-22 17:37:37,598 DEBUG AI : TestHull slots vector: <freeOrionAIInterface.ShipSlotVec object at 0x7f05e2745750>, contains
[freeOrionAIInterface.shipSlotType.external, freeOrionAIInterface.shipSlotType.external, freeOrionAIInterface.shipSlotType.external,
freeOrionAIInterface.shipSlotType.internal]
Regarding the sitreps, apparently there are a large number of sitreps generated at turn -1 or something, which are normally surpressed-- the above was for turn 2, turn 1 had reported zero current sitreps but 22 total sitreps.
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13603
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: AI Debugging in UI interface.

#17 Post by Geoff the Medio »

Dilvish wrote:...apparently there are a large number of sitreps generated at turn -1 or something, which are normally surpressed...
Those are all the before-the-first-turn unlocks. If you open the sitrep window on turn 1, they're all shown, though if you go to another turn, you can't go back.

User avatar
Cjkjvfnby
AI Contributor
Posts: 539
Joined: Tue Jun 24, 2014 9:55 pm

Re: AI Debugging in UI interface.

#18 Post by Cjkjvfnby »

Dilvish wrote:

Code: Select all

2015-01-22 17:37:37,598 DEBUG AI : Number of SitReps this turn:  2
Thank you.

What SitReps means? Is it just a number of line that was added to SitRep window? What for it can be used?

====

Did you meet such AI bug? If not I will make separate report.

Code: Select all

element Manticore-2b-7 will never be completed as stands and location 118 no longer owned; could consider deleting from queue 
...
Traceback (most recent call last):
  File "F:\projects\freeorion\FreeOrion\default\AI\FreeOrionAI.py", line 222, in generateOrders
    action()
  File "F:\projects\freeorion\FreeOrion\default\AI\test_stuff\summary.py", line 40, in wrapper
    res = function(*args, **kwargs)
  File "F:\projects\freeorion\FreeOrion\default\AI\PriorityAI.py", line 41, in calculate_priorities
    InvasionAI.get_invasion_fleets() # sets AIstate.invasionFleetIDs, AIstate.opponentPlanetIDs, and AIstate.invasionTargetedPlanetIDs
  File "F:\projects\freeorion\FreeOrion\default\AI\InvasionAI.py", line 165, in get_invasion_fleets
    evaluatedPlanets = assign_invasion_values(evaluatedPlanetIDs, EnumsAI.AIFleetMissionType.FLEET_MISSION_INVASION, fleet_supplyable_planet_ids, empire)
  File "F:\projects\freeorion\FreeOrion\default\AI\InvasionAI.py", line 245, in assign_invasion_values
    industry_ratio = planet_industries[planetID] / max(planet_industries.values())
KeyError: 118

I have trouble with bombarding planet. Bombard button does not appear on planet then I select fleet. It appears only then I selecet ship with bombard or all ships in fleet.
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

User avatar
Dilvish
AI Lead and Programmer Emeritus
Posts: 4768
Joined: Sat Sep 22, 2012 6:25 pm

Re: AI Debugging in UI interface.

#19 Post by Dilvish »

Cjkjvfnby wrote:
Dilvish wrote:

Code: Select all

2015-01-22 17:37:37,598 DEBUG AI : Number of SitReps this turn:  2
What SitReps means? Is it just a number of line that was added to SitRep window? What for it can be used?
SitRep is short for "Situation Report". For the AI to process SitReps to get more detailed information about combat, and also to be able to determine the presence of a Gateway to the Void, and other things, is one of the AI TODO items.
Did you meet such AI bug? If not I will make separate report.
No, I haven't ever seen that before. Looking at the code briefly right now, I don't even see how it is possible that the error could even arise (since PlanetID should also be in system.planetIDs). Could you please try to determine the cause of the error?
I have trouble with bombarding planet. Bombard button does not appear on planet then I select fleet. It appears only then I selecet ship with bombard or all ships in fleet.
That behavior makes sense to me, though it could be made easier. It used to be the same for colonizing and invasions until we made special helpers to help streamline those processes. A similar helper could be made for bombardment, but will probably be low priority until bombardment becomes a more significant part of the game or until it simply catches the fancy of one of the C++ devs.
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

User avatar
Dilvish
AI Lead and Programmer Emeritus
Posts: 4768
Joined: Sat Sep 22, 2012 6:25 pm

Re: AI Debugging in UI interface.

#20 Post by Dilvish »

Cjkjvfnby wrote:Any way set default message window large by default? My debug prints wont fit. :(

Code: Select all

r7871 | dilvish-fo | 2015-01-26 01:50:38 -0800 (Mon, 26 Jan 2015) | 2 lines
made player chat window width and height adjustable via command line options   --UI.chat-panel-width and --UI.chat-panel-height
The default values were, and remain, width 345 and height 160. You can also just edit config.xml instead of the using the command line, and if you start a new single player game after having provided these on the command line then they will get saved to config.xml
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13603
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: AI Debugging in UI interface.

#21 Post by Geoff the Medio »

Similar options can / should be added to store the left, top, width, and height of all the UI windows. If allowing changing the default left and top, though, it's necessary to have fallback / validation tests to ensure they are placed within the available window area.

User avatar
Dilvish
AI Lead and Programmer Emeritus
Posts: 4768
Joined: Sat Sep 22, 2012 6:25 pm

Re: AI Debugging in UI interface.

#22 Post by Dilvish »

Cjkjvfnby wrote:Did you meet such AI bug? If not I will make separate report.
Coincidentally, someone else just now submitted a savegame where they had encountered the same error-- turns out it was from insufficient care about the possibility of planets having been destroyed. I put in a quick fix for this particular problem, but the same issue could easily exist in other parts of the code-- I hadn't really been keeping planetary destruction in mind, I think. If you could take a look through for likely spots in the code to check for similar trouble that would be great.
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

User avatar
Cjkjvfnby
AI Contributor
Posts: 539
Joined: Tue Jun 24, 2014 9:55 pm

Re: AI Debugging in UI interface.

#23 Post by Cjkjvfnby »

Dilvish wrote:
Cjkjvfnby wrote:Did you meet such AI bug? If not I will make separate report.
Coincidentally, someone else just now submitted a savegame where they had encountered the same error-- turns out it was from insufficient care about the possibility of planets having been destroyed. I put in a quick fix for this particular problem, but the same issue could easily exist in other parts of the code-- I hadn't really been keeping planetary destruction in mind, I think. If you could take a look through for likely spots in the code to check for similar trouble that would be great.
I will check it.

How can planet be destroyed?
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

User avatar
Dilvish
AI Lead and Programmer Emeritus
Posts: 4768
Joined: Sat Sep 22, 2012 6:25 pm

Re: AI Debugging in UI interface.

#24 Post by Dilvish »

Cjkjvfnby wrote:How can planet be destroyed?
Nova bombs will destroy all planets in a system; in the submitted savegame it had been from ones carried by Cosmic Dragons, a late stage Experimentor monster.

The AI wouldn't necessarily have observed the system while its planets were being destroyed, so just simply checking for known destroyed objects isn't the right solution. In this case I wound up simply checking if the subject planet was still in its systems list of planets, because it was that assumption that led to the key error. Having the AI actually infer that the planet has been destroyed so it doesn't waste more time trying to investigate/target it would be helpful but is a relatively minor issue.
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

User avatar
Cjkjvfnby
AI Contributor
Posts: 539
Joined: Tue Jun 24, 2014 9:55 pm

Re: AI Debugging in UI interface.

#25 Post by Cjkjvfnby »

Dilvish wrote:
Cjkjvfnby wrote:How can planet be destroyed?
Nova bombs will destroy all planets in a system; in the submitted savegame it had been from ones carried by Cosmic Dragons, a late stage Experimentor monster.

The AI wouldn't necessarily have observed the system while its planets were being destroyed, so just simply checking for known destroyed objects isn't the right solution. In this case I wound up simply checking if the subject planet was still in its systems list of planets, because it was that assumption that led to the key error. Having the AI actually infer that the planet has been destroyed so it doesn't waste more time trying to investigate/target it would be helpful but is a relatively minor issue.
If you revert you commit it would be great.
This is not final fix but consider it as cleanup that fixies this issue.

Code: Select all

Index: default/AI/PlanetUtilsAI.py
<+>UTF-8
===================================================================
--- default/AI/PlanetUtilsAI.py	(date 1422305461000)
+++ default/AI/PlanetUtilsAI.py	(revision )
@@ -101,7 +101,6 @@
     universe = fo.getUniverse()
     planet_ids = set()
     for system_id in system_ids:
-        planet_ids.update(foAI.foAIstate.systemStatus.get(system_id, {}).get('planets', {}))  # check if we need this
         system = universe.getSystem(system_id)
         if system is not None:
             planet_ids.update(system.planetIDs)

Here is fix for systemStatus, it works for me, but I will track it in code to check if it can break in other places.

Code: Select all

Index: default/AI/AIstate.py
<+>UTF-8
===================================================================
--- default/AI/AIstate.py	(date 1422305461000)
+++ default/AI/AIstate.py	(revision )
@@ -135,6 +135,7 @@
 
     def refresh(self):
         """turn start AIstate cleanup/refresh"""
+        universe = fo.getUniverse()
         #checks exploration border & clears roles/missions of missing fleets & updates fleet locs & threats
         fleetsLostBySystem.clear()
         fleetsLostByID.clear()
@@ -143,6 +144,17 @@
         if exploration_center == -1:  # a bad state probably from an old savegame, or else empire has lost (or almost has)
             exploration_center = self.origHomeSystemID
 
+        # check if planets in cache is still present. Remove destroyed.
+        for system_id, info in sorted(self.systemStatus.items()):
+            planet_dict = info.get('planets', {})
+            cache_planet_set = set(planet_dict)
+            system_planet_set = set(universe.getSystem(system_id).planetIDs)
+            diff = cache_planet_set - system_planet_set
+            if diff:
+                print "Removing destroyed planets from systemStatus for system %s: planets to be removed: %s" % (system_id, sorted(diff))
+                for key in diff:
+                    del planet_dict[key]
+
         ExplorationAI.graphFlags.clear()
         if fo.currentTurn() < 50:
             print "-------------------------------------------------"
@@ -157,7 +169,6 @@
             ExplorationAI.follow_vis_system_connections(sysID, exploration_center)
         newlyExplored = ExplorationAI.update_explored_systems()
         nametags = []
-        universe = fo.getUniverse()
         for sysID in newlyExplored:
             newsys = universe.getSystem(sysID)
             nametags.append("ID:%4d -- %20s" % (sysID, (newsys and newsys.name) or"name unknown"))  # an explored system *should* always be able to be gotten


Upd:

Here is my save. You need purple AI, system_id: 118. (AI players change theirs order after reload.)

zipped save in xml format
https://drive.google.com/file/d/0B12sy1 ... sp=sharing
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

User avatar
Cjkjvfnby
AI Contributor
Posts: 539
Joined: Tue Jun 24, 2014 9:55 pm

Re: AI Debugging in UI interface.

#26 Post by Cjkjvfnby »

Revert fix in invasion (make it less complicated)
Remove string that cause issue in PlanetUtilsAI
Add code to cleanup cache on turn start, to avoid troubles in other places.
Attachments

[The extension patch has been deactivated and can no longer be displayed.]

If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

User avatar
Cjkjvfnby
AI Contributor
Posts: 539
Joined: Tue Jun 24, 2014 9:55 pm

Re: AI Debugging in UI interface.

#27 Post by Cjkjvfnby »

Current logger info consume a lot of space in log

Code: Select all

2015-02-08 20:41:19,834 DEBUG AI
Maybe make it shorted shorter:

Code: Select all

// current logger
InitLogger(AICLIENT_LOG_FILENAME, "%d %p AI : %m%n");
// with out date and AI
InitLogger(AICLIENT_LOG_FILENAME, "%d{%H:%M:%S,%l} %p : %m%n"); 
// with milliseconds since this layout was created.
InitLogger(AICLIENT_LOG_FILENAME, "%r %p : %m%n"); 
Or may be move this param to settings.
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13603
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: AI Debugging in UI interface.

#28 Post by Geoff the Medio »

Cjkjvfnby wrote:Current logger info consume a lot of space in log

Code: Select all

2015-02-08 20:41:19,834 DEBUG AI
The date and time info is quite useful to have in the log. The "DEBUG" or "ERROR" lines are also quite useful, to search for a few error lines in a long log file with mostly debut info. Getting rid of "AI", "HUMAN" or "SERVER" would be OK, I think, if the 2-6 characters it saves is worth worrying about.

User avatar
Cjkjvfnby
AI Contributor
Posts: 539
Joined: Tue Jun 24, 2014 9:55 pm

Re: AI Debugging in UI interface.

#29 Post by Cjkjvfnby »

Geoff the Medio wrote:
Cjkjvfnby wrote:Current logger info consume a lot of space in log

Code: Select all

2015-02-08 20:41:19,834 DEBUG AI
The date and time info is quite useful to have in the log. The "DEBUG" or "ERROR" lines are also quite useful, to search for a few error lines in a long log file with mostly debut info. Getting rid of "AI", "HUMAN" or "SERVER" would be OK, I think, if the 2-6 characters it saves is worth worrying about.
I don't sure if we need date.
Time is ok. May be try to replaced it to %r (milliseconds since this layout was created.)
"DEBUG" or "ERROR" is useful.
AI save two items.
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13603
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: AI Debugging in UI interface.

#30 Post by Geoff the Medio »

Cjkjvfnby wrote:I don't sure if we need date.
Date is quite useful; often people have issues and post logs, but it's not clear if the log (particularly for AIs) is from the same execution as the server / client logs, or form the last time (several days ago) when the AIs started up correctly.
May be try to replaced it to %r (milliseconds since this layout was created.)
Actual time is much more useful when checking a lot to see if it's from the most recent time the program was run, or some other time, and for checking how long ago (relative the currently displayed system time) the log line was generated. I don't want to have to check the latest time the file was modified or when it was created and do a bunch of time math to work all that out when I view a log file.

Post Reply