Author Topic: AI  (Read 2585 times)

discodowney

  • Guest
AI
« on: 4 August 2010, 14:02:51 »
Hi,

so im doing some work with the AI. But im curious exactly how the AI works. I think it was mentioned before that its a Rule based system. So the AI goes through a set of rules and when conditions are met for a rule that is executed. Is there any documents or anything that explain the AI in greater detail, or what each class is used for and how they are used (the classes: ai.cpp, ai_interface.cpp, ai_rule.cpp)?

Cheers.

softcoder

  • MegaGlest Team
  • Battle Machine
  • ********
  • Posts: 2,239
    • View Profile
Re: AI
« Reply #1 on: 4 August 2010, 19:52:27 »
As far as I know there currently is no documentation for the AI.

discodowney

  • Guest
Re: AI
« Reply #2 on: 5 August 2010, 13:14:19 »
Okay. Anyone ever worked with these that could give me some info?

EDIT: Also if anyone could explain the lua scripts and how they work within the AI thatd be great. Ive never used Lua before so this could get messy.
« Last Edit: 5 August 2010, 14:09:13 by discodowney »

wciow

  • Behemoth
  • *******
  • Posts: 968
    • View Profile
Re: AI
« Reply #3 on: 5 August 2010, 15:47:40 »
Titi probably knows the most about AI since he added 2 new AIs to the original ones, however as Softcoder said AI is a largely unexplored area.

You could try directing some lua questions at Silnarm but he is currently MIA  :look:

What exactly are you trying to accomplish with the AI?
Check out my new Goblin faction - https://forum.megaglest.org/index.php?topic=9658.0

ultifd

  • Airship
  • ********
  • Posts: 4,443
  • The Glest Video Guy :) The one and only. :P
    • View Profile
    • My Youtube Channel
Re: AI
« Reply #4 on: 5 August 2010, 18:02:17 »
Well, I heard we are all going  to "look into it" later...  :thumbup:

discodowney

  • Guest
Re: AI
« Reply #5 on: 6 August 2010, 11:53:32 »
Right now im just trying to see how it works currently. Ill ask Titi and see what he knows. Cheers

silnarm

  • GAE Team
  • Behemoth
  • ********
  • Posts: 1,373
    • View Profile
Re: AI
« Reply #6 on: 7 August 2010, 01:28:45 »
zombiepirate wrote up a very brief overview a while back,
http://sourceforge.net/apps/trac/glestae/wiki/Ai

Probably doesn't tell you much, but might help if you're just starting to look at it.

If you want to understand it more fully, you are going to have to do a lot of observation &| tinkering :scientist:
Glest Advanced Engine - Code Monkey

Timeline | Downloads

Solifugus

  • Guest
Re: AI
« Reply #7 on: 16 August 2010, 01:25:54 »
The AI is exceptionally simple.  Basically for each AI faction, it cycles through a bunch of things it could do and does the next thing in the list that it can do.

I hacked away at it myself (in pre-MegaGlest versions) trying to implement some features I thought would be cool.  However, the AI interface is extremely limited (built very much custom for the exact kinds of things in its list of things to do).  To do anything more fun, a new generic interface needs to be designed and developed.  I worked on that for a bit but ended up spending a lot of time just documenting how to get various info out of the system.

Giving commands is there and is easy.  Getting info about what specific unit can see what other specific units and the distances between them, for example, is not.  I think the following API would be very nice to have:

Need a way to cycle through your faction's units and then add all these methods to each Unit:

Unit->attackType[int]->attribute(string attribute); to retrieve attack type attributes (e.g. range, damage)
Unit->unitsInSight();to return a vector of units in visual range of this unit
Unit->resourcesInSight();to return a vector of types and locations of resrouces in visual range of this unit
Unit->location();returns cell location of unit (for use with other methods)
Unit->straightDistanceTo(Location location);to determine if in shooting range, for example
Unit->travelDistanceTo(Location location);to determine how many cells to travel to the other unit
Unit->attribute(string attribute);to get attributes like health, energy points, etc. of a given unit
Unit->giveCommand(Command command, Param param);to issue a command to a unit
Unit->setAttribute(string attribute, int value);to set custom attributes (create if doesn't exist) to units

This API really needs to be employable via LUA scripts so the actual AI engines are easily user-programmable.

Other things that would really help would be to allow visual fields of units to be blocked by objects like trees and other units.

I also think the ability to turn on allies would be pretty nice.  The following methods could be employed:
(1) if you directly attack your ally 3 times then they become an enemy faction.
(2) if all enemy factions are destroyed then allies turn on each other (could be an option).  This would make for some interesting positioning around when you know the enemy is almost destroyed.

I think offers of alliances would be nice, also.. but would involve a bit more work.

titi

  • MegaGlest Team
  • Airship
  • ********
  • Posts: 4,240
    • View Profile
    • http://www.titusgames.de
Re: AI
« Reply #8 on: 16 August 2010, 11:31:16 »
Well tons of ideas, but only one game ;-) .

But back to the AI improvements:
Currently I don't think the CPU player plays too bad! Its more a problem that it is too good for human players quite often!
The only thing missing at the moment for me is a bit more expanding. At the moment the CPU player only expands if he is running out of ressources , thats all. I think if this could be improved it would be a great benefit.

More different CPU players?
Currently the ultra and mega CPU players cheat with a ressource multiplier of 3x(ultra) and 5x(mega). This means if a ultra collects one gold it gets 3 instead! Beside of these  normal and ultra have the same behaviour! Easy and mega have another behaviour....
I think this multiplier has a very big affect, so its maybe a good idea to regard this a bit more.

Just ideas (brainstorming)!
We could either add some more CPU names, or we separate the ressource multiplayer as its own setting.
I think the separate setting would be a good idea!
In the custom game menu it maybe can be combined with the current cpu combobox so you have :
cpu-easy
cpu-1x
cpu-2x
cpu-3x
cpu-5x
cpu-mega-1x
cpu-mega-2x
cpu-mega-3x
cpu-mega-4x
cpu-mega-5x
( and maybe the cpu-ultra in addition to stay compatible with the old namings )

or a second combobox for every cpu player is shown where you can select the factor.

I don't really like both solutions, maybe you have another idea? But keep in mind that its a good idea to stay somehow compatible with existing data (scenarios).

« Last Edit: 16 August 2010, 11:32:50 by titi »
Try Megaglest! Improved Engine / New factions / New tilesets / New maps / New scenarios

modman

  • Guest
Re: AI
« Reply #9 on: 16 August 2010, 15:07:05 »
Even though I'm a n00b at the AI, I really want to improve it (someday).  I think people were mentioning certain attributes the AI might have, like aggressiveness and expansiveness.  You could modify them before the game on a slider.  But right now the AI is mostly improved because of cheating I think.

If Sir Modman ever gets good at programming, he wants to make the AI good enough to be competitive even without cheating.  Then you would literally "dumb-down" the AI to make it easier.

Solifugus

  • Guest
Re: AI
« Reply #10 on: 17 August 2010, 13:57:27 »
Building a more generalizable AI API and attaching a scripting language like LUA isn't to suggest that the CPU player's aren't good enough, per se.  Rather, it adds an awesome new element to the game--the ability to experiment with custom AI.  That's the killer feature.

On the other hand, it would be very nice to make it so the ultra and mega didn't cheat (more gold per gathering as mentioned above) but rather actually be smarter.  I mean, if the AI played more like it human, that would be nice.  Some very simple improvements might include: Running away if enemy strength in the vicinity is substantially higher then friendly strength and there is a place to run.  I'd calculate strength by maybe the sum of (each unit's hit points * armor * material strength) for each of enemy and ally units in each unit's vicinity..  This would cause them to fall back under pressure until they group together (or scatter, if pushed through the middle).  Leave the code to attack on contact in place as it is so they keep prodding inward toward the fight, though.  This might also cause them to encircle a well-defended base and wait until enough allies arrive before attacking in a determined way.

Also.. Auto-fight should use the attack-type with the shortest range than can hit the enemy because it's usually more lethal.  And units with repair ability that aren't doing anything might want to auto-repair any damaged units within visual range (I'm not sure if the xml annotations are too generalized to implement this properly, though).

softcoder

  • MegaGlest Team
  • Battle Machine
  • ********
  • Posts: 2,239
    • View Profile
Re: AI
« Reply #11 on: 17 August 2010, 17:49:02 »
One key ingredient to any solution is that it must be deterministic (the element often forgotten). If for some reason the AI behaviour is not deterministic, then network play will not work, so this is a word of caution. We have already seen by using the pathfinder from GAE it has affected network games so that they go "out of synch". Extreme caution must be applied in these areas when making changes.

 

anything