AI Production Queue

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

Moderator: Committer

Post Reply
Message
Author
Gray Area
Space Squid
Posts: 89
Joined: Sat Sep 24, 2011 4:39 pm

AI Production Queue

#1 Post by Gray Area »

I’ve seen a number of odd program behaviors while attempting to improve the ProductionAI module.

It appears that the main, or C++ program, is augmenting/overriding the Python ProductionAI module and is adding ships to the AI Production Queue under certain conditions.

The following are typical of messages that constantly appear in the AI log files:

2012-01-07 01:15:45,791 DEBUG AI : adding new ship to production queue: Troop Ship
2012-01-07 01:15:45,791 DEBUG AI : ProductionQueue::Update: Simulating future turns of production queue
2012-01-07 01:15:45,801 DEBUG AI : ProductionQueue::Update time: 10
2012-01-07 01:15:45,801 DEBUG AI :
2012-01-07 01:15:45,801 DEBUG AI : adding new ship to production queue: Mark I
2012-01-07 01:15:45,801 DEBUG AI : ProductionQueue::Update: Simulating future turns of production queue
2012-01-07 01:15:45,801 DEBUG AI : ProductionQueue::Update time: 0
2012-01-07 01:15:45,801 DEBUG AI :
2012-01-07 01:15:45,811 DEBUG AI : ========= Production Update for empire: 4 ========
2012-01-07 01:15:45,811 DEBUG AI : ProductionQueue::Update: Simulating future turns of production queue
2012-01-07 01:15:45,811 DEBUG AI : ProductionQueue::Update time: 0
2012-01-07 01:15:45,821 DEBUG AI : ========= Production Update for empire: 4 ========
2012-01-07 01:15:45,821 DEBUG AI : ProductionQueue::Update: Simulating future turns of production queue
2012-01-07 01:15:45,821 DEBUG AI : ProductionQueue::Update time: 0

Why is the program “Simulating future turns of production queue”?

Is it, in fact, adding ships to the AI Production Queue based upon the logic of a simulation contained within the main program code?

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

Re: AI Production Queue

#2 Post by Geoff the Medio »

Gray Area wrote:Why is the program “Simulating future turns of production queue”?
This is done so that estimates of the time it will take to complete the projects (or research) on the queue(s) can be calculated. Those times are found by repeatedly adding the allocated PP to each project until one or more are complete, then removing the completed projects, updating the allocations, and continuing the simulations until all projects are done or a predetermined number of turns (about 500 I think) are simulated.

There may or may not be any use for this in AI clients, but on the human client, it's used to determine the turns to complete projects estimates shown on the research and production queues.

Gray Area
Space Squid
Posts: 89
Joined: Sat Sep 24, 2011 4:39 pm

Re: AI Production Queue

#3 Post by Gray Area »

Geoff the Medio wrote:
Gray Area wrote:Why is the program “Simulating future turns of production queue”?
This is done ...
Thanks for the explanation. That information is good to know.

Actually, the ‘turnsLeft’ property may yet prove to be useful to the AI. I’m glad it’s available.

I took another hard, and very careful, look at the ProductionAI module’s code and finally saw what is causing one (1) anomaly. :oops:

Now, if I can only figure out the cause(s) of the other ones …

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

Re: AI Production Queue

#4 Post by Geoff the Medio »

I noticed in the ProductionAI code, you're comparing the names of shipdesigns to human-readable / english text:

Code: Select all

            explorationShipName = "Scout"
            colonyShipName = "Colony Ship"
            outpostShipName = "Outpost Ship"
            troopShipName = "Troop Ship"
            if topPriority == 6 and shipDesign.name(True) == explorationShipName:
                # exploration ship
                print ""
                print "adding new ship to production queue: " + shipDesign.name(True)
This is a bad idea; passing True to the shipDesign name() function tells it to look up the ship's name in the stringtable, and to return the translated version of the name. This means that in languages other than english, the name won't match what you're expecting. Better would be to use the stringtable entry keys, like SD_TROOP_SHIP, SD_SCOUT, SD_COLONY_SHIP, or SD_OUTPOST_SHIP, which won't depend on the user-selected language, and pass false to name(), so that it returns the stringtable entry key without looking it up first.

The only exception is player-created ship designs, which may have only the name they specify in whatever language they're playing in, but this shouldn't be an issue for AI ship designs from the premade ship designs list.

Gray Area
Space Squid
Posts: 89
Joined: Sat Sep 24, 2011 4:39 pm

Re: AI Production Queue

#5 Post by Gray Area »

Geoff the Medio wrote:I noticed in the ProductionAI code, you're comparing the names of shipdesigns to human-readable / english text:
That problem should be easy to correct. I’ll get back to you with an updated module in a day, or so.

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

Re: AI Production Queue

#6 Post by Geoff the Medio »

Gray Area wrote:I’ll get back to you with an updated module in a day, or so.
Should I be waiting? Presently this is delaying up the v0.4 RC3 release...

User avatar
Vezzra
Release Manager, Design
Posts: 6102
Joined: Wed Nov 16, 2011 12:56 pm
Location: Sol III

Re: AI Production Queue

#7 Post by Vezzra »

Looks like Gray Area can't stop by ATM for whatever reasons, so I decided to help out and made the necessary modifications to ProductionAI.py. Run a test game, seems to work. Patch file attached.
Attachments

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


Post Reply