AI programming

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

Moderator: Committer

Message
Author
freereign
Space Squid
Posts: 53
Joined: Wed Mar 19, 2008 4:40 pm

AI programming

#1 Post by freereign »

Hello,
I have been following this project since ~v0.2 and I love what you all are doing! I finally decided to register on these forums specifically because I want to help work on this game.

Tyreth said just to post here, introduce myself, and tell what I would be working on. I've already introduced myself. And I intend to help out with the AI programming.

If anyone has any pointers (no pun intended) on getting started delving into the existing AI code, go ahead and tell me.
MoO: Darloks Rule!
MoO2: Custom Darloks Rule!
MoO3: Dunno cuz I'm a cheapskate

User avatar
The Silent One
Graphics
Posts: 1129
Joined: Tue Jul 01, 2003 8:27 pm

Re: AI programming

#2 Post by The Silent One »

Hi freereign, welcome! :)

I'll be happy to fill you in on what's been done so far and where you can contribute. However, I'm currently very busy, but I'll get back to you ASAP.

I'm working on exploration, colonisation and production,
m_k considers working on research or design.

My next project would be resource management (means: setting focus), would you be interested to work on that? Otherwise, just have a look and tell us what you'd like to do.
If I provided any images, code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0.

freereign
Space Squid
Posts: 53
Joined: Wed Mar 19, 2008 4:40 pm

Re: AI programming

#3 Post by freereign »

I was considering either war AI (deciding which planets to attack when, and in what order) or research AI. But an integral part of research AI is the RP cost of each Tech. (when deciding, one needs to consider what is needed now, and how long will it take).

Another note: I will be working with a static debian build of freeorion (will update pyAI from svn) until I get it to compile under Ubuntu Hardy.
MoO: Darloks Rule!
MoO2: Custom Darloks Rule!
MoO3: Dunno cuz I'm a cheapskate

m_k
Space Floater
Posts: 33
Joined: Wed Mar 12, 2008 10:54 am
Location: Aachen, Germany

Re: AI programming

#4 Post by m_k »

freereign wrote:I was considering either war AI (deciding which planets to attack when, and in what order) or research AI. But an integral part of research AI is the RP cost of each Tech. (when deciding, one needs to consider what is needed now, and how long will it take).
I believe the war AI will be the hardest of them all, because it will not only need to coordinate attacks, but also defense, since they are closely related and it will need to communicate its demands with most of the other AIs, including resource management. So you could try, but I believe it will be wiser to gather some ideas first and maybe start a thread about it first.
Considering research AI, I'm nearly done with it, and the approach I took is able to cope with changes in the tech tree and the fact, that the RP costs will change. Expect a thread soon. :wink:

freereign
Space Squid
Posts: 53
Joined: Wed Mar 19, 2008 4:40 pm

Re: AI programming

#5 Post by freereign »

Alright, then I will start on resource management. Once the diplomacy engine is finished, I wouldn't mind working on the diplomacy AI either. But either of you could if you wish.
MoO: Darloks Rule!
MoO2: Custom Darloks Rule!
MoO3: Dunno cuz I'm a cheapskate

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

Re: AI programming

#6 Post by Geoff the Medio »

If one of you is willing and able, I'd appreciate someone writing a FreeOrion python AI interface document on the wiki. Currently the only documentation is the C++ source code, which is obviously not ideal, and definitely harder to use than proper documentation.

User avatar
The Silent One
Graphics
Posts: 1129
Joined: Tue Jul 01, 2003 8:27 pm

Re: AI programming

#7 Post by The Silent One »

freereign wrote:Alright, then I will start on resource management.
Before you start, we should talk about AI demand assessment... the production UI as well as the resource management AI will make use of this so they should share a common demand interface. I've done some basic work on this and I'll put this up for discussion soon - the basic idea however is to have a set of demands that -like meters- are assigned values from 0-100; the AI will try to meet all of the demands as well as possible.
However, don't feel discouraged to do anything. I just try to avoid waste of energy.
freereign wrote:Once the diplomacy engine is finished, I wouldn't mind working on the diplomacy AI either. But either of you could if you wish.
I certainly don't mind.
If I provided any images, code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0.

freereign
Space Squid
Posts: 53
Joined: Wed Mar 19, 2008 4:40 pm

Re: AI programming

#8 Post by freereign »

The Silent One wrote:
freereign wrote:Alright, then I will start on resource management.
Before you start, we should talk about AI demand assessment... the production UI as well as the resource management AI will make use of this so they should share a common demand interface. I've done some basic work on this and I'll put this up for discussion soon - the basic idea however is to have a set of demands that -like meters- are assigned values from 0-100; the AI will try to meet all of the demands as well as possible.
However, don't feel discouraged to do anything. I just try to avoid waste of energy.
freereign wrote:Once the diplomacy engine is finished, I wouldn't mind working on the diplomacy AI either. But either of you could if you wish.
I certainly don't mind.
Alright. I had a similar plan in mind. The AI would assign a priority to each asset each turn, then would make necessary changes to it. So if the empire needs more PP than RP, then PP would have a higher priority then RP. So, say we had twice as many RP(Priority 100) as PP(Priority 50), but we wanted then to be equal. The AI would move the RP Priority down and the PP priority up, until there were an equal amount of Points in each. This may be what you were saying. Anyway, another thing that could adjust priorities would be ruler personalities or citizen wants, or both. If a leader naturally leans more on Research than Production, then Research would have a higher priority than Production. On the other hand, if the citizens are anti-technology (like the Amish, sorta) then priorities would shift and Production would have a higher priority than Research.

That may be too complicated. But both could be generated using random numbers. (0=tech inclined,1=neutral,2=production inclined). Of course there are more resources than RP and PP, but you get the idea.
MoO: Darloks Rule!
MoO2: Custom Darloks Rule!
MoO3: Dunno cuz I'm a cheapskate

User avatar
The Silent One
Graphics
Posts: 1129
Joined: Tue Jul 01, 2003 8:27 pm

Re: AI programming

#9 Post by The Silent One »

freereign wrote:The AI would assign a priority to each asset each turn, then would make necessary changes to it. So if the empire needs more PP than RP, then PP would have a higher priority then RP. So, say we had twice as many RP(Priority 100) as PP(Priority 50), but we wanted then to be equal. The AI would move the RP Priority down and the PP priority up, until there were an equal amount of Points in each. This may be what you were saying.
Exactly.
freereign wrote:Anyway, another thing that could adjust priorities would be ruler personalities or citizen wants, or both. If a leader naturally leans more on Research than Production, then Research would have a higher priority than Production. On the other hand, if the citizens are anti-technology (like the Amish, sorta) then priorities would shift and Production would have a higher priority than Research.
This is what I would be aiming at, and later we will have to accommodate the leader/peoples attitude with the demand assessment, but at this point it's irrelevant. We can come back to this when we handle races.
If I provided any images, code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0.

m_k
Space Floater
Posts: 33
Joined: Wed Mar 12, 2008 10:54 am
Location: Aachen, Germany

Re: AI programming

#10 Post by m_k »

freereign wrote: Alright. I had a similar plan in mind. The AI would assign a priority to each asset each turn, then would make necessary changes to it. So if the empire needs more PP than RP, then PP would have a higher priority then RP. So, say we had twice as many RP(Priority 100) as PP(Priority 50), but we wanted then to be equal. The AI would move the RP Priority down and the PP priority up, until there were an equal amount of Points in each. This may be what you were saying. Anyway, another thing that could adjust priorities would be ruler personalities or citizen wants, or both. If a leader naturally leans more on Research than Production, then Research would have a higher priority than Production. On the other hand, if the citizens are anti-technology (like the Amish, sorta) then priorities would shift and Production would have a higher priority than Research.

That may be too complicated. But both could be generated using random numbers. (0=tech inclined,1=neutral,2=production inclined). Of course there are more resources than RP and PP, but you get the idea.
No one said it would be easy. There is also more to it than just random numbers, an empire at war will have to divert more resources to PP, while at peace most can be spend on accumulating food, farming, mining and RP, if the army is already large enough. But the exact assesment of priorities will be needed for nearly all AIs so its best put in yet another AI. We should just agree on a standartized interface for this some time in the future. For now just expect that there can be different priorities and that they can change not only from empire to empire but also with time. You'll probably also have to include some sort of dampening method, so that the AI doesn't change planetary focus to often, but only when really needed.

freereign
Space Squid
Posts: 53
Joined: Wed Mar 19, 2008 4:40 pm

Re: AI programming

#11 Post by freereign »

m_k wrote:
freereign wrote: Alright. I had a similar plan in mind. The AI would assign a priority to each asset each turn, then would make necessary changes to it. So if the empire needs more PP than RP, then PP would have a higher priority then RP. So, say we had twice as many RP(Priority 100) as PP(Priority 50), but we wanted then to be equal. The AI would move the RP Priority down and the PP priority up, until there were an equal amount of Points in each. This may be what you were saying. Anyway, another thing that could adjust priorities would be ruler personalities or citizen wants, or both. If a leader naturally leans more on Research than Production, then Research would have a higher priority than Production. On the other hand, if the citizens are anti-technology (like the Amish, sorta) then priorities would shift and Production would have a higher priority than Research.

That may be too complicated. But both could be generated using random numbers. (0=tech inclined,1=neutral,2=production inclined). Of course there are more resources than RP and PP, but you get the idea.
No one said it would be easy. There is also more to it than just random numbers, an empire at war will have to divert more resources to PP, while at peace most can be spend on accumulating food, farming, mining and RP, if the army is already large enough. But the exact assesment of priorities will be needed for nearly all AIs so its best put in yet another AI. We should just agree on a standartized interface for this some time in the future. For now just expect that there can be different priorities and that they can change not only from empire to empire but also with time. You'll probably also have to include some sort of dampening method, so that the AI doesn't change planetary focus to often, but only when really needed.
Correct, but we don't have war really done yet :)
Also, I wasn't planning on adding the ruler/citizen modifiers until we actually have races, just leaving room to add them.
MoO: Darloks Rule!
MoO2: Custom Darloks Rule!
MoO3: Dunno cuz I'm a cheapskate

freereign
Space Squid
Posts: 53
Joined: Wed Mar 19, 2008 4:40 pm

Re: AI programming

#12 Post by freereign »

I believe I have figured out a remarkably simple way of calculating priorities! It is simple. We take the amount of a resource being produced (lets say food) and then divide it by the requirement. If it is more than 1, we decrease the priority, if it is 1, then we keep it the same, if it is less than 1, we increase priority.

So if we are producing 10 food and we need 10, it comes out to 1. Meaning no change. But if we are producing 15 food and we need 10, it comes out to 1.5. This means that we need to lower the priority. Or if we are producing 5 and we need 10, then it comes out to 0.5 and we increase the priority.

Food automatically takes priority over Research, Industry, Minerals, and Trade so that none of your population starves.

What do you think?
MoO: Darloks Rule!
MoO2: Custom Darloks Rule!
MoO3: Dunno cuz I'm a cheapskate

m_k
Space Floater
Posts: 33
Joined: Wed Mar 12, 2008 10:54 am
Location: Aachen, Germany

Re: AI programming

#13 Post by m_k »

In the simple case of food, this would be the right solution, yes, apart from the fact that you should consider including a factor for building up reserves, since the need for food often changes much faster than the production can adapt. But this only works in the limited case where a definitve requirement exists which isn't true for the other resources.

freereign
Space Squid
Posts: 53
Joined: Wed Mar 19, 2008 4:40 pm

Re: AI programming

#14 Post by freereign »

Like I said, food would have a higher priority than the others. What I meant was that food would need like a 1.2-1.5 instead of a 1. For PP and RP, the goal would be to be able to finish the current tech/production in 1 turn. The AI will balance it, giving food the priority and making the result of production/requirement for RP and PP equal (or as close to that as possible).

If anyone has any other ideas, please give me them. I want this AI to be good, not mediocre.
MoO: Darloks Rule!
MoO2: Custom Darloks Rule!
MoO3: Dunno cuz I'm a cheapskate

m_k
Space Floater
Posts: 33
Joined: Wed Mar 12, 2008 10:54 am
Location: Aachen, Germany

Re: AI programming

#15 Post by m_k »

freereign wrote:Like I said, food would have a higher priority than the others. What I meant was that food would need like a 1.2-1.5 instead of a 1. For PP and RP, the goal would be to be able to finish the current tech/production in 1 turn. The AI will balance it, giving food the priority and making the result of production/requirement for RP and PP equal (or as close to that as possible).

If anyone has any other ideas, please give me them. I want this AI to be good, not mediocre.
I don't believe it would be such a good idea to try to get PP and RP up to a distinct level given by the current production/research queues, it will be better to let the production/research AI take care of not starting projects that will take ages instead of projects that will be finished soon. Also since more than one project can be build/researched at once it would sort of cripple the AI to artifically limit it to one project. Maybe the best idea is the demand system the silent one mentioned. The management AI would get demands/priorities, like in the range 1-100 for production, research and trade and then first try to get the food production to 105% (or something the like) of what's needed, then balance the other four so that they have the same ratios as the demands (the mining should be at 95% of the production). So for example with a population of 200 and demands of 50 for production, 25 for research and 10 for trade 210 food, 95 mining, 100 production, 50 research and 20 trade would be ideal, and so on. The tricky thing will be deciding when everything is of the balance so much that the focus will need to change. You'll probably have to devise some set of rules for this and test it until you found the right parameters.

Post Reply