First Pass at an AI upgrade

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

First Pass at an AI upgrade

#1 Post by Dilvish »

Hi, I've made a number of changes to the AI that really help it be more challenging. First off, I've given it a fixed research schedule that I think works better than the previous arrangement. Second, I gave it a few more ship building options, and implemented a naming scheme so that it always builds the best available in class rather than a random one in a given class (really only effects military ships currently). I also improved the colonization decision making so that it takes into account related technology, and I tweaked the production/research priority handling as well.

***revised files attached a few posts down***

You can drop the attached zip file in your "FreeOrion/default" folder (after backing up said folder please), and upon unpacking it should replace 3 of the text files related to ships (I only updated the english stringtable, so if you use a diff language there may be problems unless you port my stringtable changes), and will replace a few of the AI python files.

I've play-tested this a bit, but not as much testing as I'd planned, so definitely backup the default folder before unpacking.

That said, I'm pretty proud of these improvements; the seem to me to do a lot to making the game enjoyable for the strategy challenge rather than being more of a sandbox. I'm quite interested in hearing feedback & will try to be responsive if anyone has trouble with it. I have been getting a lot of "end of file" disconnects from the networking thread, lately that I haven't been able to figure out yet, but I don't *think* it's from these AI changes.

Cheers,
Dilvish

p.s. I release this code under the GPL 2.0 license.
p.p.s. My "end of file" disconnections seem to be entirely linked in with the system design system -- I very frequently get disconnects upon game save after making new ship designs or deleting old ones. If I do the design changes immediately after loading a game file, I can then save the game & things seem to proceed fine. I'll try double checking if this could be tied to any typos in the revised ship files included above.
Last edited by Dilvish on Sun Sep 23, 2012 9:20 am, edited 4 times in total.
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
eleazar
Design & Graphics Lead Emeritus
Posts: 3858
Joined: Sat Sep 23, 2006 7:09 pm
Location: USA — midwest

Re: First Pass at an AI upgrade

#2 Post by eleazar »

Sounds promising!

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

Re: First Pass at an AI upgrade

#3 Post by Geoff the Medio »

Geoff the Medio wrote:
Dilvish wrote:Hi, I've been working on AI upgrades and am pretty pleased with them. I'll upload a zip file & make a separate post for it.
Be sure to note in your post that you release the changes under the GPL 2.0 or later.
Also, what version of FreeOrion are these changes written for?

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

Re: First Pass at an AI upgrade

#4 Post by Dilvish »

Geoff the Medio wrote:
Geoff the Medio wrote:
Dilvish wrote:Hi, I've been working on AI upgrades and am pretty pleased with them. I'll upload a zip file & make a separate post for it.
Be sure to note in your post that you release the changes under the GPL 2.0 or later.
Also, what version of FreeOrion are these changes written for?
I believe I grabbed the trunk via SVN early morning of Sept 8. The changelog is dated 9/4/12 and says v0.4.1 + SVN -- If I go into svn I can see lots of revision numbers for files that have changed since then, but I'm not that famiar with SVN and I'm not sure how to more precisely identify the version I have.
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: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: First Pass at an AI upgrade

#5 Post by Geoff the Medio »

Dilvish wrote:p.p.s. My "end of file" disconnections seem to be entirely linked in with the system design system -- I very frequently get disconnects upon game save after making new ship designs or deleting old ones. If I do the design changes immediately after loading a game file, I can then save the game & things seem to proceed fine. I'll try double checking if this could be tied to any typos in the revised ship files included above.
You should make a separate thread about this. I doubt it's related to any changes you've made, and even if it is, it probably still shouldn't be happening.

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

Re: First Pass at an AI upgrade

#6 Post by Geoff the Medio »

Dilvish wrote:Hi, I've made a number of changes to the AI that really help it be more challenging.
A few requested changes:
* Update SVN to the latest revision, so that your stringtable file has the additions since the version you based your changes on.
* Replace all tab characters with four spaces in changes you made.

Please resubmit with those changes...

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

Re: First Pass at an AI upgrade

#7 Post by Dilvish »

Geoff the Medio wrote:
Dilvish wrote:Hi, I've made a number of changes to the AI that really help it be more challenging.
A few requested changes:
* Update SVN to the latest revision, so that your stringtable file has the additions since the version you based your changes on.
* Replace all tab characters with four spaces in changes you made.

Please resubmit with those changes...
Ok, I cleaned up the tabs that had slipped though before I changed my editor settings. In the review I also realized I had missed one of the changed ship text files, so that's cleared up also). I also fully updated my installation via SVN, merged my changes in, and confirmed that these all still seem to work fine with the current SVN version.

Say, also, just to check -- rather than making a new ship description in the stringtable for every new ship build, in the premade ship designs file for some of the ship designs I specify the same description from the stringtable -- like the designs for SD_MARK_A8 and SD_MARK_A8B both refer to the same description SD_MARK8_DESC . It seemed that ought to work, & I was a bit lazy on the typing, but if the stringtable parser is expecting every ship name to also have an accompanying ship description then I could add the extras. It does seem to work fine, though since I'm having some issues with ship design interactions causing me some disconnects I'm wondering if this could be it. I guess I shouldn't be so lazy and just add the extra descriptions to be sure, but I want to play the game :D

edit: updated files with corrections mentioned below
Attachments
AI_upgrade.zip
(100.56 KiB) Downloaded 73 times
Last edited by Dilvish on Sun Sep 23, 2012 8:18 pm, edited 1 time in total.
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: First Pass at an AI upgrade

#8 Post by Dilvish »

oh, btw, it seems that updating fully to the current SVN fixed the disconnect issues I was having, so it seems not have been related to my being miserly with ship descriptions.
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: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: First Pass at an AI upgrade

#9 Post by Geoff the Medio »

Dilvish wrote:I also fully updated my installation via SVN, merged my changes in...
You didn't do this correctly for the stringtable. Several strings are marked as being removed or other changes undone in your modified version when I compare with the latest SVN.

Re: using the same description string for multiple designs: That should be fine.
oh, btw, it seems that updating fully to the current SVN fixed the disconnect issues I was having, so it seems not have been related to my being miserly with ship descriptions.
Are you rebuilding the executables from source after updating, or did you just update the content files and had it apparently stop disconnecting? Particularly if it was just content files, that's probably just a coincidence / random testing variation... If it is really just from the content files though, it'd be nice if you could isolate a process to reproduce it.

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

Re: First Pass at an AI upgrade

#10 Post by Dilvish »

Geoff the Medio wrote:You didn't do this correctly for the stringtable. Several strings are marked as being removed or other changes undone in your modified version when I compare with the latest SVN.
Ah, well, I did intentionally remove strings that I had superseded, such as SD_MARK1 --> SD_MARK_A1 since I believed the old strings are no longer used in the modified fileset. If that's a problem let me know and I can put those back. If there's something else I messed up with, please at least give an example to help me verify that I don't make the same mistake I made before.
Geoff the Medio wrote:Are you rebuilding the executables from source after updating, or did you just update the content files and had it apparently stop disconnecting? Particularly if it was just content files, that's probably just a coincidence / random testing variation... If it is really just from the content files though, it'd be nice if you could isolate a process to reproduce it.
I rebuilt the executables after updating; I don't think I made any other content changes between the period of having disconnections and no longer having disconnections.
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
Vezzra
Release Manager, Design
Posts: 6095
Joined: Wed Nov 16, 2011 12:56 pm
Location: Sol III

Re: First Pass at an AI upgrade

#11 Post by Vezzra »

Geoff the Medio wrote:
Dilvish wrote:oh, btw, it seems that updating fully to the current SVN fixed the disconnect issues I was having, so it seems not have been related to my being miserly with ship descriptions.
Are you rebuilding the executables from source after updating, or did you just update the content files and had it apparently stop disconnecting? Particularly if it was just content files, that's probably just a coincidence / random testing variation... If it is really just from the content files though, it'd be nice if you could isolate a process to reproduce it.
Whatever the cause for this issue is, it's not fixed in the latest SVN. I just ran a test game with Dilvish's updated AI and content scripts, and experienced a network disconnect (and consequent crash) around turn 95. I didn't have this particular problem before, so that might indicate that it's somehow related to the Dilvish's changes. Unfortunately I'm not able to reproduce the problem, reloading fixed it.

The improvements to the AI's performance are significant however. I'm delighted. :D Aside from the disconnect issues, I'd vote for committing these changes.

User avatar
eleazar
Design & Graphics Lead Emeritus
Posts: 3858
Joined: Sat Sep 23, 2006 7:09 pm
Location: USA — midwest

Re: First Pass at an AI upgrade

#12 Post by eleazar »

What happens if the some techs expected by the new AI script aren't present, or occur in a different order, or with new prerequisits?

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

Re: First Pass at an AI upgrade

#13 Post by Vezzra »

Dilvish wrote:...If there's something else I messed up with, please at least give an example to help me verify that I don't make the same mistake I made before.
An example:

eng_stringtable SVN r5258:

Code: Select all

...

BUILDING
Building

FIELD
Field

PASSED
<rgba 0 255 0 255>(PASSED)</rgba>

FAILED
<rgba 255 0 0 255>(FAILED)</rgba>

...
Your eng_stringtable.txt:

Code: Select all

...

BUILDING
Building

PASSED
<rgba 0 255 0 255>(PASSED)</rgba>

FAILED
<rgba 255 0 0 255>(FAILED)</rgba>

...
The "FIELD" entry is missing in your eng_stringtable.txt.

Another example:

eng_stringtable.txt SVN r5258:

Code: Select all

...

BLD_SHIPYARD_AST_DESC
'''This building is required for the production of all asteroid hulls and all further asteroid processor upgrades.

A massive processing plant dedicated to the purpose of hollowing out asteroids and preparing them to be used as ships' hulls. Asteroids thus prepared are sent to a shipyard in the same system, where they are turned into the final hull. This building can only be built on asteroid belts.'''

...
Your eng_stringtable.txt:

Code: Select all

...
BLD_SHIPYARD_AST_DESC
'''This is an upgrade to the Basic Shipyard and is required for the production of all asteroid hulls and all further asteroid hulls shipyard upgrades.

A shipyard dedicated to the purpose of hollowing out asteroids and using them as ships' hulls. It can only be built at an asteroid belt.'''

...
The text for the BLD_SHIPYARD_AST_DESC in your eng_stringtable.txt is different, an old version actually, that has been replaced by the current version in revision 5252.

Obviously you've been working with an outdated working copy of this file, and didn't merge changes by later commits. I think that is what Geoff was referring to.

Aside from that, nice work with the AI! :D

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

Re: First Pass at an AI upgrade

#14 Post by Vezzra »

eleazar wrote:What happens if the some techs expected by the new AI script aren't present, or occur in a different order, or with new prerequisits?
As far as I can guess:

Not present: Will likely break the AI (because trying to enqueue a nonexistent tech probably results in an exception thrown, aborting the AI python script).

Different order: What exactly do you mean by that?

New prerequisites: Will more or less impact the AI's efficiency at researching (assuming Dilvish has optimized the order in which the techs are reserched), but otherwise things should continue to work, as prerequisites are queued automatically (as far as I know).

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

Re: First Pass at an AI upgrade

#15 Post by Geoff the Medio »

Vezzra wrote:Not present: Will likely break the AI (because trying to enqueue a nonexistent tech probably results in an exception thrown, aborting the AI python script).
It should just put an ERROR line in the AI log file if a nonexistent tech is ordered enqueued. See IssueEnqueueTechOrder in AIInterface.cpp.
...prerequisites are queued automatically (as far as I know).
I think that only happens in the human client; AIs need to explicitly enqueue every tech. If a prereq is missing, the dependent tech will just not receive any RP.

Post Reply