FreeOrion

Forums for the FreeOrion project
It is currently Tue Jun 18, 2013 10:45 pm

All times are UTC




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: AI Python API – Research
PostPosted: Tue Nov 01, 2011 8:48 pm 
Offline
Space Floater

Joined: Sat Sep 24, 2011 4:39 pm
Posts: 44
After seeing how easily new member ‘qsswin’ was able to tweak the program, I took a close look at the AI’s various .py files.

I have minimal formal programming training, have not done any programming in a long time, and have no experience using Python. I have, however, successfully managed to make some tweaks to the Research portion of the AI program. (Given my lack of experience using Python, etc, Research appears to me to be the easiest portion of the AI program to tweak.)

Is anyone else currently working on the Research portion of the AI?

If not, I’m going to attempt to do something with the research priorities listed in class AIPriorityType(object): of the EnumsAI.py file.


Top
 Profile  
 
 Post subject: Re: AI Python API – Research
PostPosted: Tue Nov 01, 2011 11:23 pm 
Offline
Programming, Design, and De Facto Lead
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 8055
Location: Vancouver, BC
Gray Area wrote:
Is anyone else currently working on the Research portion of the AI?
Most likely no.


Top
 Profile  
 
 Post subject: Re: AI Python API – Research
PostPosted: Thu Nov 03, 2011 11:42 pm 
Offline
Space Floater

Joined: Sat Sep 24, 2011 4:39 pm
Posts: 44
Geoff the Medio wrote:
Gray Area wrote:
Is anyone else currently working on the Research portion of the AI?
Most likely no.

Okay then.

I’m going to start by attempting to organize the priorities for the Research Queue, including defining the required calculations for the six (6) techs category priorities.

I know this alone won’t make the AI that much more effective, but it looks like grunt work that needs to be done and I believe it is within my current capabilities.


Top
 Profile  
 
 Post subject: Re: AI Python API – Research
PostPosted: Fri Nov 04, 2011 1:18 am 
Offline
Design & Graphics Lead
User avatar

Joined: Sat Sep 23, 2006 7:09 pm
Posts: 3707
Location: USA — midwest
I don't know anything about how the AI works, but be aware that the tech tree is still fluid, and certain to change, including the number of categories as new features are added, and the game is refined.

_________________
—• Read this First before posting Game Design Ideas!
—• Design Philosophy

—•— My Ideas, Organized —•— Get an Avatar —•— Acronyms —•—


Top
 Profile  
 
 Post subject: Re: AI Python API – Research
PostPosted: Fri Nov 04, 2011 3:59 am 
Offline
Space Floater

Joined: Sat Sep 24, 2011 4:39 pm
Posts: 44
eleazar wrote:
I don't know anything about how the AI works, but be aware that the tech tree is still fluid, and certain to change, including the number of categories as new features are added, and the game is refined.

Thanks for the warning.

If I correctly understand the intended flow of the Research portion of the AI program as it currently exists, the grunt work I am currently attempting will not go to waste.

Don’t worry, changes to existing techs, the addition of new techs, and even the addition of new techs categories will still be able to be programmed into the AI in the future. Those types of changes will, of course, require additional grunt work, but the amount of work required will be proportional to the level of sophistication desired in the AI.

At this point in time, I’m merely attempting to tweak the AI to select the most beneficial techs for initial addition to its Research Queue. (At present, the AI selects its initial techs based upon lack of prerequisites and lowest ‘cost’.)

If I’m successful, I believe I will have gained enough experience to next attempt tweaking the ‘Planet Resource Foci’ portion of the AI.

I would love to go to work on the AI’s ‘Military Operations’ right now. Unfortunately, I need to acquire more expertise with Python and the AI program itself, before I’ll be able to make any useful contributions to the AI’s ability to defend, patrol, attack, or invade.


Top
 Profile  
 
 Post subject: Re: AI Python API – Research
PostPosted: Thu Nov 17, 2011 4:32 pm 
Offline
Space Floater

Joined: Sat Sep 24, 2011 4:39 pm
Posts: 44
The two (2) modified and one (1) new AI modules attached have been run successfully on v0.3.17 [SVN 4282] MSVC 2010.

These modifications are primarily add-ons to the existing framework of the AI program’s Priorities and Research Queue. Their inclusions in the existing program will result in only a very small, incremental increase in the AI’s overall performance. These modifications do, however, ‘flesh out’ the existing AI program to permit more sophisticated programming in the future.

As you are no doubt aware, the AI can not, at present, add new building types to its production queue, or design and build custom ships. Therefore, I have written functions to delete unusable techs from the AI’s research queue. (Without the deletion of these currently unusable techs, the AI simply wastes a lot of valuable research points and turns.)

I have also chosen to deviate from what I perceived to be an ‘apparent pattern’ in the AI Python API. That is, it ‘appears’ that the original AI programmers intended to enqueue techs into the AI’s research queue by category. I see no real advantage in doing that. Instead, I have modified the ResearchAI module to enqueue a few specific, usable techs based upon a few specific production queue priorities. I have also modified the existing techs selection and enqueuing method to be the default method, as, given no other selection criteria, it is in itself an excellent enqueuing method.

I imagine that, in the future, as the AI becomes more sophisticated, the techs selection method will become quite complex. These present modifications represent only a small step in that direction, but they have served their purpose in giving me some valuable experience with the Python programming language.

I release my humble contribution under the terms of the Creative Commons Attribution-ShareAlike 3.0 and GNU GPL 2.0 licenses.


Attachments:
Contribution_01.zip [5.19 KiB]
Downloaded 22 times
Top
 Profile  
 
 Post subject: Re: AI Python API – Research
PostPosted: Sun Dec 04, 2011 6:22 am 
Offline
Programming, Design, and De Facto Lead
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 8055
Location: Vancouver, BC
Is there a reason you've added comments listing the date you added or modified various lines of Python code?

There are various lines with messy whitespace, such as a tab character for no apparent reason at the end of an empty line (especially when the indenting is all spaces) or trailing spaces at the end of lines. It'd be nice if those were cleaned up, though not essential in most cases.

I'm getting some errors using these changed files:
Code:
2011-12-03 22:26:25,399 ERROR AI : AIInterface::IssueEnqueueTechOrder : passed tech_name that is not the name of a tech.

Code:
2011-12-03 22:26:25,402 ERROR AI : Traceback (most recent call last):
2011-12-03 22:26:25,402 ERROR AI :   File "C:\FreeOrion_VS2010_SDK\FreeOrion\default\AI\FreeOrionAI.py", line 127, in generateOrders
2011-12-03 22:26:25,403 ERROR AI :     ResearchAI.generateResearchOrders()
2011-12-03 22:26:25,403 ERROR AI :   File "C:\FreeOrion_VS2010_SDK\FreeOrion\default\AI\ResearchAI.py", line 58, in generateResearchOrders
2011-12-03 22:26:25,404 ERROR AI :     generateDefaultResearchOrders()       
2011-12-03 22:26:25,404 ERROR AI :   File "C:\FreeOrion_VS2010_SDK\FreeOrion\default\AI\ResearchAI.py", line 109, in generateDefaultResearchOrders
2011-12-03 22:26:25,404 ERROR AI :     researchQueueList = getResearchQueueTechs ()         
2011-12-03 22:26:25,405 ERROR AI :   File "C:\FreeOrion_VS2010_SDK\FreeOrion\default\AI\ResearchAI.py", line 179, in getResearchQueueTechs
2011-12-03 22:26:25,405 ERROR AI :     researchQueueList.append(element.tech.name)
2011-12-03 22:26:25,405 ERROR AI : AttributeError: 'str' object has no attribute 'name'

These might be related to some interface changes in this commit, which made researchQueueElement's .tech property return a string of the tech's name, instead of a Tech object.


Top
 Profile  
 
 Post subject: Re: AI Python API – Research
PostPosted: Sun Dec 04, 2011 2:47 pm 
Offline
Space Floater

Joined: Sat Sep 24, 2011 4:39 pm
Posts: 44
Geoff the Medio wrote:
Is there a reason you've added comments listing the date you added or modified various lines of Python code?

Yes, to keep track of the additions and modifications I’ve made to the original modules for my own benefit. As they are an annoyance to others, I will remove all of my tracking comments in any future contributions.
Geoff the Medio wrote:
There are various lines with messy whitespace, such as a tab character for no apparent reason at the end of an empty line (especially when the indenting is all spaces) or trailing spaces at the end of lines. It'd be nice if those were cleaned up, though not essential in most cases.

I will cleanup the ‘messy whitespace’ in any future contributions. I did, however, put them in intentionally, to help clearly indicate where I had made additions and modifications to the original AI modules.

I will also be more careful, in the future, about leaving tab characters, etc. in the AI modules I’ve modified.
Geoff the Medio wrote:
I'm getting some errors using these changed files:

These might be related to some interface changes in this commit, which made researchQueueElement's .tech property return a string of the tech's name, instead of a Tech object.

I suspect you are right. My contributions have been written to run successfully on v0.3.17 [SVN 4282] MSVC 2010. I have not compiled or run the updated program since that release.


Top
 Profile  
 
 Post subject: Re: AI Python API – Research
PostPosted: Mon Dec 05, 2011 2:11 am 
Offline
Space Floater

Joined: Sat Sep 24, 2011 4:39 pm
Posts: 44
Dear Geoff the Medio,

After having thought about it for a bit, I request that you simply discard the contents of my ‘Contribution_01.zip’ file in its entirety.

I have already made additional modifications to the PriorityAI module, in order to implement a new InvasionAI module. Therefore, rather than putting any more work into an already obsolete module, I will clean up and resubmit all three (3) of the modules associated with my first contribution, after I have successfully completed my other work-in-progress. I will, of course, attempt to compile the latest version of the program and verify that my AI modifications work with it before resubmission.

I apologize for the problems associated with my first submittal.


Top
 Profile  
 
 Post subject: Re: AI Python API – Research
PostPosted: Sat Dec 17, 2011 9:06 pm 
Offline
Space Floater

Joined: Sat Sep 24, 2011 4:39 pm
Posts: 44
I wasn’t expecting a new Win32 build to be released so soon, but thank you! The new release will allow me to postpone the dreaded ‘FO compiling learning curve’ for a bit longer. :D

I see that there have been quite a few changes made to the tech tree since the last WIN32 build. It will take me a while to go through them all, but I will make it a priority and will post updated modules that are compatible with the new build in the near future.

Thanks again.


Top
 Profile  
 
 Post subject: Re: AI Python API – Research
PostPosted: Sat Dec 17, 2011 9:53 pm 
Offline
Programming, Design, and De Facto Lead
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 8055
Location: Vancouver, BC
I've already committed your updated scripts after some minor changes (tech.name to just tech mostly). All that needs updating more is, I think, the list of techs to attempt to research. If there are lists of other content, they might also need updating, though.


Top
 Profile  
 
 Post subject: Re: AI Python API – Research
PostPosted: Sun Dec 25, 2011 12:07 am 
Offline
Space Floater

Joined: Sat Sep 24, 2011 4:39 pm
Posts: 44
Attached are a bundle of updated AI modules for research, colonization, invasion, etc.

I release my contribution under the terms of the Creative Commons Attribution-ShareAlike 3.0 and GNU GPL 2.0 licenses.

Happy holidays! :D


Attachments:
GA_Contribution_03.zip [10.75 KiB]
Downloaded 24 times
Top
 Profile  
 
 Post subject: Re: AI Python API – Research
PostPosted: Sun Dec 25, 2011 5:33 am 
Offline
Programming, Design, and De Facto Lead
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 8055
Location: Vancouver, BC
Gray Area wrote:
Attached are a bundle of updated AI modules for research, colonization, invasion, etc.
What's new?


Top
 Profile  
 
 Post subject: Re: AI Python API – Research
PostPosted: Sun Dec 25, 2011 6:54 am 
Offline
Space Floater

Joined: Sat Sep 24, 2011 4:39 pm
Posts: 44
Geoff the Medio wrote:
Gray Area wrote:
Attached are a bundle of updated AI modules for research, colonization, invasion, etc.
What's new?

The TechsListsAI module has been updated to handle additions and deletions to the tech tree since FO v0.3.17 [SVN 4282] MSVC 2010.

The EnumsAI module has been updated to handle the new Defense Category that has been added to the tech tree. While making that update, I also added ‘construction’ resource and focus to their respective classes.

The PriorityAI module has been updated to handle the updates made to the EnumsAI module. (I also rearranged some functions to reflect their order as listed in the EnumsAI module and eliminated some duplicate print statements.)

The ProductionAI module has been updated to handle the updates made to the EnumsAI module. (I also eliminated some duplicate print statements.)

The ColonisationAI module has been updated to ‘see’ and avoid ‘monster populated planets’. (I also added some additional print statements so that I can better see what the AI is doing.)

The InvasionAI module has been updated to utilize, as much as is practical, the same functions as the ColonisationAI module. (Again, I also added some additional print statements so that I can better see what the AI is doing.)

The PlanetUtilsAI module has been updated to support the updates to the ColonisationAI and InvasionAI modules and eliminate an unused function.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group