Author Topic: Making the AI constantly Attack?...  (Read 2095 times)

Ildiz

  • Guest
Making the AI constantly Attack?...
« on: 6 April 2011, 10:51:42 »
Hey guys/girls,

I've been playing around with the AI some more, trying to get 3 different types of AI going.
The AI I have at the moment are as follows:
1. Resource horder - only gatheres resources and expands, doesn't produce warrior units.
2. Overly Defensive - Produces a lot of warrior units, but doesn't expand and doesn't attack (only auto attack enabled), designed to defend a single base(with multiple castles).
3. Overly Aggressive - designed to produce lots of warriors and attack constantly (idealy, they wouldn't expand)

I'm having a problem with the last AI. I can't seem to get them to attack my base 'constantly'. At the moment all they do is send out 1 unit at a time (in rotation) to each of the possible spawn locations on the map (i'm playing on the default map - dark forest (i think)). This causes a very slow attack on my base, which is easily defended by the starting defense tower alone.

How do I get the AI to always attack my base, rather than all the other possible spawn locations aswell? (since all they do at the other locations is just stand there).

Cheers in advance,
Matt

Psychedelic_hands

  • Guest
Re: Making the AI constantly Attack?...
« Reply #1 on: 6 April 2011, 11:10:25 »
Hey  :)

Hmmmm, GAE is actually planning on implementing AI coded in Lua in the future, the benefits of this are:
-Easily modible.
-You can have different AIs per faction.
-Much more flexible.
-Not hard-coded (like the AI we have now)

Maybe this would be an easier way to achieve what you want?

Ildiz

  • Guest
Re: Making the AI constantly Attack?...
« Reply #2 on: 6 April 2011, 11:19:42 »
Hey  :)

It probably would be, but this is for my dissertation which is due in a month xD

Idealy I need a quick work around. I was thinking of changing the test interval number so it's smaller, although I wanted to keep one AI the same as the normal AI is now, so altering the test interval would affect the 'normal' AI aswell as my altered AI.
Unless there is a way to have 2 different test intervals?...

Zoythrus

  • Guest
Re: Making the AI constantly Attack?...
« Reply #3 on: 6 April 2011, 16:07:53 »
How do I get the AI to always attack my base?

isnt this what you are trying to avoid in any normal game?  :P

i agree with Hands, the Lua AI is the way to go.

Ildiz

  • Guest
Re: Making the AI constantly Attack?...
« Reply #4 on: 6 April 2011, 21:37:19 »
isnt this what you are trying to avoid in any normal game?  :P

Haha, well yes. But the nature of this AI is to attack my base (like any other human player would do), rather than attacking empty spaces on the other spawn points when they know no one is there.

-Archmage-

  • Moderator
  • Dragon
  • ********
  • Posts: 5,887
  • Make it so.
    • View Profile
    • My Website
Re: Making the AI constantly Attack?...
« Reply #5 on: 6 April 2011, 22:31:18 »
If you want them to be aggressive don't have them 'constantly' attack, because then you get the effect of dribbling units. Have them focus most on building combat units, then they'll attack like normal(in waves), though at a much faster rate because they're getting the number of units they need to attack faster.
Egypt Remastered!

Proof: Owner of glest@mail.com

ultifd

  • Airship
  • ********
  • Posts: 4,443
  • The Glest Video Guy :) The one and only. :P
    • View Profile
    • My Youtube Channel
Re: Making the AI constantly Attack?...
« Reply #6 on: 6 April 2011, 22:51:31 »
I don't really know if you can hack the present AI in such a way...but once Lua AI is implemented, you could probably do this. The problem is that is mostly not going to be implemented by a month...I think.  :-X

Psychedelic_hands

  • Guest
Re: Making the AI constantly Attack?...
« Reply #7 on: 7 April 2011, 06:20:30 »
He isn't hacking the AI, I don't think he could do his dissertation on a hack lol.
He is rewriting it fully.

Most of us on the forum's are not coders, so ask Silnarm, Hailstone, ydd-whatever(sorry), titi, softcoder or Tom.

Ildiz

  • Guest
Re: Making the AI constantly Attack?...
« Reply #8 on: 7 April 2011, 10:51:00 »
Haha, I wouldn't call what i'm doing as hacking, it's more manipulating the code already in place to give some AI 'characteristics' so to speak (I'm sure people have probably done this before to implement a 'rush' tactic or something similar).

-Archmage- mentioned having them spawn lot of units and they'll attack in waves quicker. Does anyone know the number of units needed to initiate the attack? I've currently got them spawning up to 40 warrior class units (with the code i'd changed to get them attacking each base), but they never sent out a group at all.

I'll have a play around with getting them to attack in waves as mentioned, they spawn units almost without stopping (due to the 20+ workers I have the AI build for the mass resource gathering), so i'll take a look at that and get back to you tomorow at some point.

Cheers guys/gals

ultifd

  • Airship
  • ********
  • Posts: 4,443
  • The Glest Video Guy :) The one and only. :P
    • View Profile
    • My Youtube Channel
Re: Making the AI constantly Attack?...
« Reply #9 on: 7 April 2011, 21:54:39 »
I don't know, what you seem to be doing seems to be more of a hack to me...but that's not a bad thing...

BTW, have you tried analyzing GAE's AI?
http://glestae.git.sourceforge.net/git/gitweb.cgi?p=glestae/glestae;a=blob;f=source/game/ai/ai.cpp;h=01e8dbed66db521cb8d681e0cbc15eea9755ff15;hb=HEAD#l135

Ildiz

  • Guest
Re: Making the AI constantly Attack?...
« Reply #10 on: 7 April 2011, 22:24:05 »
BTW, have you tried analyzing GAE's AI?
Yeah, i'm using all the code in GAE AI to do this.
I'm just using some bits to create extra rules (like building specific building types, ie. barracks and castles).

I've been trying to use the MassiveAttack function to force the AI to attack more often with a particular AI, which isn't working too well at the moment.

Omega

  • MegaGlest Team
  • Dragon
  • ********
  • Posts: 6,167
  • Professional bug writer
    • View Profile
    • Personal site
Re: Making the AI constantly Attack?...
« Reply #11 on: 8 April 2011, 04:00:20 »
Most of us on the forum's are not coders, so ask Silnarm, Hailstone, ydd-whatever(sorry), titi, softcoder or Tom.
Yggdrasil. (Named after a mythical "World Tree" in Norse legend)

I wish you luck. GAE could use some improved AI, even if not necessarily just constantly attacking, but a smarter AI in general (or at least one that works more often). Of course, Lua AI could be coming eventually, but I don't think it will be here for a looong time, so this is a fine idea.
Edit the MegaGlest wiki: http://docs.megaglest.org/

My personal projects: http://github.com/KatrinaHoffert

silnarm

  • Local Moderator
  • Behemoth
  • ********
  • Posts: 1,373
    • View Profile
Re: Making the AI constantly Attack?...
« Reply #12 on: 8 April 2011, 09:43:55 »
I've been trying to use the MassiveAttack function to force the AI to attack more often with a particular AI, which isn't working too well at the moment.

Hi Ildiz,
 I've been cleaning in the AI code recently, and after I first saw this thread couldn't help tweaking...

There was a member of Ai 'knownEnemyLocations' (except with a typo), that was unused, I changed its type(def) to a map<Vec2i,const Unit*>, the 'massive attack' rule is called every second (at normal speed), so I 'maintain the list' then (err... map), adding newly visible enemy buildings and have it refresh the map<>, removing entries for buildings that are dead and visible, and nulling the unit ptr if they are dead but not visible.

The rule test proceeds as normal, but if baseIsStable() && !beingAttacked() then it will blindAttack() to a known enemy building location.

initial commit.

unfortunately I messed it up of course, so see also this one line fix.

If you have them harvesting and producing like mad, adding this will surely make them very aggressive  :-\

I also fixed up the AI logging lots very recently, are you running from git?
« Last Edit: 8 April 2011, 09:46:15 by silnarm »
Glest Advanced Engine - Code Monkey

Timeline | Downloads

Ildiz

  • Guest
Re: Making the AI constantly Attack?...
« Reply #13 on: 8 April 2011, 10:17:31 »
Hey Silnarm,

Brilliant, that's pretty much exactly what I need the AI MassiveAttack to work off.
Yes i'm using the version downloaded from git svn, so how can I easily put this in AND not destroy the code I have already added/edited?

Although I think i'll keep the new code you've done seperate from the 'normal' AI when I downloaded it so that only the aggressive AI works off this code (just a couple of if statements should sort that).

Nice update though :D

silnarm

  • Local Moderator
  • Behemoth
  • ********
  • Posts: 1,373
    • View Profile
Re: Making the AI constantly Attack?...
« Reply #14 on: 8 April 2011, 11:44:23 »
Yes i'm using the version downloaded from git svn, so how can I easily put this in AND not destroy the code I have already added/edited?

That depends, svn and git are two different version control systems, we switched from svn to git not so long ago. If you've been modifying a clone of the git repository then things can be updated easily enough, by committing your changes then doing a 'git pull', although these AI changes I made are actually in a branch, which complicates things... hmm, maybe the process is not entirely trivial (in fact, with all the logging changes I made there would probably be lots of conflicts git couldn't resolve itself, so this would be a bit of a pain).

Maybe just copy and paste from those diffs ;)

Quote
Although I think i'll keep the new code you've done seperate from the 'normal' AI when I downloaded it so that only the aggressive AI works off this code (just a couple of if statements should sort that).

Just one should do it, I'm not sure whether this will be enabled for the forthcoming release, in that patch you will find (in AiRuleMassiveAttack::test()) the following, if (true != false) { :)
Glest Advanced Engine - Code Monkey

Timeline | Downloads

Ildiz

  • Guest
Re: Making the AI constantly Attack?...
« Reply #15 on: 8 April 2011, 12:04:02 »
Ah right,
I'll try copy and paste stuff over into the right places (although no doubt i'll go wrong somewhere xD).
I'm using the git version (since the svn one was broken when i downlaoded it - seems i got caught just before the git change).

Edit:
Just to clarify, the --- a (in red) stuff on the links I need to take out and the +++ b (in green) I add in?



Ok so, there were a few lines causing errors, mainly to do with the AI_LOG and MILITARY, for some reason the version i'm using doesn't know about these things, I've commented those lines out for now since as far as I'm aware the logs aren't needed for the AI to work(?).

The only error left causing me a problem is:
Error   2   error C2039: 'getCountOfUnitType' : is not a member of 'Glest::Entities::Faction'   c:\Users\Matt\Desktop\Take 2 - GLEST\glestae\source\game\ai\ai.cpp   424

Yeah, the "faction->getCountOfUnitType" isn't in faction. I'm assuming this is a version problem. Could I get the code used in Faction.cpp/.h so that this line works please xD



Ok, I used a work around for that by just using the getCountOfType already available in the ai.cpp

And yes, they attack constantly  :o :o

Which is pretty much how I intended, but I might need to play around with the ammount of units it produces, It got to a stage (about 5-10 minutes in) where the AI sent a constant string of enemies at me (about 2-5 yards between each) spanning the length of the map, and it didn't stop xD
Probably need to lower the ammount of workers so they can't produce resources quick enough.

So i'll play around with that, but it's pretty much how I want it, designed to force you into a more defensive role to see if you can still push through their 'endless' waves.

Cheers for that code, worked like a charm.

Edit:
Btw, is there and easy way to make a release version of my version so that I can have other people test it? If it's possible just an .exe and as minimal ammount of files to go with it.
I've not used CMake before so I can't tell how it's possible since the file system looks a bit complicated to me.

Edit by Omega: Merged 3 posts into one. Please do not triple post if only one hour apart.
« Last Edit: 8 April 2011, 19:18:08 by Omega »

silnarm

  • Local Moderator
  • Behemoth
  • ********
  • Posts: 1,373
    • View Profile
Re: Making the AI constantly Attack?...
« Reply #16 on: 15 April 2011, 06:50:02 »
another crash fix was required, and it was using an evil M$ extension to std::map<>  :|

Ai::evaluateEnemies() now looks like this:
Code: [Select]
void Ai::evaluateEnemies() {

// 1. maintain knownEnemyLocations
// remove if enemy building is dead and visible, null Unit pointers if dead and not visible
const int teamIndex = aiInterface->getFaction()->getTeam();
UnitPositions::iterator it = m_knownEnemyLocations.begin();
UnitPositions::iterator itEnd = m_knownEnemyLocations.end();
vector<Vec2i> remList;
while (it != itEnd) {
const Vec2i tPos = Map::toTileCoords(it->first);
bool canSee = g_map.getTile(tPos)->isVisible(teamIndex);
bool dead = it->second == 0;
if (canSee) {
if (dead || it->second->isDead()) {
remList.push_back(it->first);
}
} else {
if (!dead) {
if (it->second->isDead()) {
it->second = 0;
}
}
}
++it;
}
foreach (vector<Vec2i>, it, remList) {
m_knownEnemyLocations.erase(*it);
}

// 2. refresh visibleEnemies and closestEnemy
m_visibleEnemies.clear();
aiInterface->findEnemies(m_visibleEnemies, m_closestEnemy);

// 3. update knownEnemyLocations with any previously unseen enemy buildings
foreach_const (ConstUnitVector, it, m_visibleEnemies) {
const Unit &enemy = **it;
if (enemy.isBuilding()) {
Vec2i bPos = enemy.getCenteredPos();
if (m_knownEnemyLocations.find(bPos) == m_knownEnemyLocations.end()) {
m_knownEnemyLocations[bPos] = &enemy;
}
}
}
}
Glest Advanced Engine - Code Monkey

Timeline | Downloads

 

anything