Author Topic: Designing A General Ai  (Read 1347 times)

Offline cycletronic

  • Newbie
  • *
  • Posts: 11
Designing A General Ai
« on: June 22, 2005, 03:03:32 PM »
I'll be posting more about this.  I have a book called AI Game Programming Wisdom (or something).  It has a section on designing a RTS AI.  I don't have the book in front of me, so I'm going to try to remember what I read a few days ago.

The basic idea is to start from a high level and work your way down.  So, we start off with a civilization manager.  Here, you set goals for things like population and resources.

So, say we have a population goal of 100 to start with.  We know that a nursery increases population, so we need to get one of those.  If we can't build one yet (i.e., no structures built, or not researched) then go to the next step down.  If there's not a structure factory to build with, build that.  If there's not command center to connect to, build that.  It all trickles down.

That sounds easy, but it can be difficult to represent that in a computer program.  Quite a few things can be accomplished with this technique, though.  Say I want to use a rpg/emp attack strategy.  They need to be built first.  So you look at what research is required and work backwards until you get to the first unresearched thing.  You also need a vehicle factory.  That requires such and such research, so do that research too, and then build the vehicle factory.  Once everything is in order, build as many rpg/emp vehicles as you can.

The way that seems most natural to implement this in code is to create a requirements class/structure.  You specify what the "goal" is, and any immediate prerequisites to reach that goal.  So an EMP lynx requires "Electromagnetic Pulsing" and a "Vehicle Factory" and "1200 common" (or whatever) to build.  There would also be a requirements record for each of those requirements.

With such a requirements setup, it is easier to direct the AI to do cool things.  You simply say "Make an EMP missile" at the beginning of the match, and it will start researching and building what it needs to in order to get an EMP missile.  

Will such an AI be good?  Maybe, maybe not.  It depends on what it chooses for goals.  And the goals must be chosen on a higher level.  Those goals must either be scripted or made dynamically while playing.

Ok, that's enough brain food (and finger pain) for today.  Maybe I'll get around to adding more to this, or even *gasp* coding it up.  Eventually I'll probably move it to the wiki, also.

Offline Leviathan

  • Hero Member
  • *****
  • Posts: 4106
Designing A General Ai
« Reply #1 on: June 22, 2005, 03:06:36 PM »
Best of luck, would be great if you could be dedicated to bringing some way to make AI easyer or somthing? :P

Offline Cynex

  • Newbie
  • *
  • Posts: 31
Designing A General Ai
« Reply #2 on: June 22, 2005, 04:27:37 PM »
Sounds good.

But what if there are conflicts like several things to build at the same time or several researches to do with only few scientists...?
Maybe buildings have to be disabled, scientists to be drawn off research in order to enable a more important building or similar.
On the other side when the AI needs a certain weapon and is only a few research topics away from it, it should disable spaceport, observatory or other to get scientists (of course only if there aren't the full number on a research).

Therefore all tasks should be ordered by a well chosen priority. Maybe the priority can be dynamically so for example when the opponent is about to attack, the need to build vehicles is higher than the need to research something unimportant..

The AI has to make decisions, it has to improvise and maybe even predict certain events.

I know this sounds all complicated, but you have to think about it sooner or later.

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1194
    • http://www.eddy-b.com
Designing A General Ai
« Reply #3 on: August 13, 2005, 02:10:17 PM »
Cycletronic: i been working on this idea for some time - but decided to create a new campaign (renegades), in so learning to work with the current AI - and eventually creating a "default" Ai that could be inserted into any map or gametype, in wich the AI would do pretty well, without having to cheat.

Needless to say: it's HARD coding this!!  :(  
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline [Final Valiant]

  • Newbie
  • *
  • Posts: 3
Designing A General Ai
« Reply #4 on: August 28, 2005, 03:08:53 AM »
Hey guys, since I took an interest in op2, and since I am a AI Coder, I figured I'd check out the AI stuf! :-D

Anyways, I really like what you have here, and I wanted to add on to this topic.
So, here I go.

The way the AI choses between certain "Goals", like which building to build, or what weaponn\technology to research (I haven't played but a few minutes of OP2, so I'm generalizing), by giving each goal a "weight", a number that represents that goal's importance. The way the goal's weight is set is determined by the specific need for that goal. This need could be a lotta of things in a lot of game situations.
Oh, and this also can be used to make a desired goal list, where the most important and primary goal is put at the top, then the ones that are secondary are right below, and it continues down. But, when one goal is finished, the goals in this list are re-evaluated, and resorted, based on their *current* weight, determined, again, by changing game situations.

Hey, is this making any sense? lol.
Cause, I'm not really great at explaining stuff...

I hope it helps, at least! :-D

I'll be back for more AI goodies!



 

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1194
    • http://www.eddy-b.com
Designing A General Ai
« Reply #5 on: August 28, 2005, 05:22:10 AM »
Quote
Hey guys, since I took an interest in op2, and since I am a AI Coder, I figured I'd check out the AI stuf! :-D

Anyways, I really like what you have here, and I wanted to add on to this topic.
So, here I go.

The way the AI choses between certain "Goals", like which building to build, or what weaponn\technology to research (I haven't played but a few minutes of OP2, so I'm generalizing), by giving each goal a "weight", a number that represents that goal's importance. The way the goal's weight is set is determined by the specific need for that goal. This need could be a lotta of things in a lot of game situations.
Oh, and this also can be used to make a desired goal list, where the most important and primary goal is put at the top, then the ones that are secondary are right below, and it continues down. But, when one goal is finished, the goals in this list are re-evaluated, and resorted, based on their *current* weight, determined, again, by changing game situations.

Hey, is this making any sense? lol.
Cause, I'm not really great at explaining stuff...

I hope it helps, at least! :-D

I'll be back for more AI goodies!
..yes, it's making sense.
I basicly knew all of this already, but it just never came up before now.. This may help me in rewriting some of the AI routines that are already part of Outpost; something i been wanting to do for a couple months now.
I believe we're almost ready to start a project like that.
The default AI routines, like RecordBuilding and RecordVehReinforce have limitations. For instance, i found an AI that lost all its trucks, yet insisted on building a small lynx army first, before wanting to build 1 truck (and by that time the common metals might be gone already, resulting in a total-loss situation). With using an adaptive weight system, when a truck dies the "construct new truck" weight will go up. When the last truck dies, it goes up to the roof.. resulting in a new truck being issued.
Also, it is very hard to code a way to have a earthworker build tubes to GPs, after they been constructed. Using the original gaming format, you'd have to create a trigger for each seperate GP to test if it got built.

Some of the coders already know, i want to create a new event-system, rather then using the existing trigger-system, which has obvious (not to say very annoying) shortcomings.
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz