Second Pass on AI

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

Second Pass on AI

#1 Post by Dilvish »

Hi, well I did another revamp of the AI. It manages its fleets a fair bit more intelligently now & should do a much better job of defense and be able to put up decent resistance for longer than before. I had also hoped to work in some improved colonization, but I think I should toss this over while Vezzra is still around to (hopefully) work it into a pre-packaged build for the Windows users.

In updating to the current head and making sure this is all compatible, I just now saw the implementation of Rebels, etc. Hopefully my next pass can have some improved invasion planning to cope with Rebels, as well as better colonization. I'll also get around to planning some better ships for the AIs at the higher end of the tech chain, as it stands now they get stuck with upper-mid-tier ships.

Feedback of any kind is always welcome.

p.s. oh yeah, released under GPL 2.0
Attachments
AI_upgrade3.zip
(61.45 KiB) Downloaded 58 times
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: Second Pass on AI

#2 Post by Geoff the Medio »

Dilvish wrote:I just now saw the implementation of Rebels, etc. Hopefully my next pass can have some improved invasion planning to cope with Rebels...
Rebels stuff isn't finished yet, but also shouldn't yet have any impact on the game, as long as nothing modifies the rebel troops meter. Properly implementing rebels will require a bunch of content changes, perhaps including a "suppress rebels" focus or similar, and ways to determine how many rebel troops should be present, including various modifiers to happiness, and some way for a planet to know whether it should have rebellions at all (which recently captured planets should more often than an empires self-colonized planets)... So, for the short term, don't worry about it for the AI.

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

Re: Second Pass on AI

#3 Post by Vezzra »

Dilvish wrote:...but I think I should toss this over while Vezzra is still around to (hopefully) work it into a pre-packaged build for the Windows users...
Done. I've committed your update to SVN, the new test builds already have these changes incorporated.

I had to fix two things:

1.) The PythonEmpireWrapper.cpp you provided had the following statement on line 69:

Code: Select all

typedef typename std::pair<int, int> IntPair;
Here the compiler complained about the "typename" statement. Removing it solved the issue.

2.) The debug print statement on line 61 in ProductionAI.py:

Code: Select all

print "    " + str(buildingType.name) + " cost:" + str(buildingType.productionCost) + " time:" + str(buildingType.productionTime)
threw an exception:

Code: Select all

2012-10-15 20:10:22,548 ERROR AI : Traceback (most recent call last):
2012-10-15 20:10:22,548 ERROR AI :   File "/Users/.../SoftwareProjekte/FO/release/FreeOrion/Xcode/build/Test/FreeOrion.app/Contents/Resources/default/AI/FreeOrionAI.py", line 233, in generateOrders
2012-10-15 20:10:22,549 ERROR AI :     ProductionAI.generateProductionOrders()
2012-10-15 20:10:22,549 ERROR AI :   File "/Users/.../SoftwareProjekte/FO/release/FreeOrion/Xcode/build/Test/FreeOrion.app/Contents/Resources/default/AI/ProductionAI.py", line 61, in generateProductionOrders
2012-10-15 20:10:22,549 ERROR AI :     print "    " + str(buildingType.name) + " cost:" + str(buildingType.productionCost) + " time:" + str(buildingType.productionTime)
2012-10-15 20:10:22,549 ERROR AI : Boost.Python.ArgumentError: Python argument types in
2012-10-15 20:10:22,549 ERROR AI :     None.None(buildingType)
2012-10-15 20:10:22,549 ERROR AI : did not match C++ signature:
2012-10-15 20:10:22,549 ERROR AI :     None(BuildingType {lvalue}, int, int)
The strange thing is, when I first tested your updates, everything worked just fine. Before I could commit these changes, I had to merge some revisions Geoff had committed in the meantime, and after that I got this exception. However, as far as I could see, Geoffs commits only changed completely different files than those affected by your update. I must have missed something...

Anyway, I was able to solve this issue by commenting out everything after "str(buildingType.name)".

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

Re: Second Pass on AI

#4 Post by Dilvish »

yeah, I see that building type production cost and time now require an empireID and locationID. The odd thing is that even taking that into account I haven't yet (in the 10 minutes I've been looking at it) been able to get the call to work.

It's especially odd because just a few lines above, I can successfully make a different call thats always had empireID and location ID:
fo.getBuildingType(bldTID).canBeProduced(empire.empireID, homeworld.id)

but trying to call
buildingType = fo.getBuildingType(buildingTypeID)
buildingType.productionCost(empire.empireID, homeworld.id)
fails :cry:

I'll keep looking at it, though it's not critical, currently the AI doesn't take that info into account, it was just for debugging purposes.
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: Second Pass on AI

#5 Post by Geoff the Medio »

Dilvish wrote:yeah, I see that building type production cost and time now require an empireID and locationID. The odd thing is that even taking that into account I haven't yet (in the 10 minutes I've been looking at it) been able to get the call to work.
The problem is that productionTime and productionCost are exposed as properties, not functions, so there's probably no way they'll work. I was just about to attempt to fix it by exposing as functions, and adding a default case (using the capital and the AI player's empire id) as a property.

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

Re: Second Pass on AI

#6 Post by Dilvish »

Oh yes, good catch Geoff, that's exactly it. I just changed the ".add_property" for those to ".def" , recompiled and tried the calls again as above and they work just fine.
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: Second Pass on AI

#7 Post by Geoff the Medio »

Dilvish wrote:I just changed the ".add_property" for those to ".def" , recompiled and tried the calls again as above and they work just fine.
Should I not bother with the default case properties then?

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

Re: Second Pass on AI

#8 Post by Dilvish »

right, here's a new version of univerwrapper with just those 2 lines changed, let's just go with that.

I should also note, I can see that this new AI round still needs a fair bit of tuning It had a number of important new hooks in the various wrappers, though, that I really wanted to get submitted before the code changes I was making got to be too much of a headache to merge with the ones Geoff was making. I think once I get the new python scripting routines tuned well, it will be a substantial improvement; I'll try to get that done as soon as possible.
Attachments
PythonUniverseWrapper.cpp
(34.71 KiB) Downloaded 53 times
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: Second Pass on AI

#9 Post by eleazar »

Dilvish wrote:...I'll try to get that done as soon as possible.
Your work and quickness in the AI is very much appreciated. :D
However, don't let it become an obligation that's no longer fun.

I'd rather you work at a slower, sustainable pace, and stick around for the long haul rather than feel like feel like you need to work at a certain rate, and eventually burn out your enjoyment in working on the project. Choose the pace that you want, but don't worry that we've started to frown at you because updates, corrections, etc aren't swiftly made.

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

Re: Second Pass on AI

#10 Post by Dilvish »

Thanks for the kind words. Here's a couple more tweaks to the AI.
Attachments
AI_upgrade3.1.zip
(6.38 KiB) Downloaded 49 times
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: Second Pass on AI

#11 Post by Geoff the Medio »

Dilvish wrote:Here's a couple more tweaks to the AI.
FYI, an upcoming commit will require similar changes to how tech, ship part, ship hull, and ship design production / research costs and time are accessed from Python.

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

Re: Second Pass on AI

#12 Post by Dilvish »

Ok, I'll keep that in mind. Perhaps as a failsafe I'll try to work in a bunch of
try:
current
except:
new

calls for all those things, it will be usable during your testing and wont be broken immediately upon update
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: Second Pass on AI

#13 Post by Geoff the Medio »

Dilvish wrote:...it will be usable during your testing and wont be broken immediately upon update
The update has already happened, so if you're building the latest svn, the try/except shouldn't be necessary.

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

Re: Second Pass on AI

#14 Post by Dilvish »

Geoff the Medio wrote:
Dilvish wrote:...it will be usable during your testing and wont be broken immediately upon update
The update has already happened, so if you're building the latest svn, the try/except shouldn't be necessary.
Ah, no, hmm. I thought I had gotten fully up to date earlier today, but must have been before your changes went in, I certainly see a fair number of files needing update now. For some reason my IDE stopped showing me when files need updating & I have to check a different tool, need to look up how to fix that.

Anyways, if there's not default versions like we considered earlier, compatible with the previous calls, then the AI is likely crippled - I'll double check & try to get changes in soon if needed.
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: Second Pass on AI

#15 Post by Geoff the Medio »

Dilvish wrote:Anyways, if there's not default versions like we considered earlier, compatible with the previous calls...
I didn't add any.

Post Reply