Playing with the AI

Need help testing contributed art or code or having trouble getting your newest additions into game compatible format? Confused by changes to data formats? Reading through source and wondering what the developers were thinking when they wrote something? Need "how-to" style guidance for messing with VS internals? This is probably the right forum.
denyasis
Hunter
Hunter
Posts: 75
Joined: Thu Mar 19, 2009 10:31 am

Playing with the AI

Post by denyasis »

===================================EDIT========================
hey - here is the .patch file for the data/ai directory. I figure it would be easier to place it up here. For SVN - no garuntees for 0.5, sorry. Use your SVN program to update the directory!

5-17-2009 - Completed a quick Cap Ship AI skeleton. Our large ships will try to make better use of their forward guns by cirlcling thier targets. Small update to the bomber int events.
5-12-2009 - Couldn't sleep, bah! Fixed another typo in the bomber Script. Added my note (Explanation of stuff) files, so If anyone knows better, they can correct me before I kill the AI. Started work on the Capship AI - nothing yet, just some notes in the script file.
4-22-2009 - Did you know interrupt has 2 R's? The Bombers will be focus a little better and be much less indecisive.
4-22-2009- tweaked the distances/threat values a little more. The bomber is more aggressive. Added a condition where the bomber will try to "strafe" out of the way if the target turns toward the bomber (ie trying to hit it with the main gun). Started experimenting on the int(terupt) bomber file, bomber.int.xml
4-17-09 - updated the distances for bomber.agg events and also added a few more evasion events to keep the bombers out of trouble.
Ai directory.patch
Again - just use you're SVN program to update the AI directory :-) Have fun!


================================EDIT===========================


hey - I love my days off...
So today, I got a little bored and decided to play with the AI - since they're all XML and that's about all I can code (you may laugh at me)
I found a wiki page (looks like it was written by the WCU folks) with most of the info I needed here:
http://vegastrike.sourceforge.net/media ... :AIScripts

But I have a few questions:

1. The wiki mentions a file called VegaPersonalities.csv that determines what type of AI a given unit will use given its faction. I found the file in the WCU SVN, but not in VS's. Does it still exist? If not, what determines the AI type?
AI used = <VegaEvent ouput>.THIS PART HERE.xml <-- yeah that thing :-)

2. meterdistance vs. threat -- Meterdistance is from the target object or any object in general? Threat?? distance from a threat? - what does that mean - The target? a unit attacking the AI? any hostile unit?

3. VegaPriorities.csv - what does it do? Target selection if multiple hostiles are present? What do the Values mean?

Thanks in advance. I'm working on trying to give the AI a few more combat options. Currently I've rewritten the Bomber.agg AI so bombers will attempt straffing runs while evading enemy fire (I hope). Now I just need to figure out a way to test the AI's...
You do not have the required permissions to view the files attached to this post.
Last edited by denyasis on Sun May 17, 2009 4:44 pm, edited 6 times in total.
RedAdder
Bounty Hunter
Bounty Hunter
Posts: 149
Joined: Sat Jan 03, 2009 8:11 pm
Location: Germany, Munich
Contact:

Re: Playing with the AI

Post by RedAdder »

"Threat" is a term that means how much the AI hates you.
My guess it is based on your faction alignment plus how much damage you did to a faction.
ace123
Lead Network Developer
Lead Network Developer
Posts: 2560
Joined: Sun Jan 12, 2003 9:13 am
Location: Palo Alto CA
Contact:

Re: Playing with the AI

Post by ace123 »

I think threats might be more specific than that -- I think it refers to units who are actively targeting you, or are in missile range, or have a lock on you.

There's a wiki page that lists the unit functions (though it's a little out of date)
http://vegastrike.sourceforge.net/media ... ngs:Python
and there are functions Threaten, ResetThreatLevel, and Threat() which returns the single threat unit.

So threats seem kind of arbitrary but they are probably based on a few of the factors, and if you are writing an AI script, right now I think they don't handle two people attacking a single unit very well since there is only one threat.
denyasis
Hunter
Hunter
Posts: 75
Joined: Thu Mar 19, 2009 10:31 am

Re: Playing with the AI

Post by denyasis »

ok, thanks for the link. It just gave me a few ideas for the Luddite/Pirate AI's. :twisted:

Looking at the usage in the XML events, I'm gussing the AI is checking the distance of the "threat" unit before activating its scripts. ie - don't fly straight if there's an enemy right next to you.

I've noticed there seem to be several different "styles" with the XML scripts. for example several are written using Meterdistance, but default.final is written using distance where distance looks like a percentage.

Now for another question - Can I have a AI script call for an AI event, Or and AI Event call for another AI event? Providing I place the event(s) in the scripts directory?

Doing that would make life easier As I could call sets of events, instead of copy/pasting the same code pver and over...
denyasis
Hunter
Hunter
Posts: 75
Joined: Thu Mar 19, 2009 10:31 am

Re: Playing with the AI

Post by denyasis »

ok, sorry to burden you all with more ??'s

Code: Select all

<ChangeHead terminate="1" accuracy = "1">
    <ADD>
      <VECTOR Position="v"/>
      <VECTOR x="1" y="0" z="1"/>
    </ADD>
  </ChangeHead>
  <MatchLin local="0" terminate="1">
    <VECTOR x="-10000" y="0" z="10000"/>
  </MatchLin>
1) Ok, I can't find this in the wiki (Not having much luck searching it - many thanks for the links guys), but VECTOR Position="v", I can't find this in the list of Python bindings and Am not sure what it does and what arguements I can put in there:

"v" for Velocity, Vertical, Ventriloquist? what other

2) Lastly the Wiki states that a Generic AI (defualt or sitting duck) can be defined in the missions. Looking at the *.mission files, it appears the AI can be given some orders (order priority). I assume once it has a target, the AI then goes to the Event xml's and loads the appropriate script. I found the AI-Sitting-duck.py - Where is the defualt AI stored? I can't seem to find a .py for it. hardcoded? I'm interested (right now) in the conditions where it decides to with drawl from combat (and spec away).

My only intrest ATM is the combat AI - since its all defined in XML and I'm pretty much limited to writting that. Looking at the scripts, it seems there is a ton of possible queiries the Script can ask the AI. The more possibilities, the more triggers I can write, the more stuff the ships will do in combat :-)

I'm gonna search the wiki some more tonight before work, but right now its nap time (3rd shift - yay)
BtW:
-Bomber AI: Will do a standard approach and straffing run on the target ship.
-Flee AI: I wrote a quick flee system when a ship get too damage to keep fighting. Righ now its for frieghters, but Its flexible enough I can adapt it to almost any style ship with a few variable changes.

Take care!
denyasis
Hunter
Hunter
Posts: 75
Joined: Thu Mar 19, 2009 10:31 am

Re: Playing with the AI

Post by denyasis »

ok, solved the Vector ="v" thing, Everything I need for that is in Vector.py

I guess All I need to know right now is:

1) Where is the "defualt" AI stored?
-I'd really like to know when the AI calls it quits and withdrawls, Specing out.
2)How is the "personality" determined w/o a VegaPersonalties.csv file (how does the AI chose which Combat Event.xml to Load)?
-Right now there are only 4 combat event types. And they treat every situation identically. Why would a fighter attack a base the same way it attacks another fighter?
3)Is it possible to call an event from a script or an event from an event?
-That would go a long way towards making the AI event/scripts more modular.


Thanks all!

Just finished an updated Evade script and wrote a new Cloak and Evade Script (its a hack I won't lie, but the ship will cloak and change its position, so you can't guess where it would be and still shoot it - hope :-)).
denyasis
Hunter
Hunter
Posts: 75
Joined: Thu Mar 19, 2009 10:31 am

Re: Playing with the AI

Post by denyasis »

And then I broke my install!!
More specifically, I decided to download the SVN version of VS a few weeks ago. So I decided "feh, I don't need 0.50 anymore, and I'll just get confused with it, so I'll delete it" and so I did. Afterwards I remembered I had everything I changed, stored in the 0.50 directory and it was not there any more.

So, I started again:

I just wrote a new Evade.xml script. The WiKi indicated there was Evade, Evade up Down, and Evade left right. Also in the WiKi Evade=Evade left right. So I added two new vectors and change heading commands so Evade will cause the shipt to wiggle Up, down, left, and right ( ithink - or possible do a spiral thing - not too sure...)

I also wrote a new Bomber.agg.xml script (again). In it the bomber will attempt to evade enemy fire and keep out of the gun's range. (In the original one, the bomber was instructed to stop, sit there, and keep firing) Here's some test results of the new Event xml compared to the old Event xml:

--Original bomber.agg.xml:--
-10 rounds. 8 Goddard vs 1 Agesipolis
Goddard's won everytime
Avg. # of bomber's lost per round 1.3
Avg. time of each round 88.7 sec
-Bomber's lost in aftershock were not counted

10 rounds. 8 Goddard vs 3 Agasicles
Goddards won 4 times. rest were draws (see notes below)
Avg # of Bomber's lost per round 2
Avg # of Agasicles lost per round 2.2

--New bomber.agg.xml--
-10 rounds. 8 Goddard vs 1 Agesipolis
Goddards won every time
Avg. # of bomber's lost per round .4
Avg. time of each round 99.2 sec
-Bomber's lost in aftershock were not counted

10 rounds. 8 Goddard vs 3 Agasicles
Goddards won 4 times. Rest were draws (see notes below)
Avg # of Bomber's lost per round 2
Avg # of Agasicles lost per round 2

Note: Ok, for some reason, Goddard's and Agasicles' would randomly SPEC away. In almost every case, up to 3 of the Goddard's would just SPEC away at teh start of every round. A similar thing occurred with the Agasicles. In 6/10 rounds for both xml sets, atleast one of the Agasicles would spec away before being attacked/destroyed. There were only 4 times where the bombers were able to wipe them out fast enough in each xml.

I'm pretty happy with the bomber's against a large capship. There were significantly fewer losses. It did take longer to Kill the cap ship, but I guess that is because the new XML has teh bombers changing direction and trying to evade incoming fire.

The test with the corvette (agasicles) is a littel more mixed. With the corvettes randomly SPEC'ing out, its almost imposible to get a true apples to apples comparison. The fewer kills with the new script might be caused by the evasion. Since the bomber's are manuevuring more, they are firing less, hence the corvettes SPEC'ed out before being destroyed (and I'd call it a draw).

Also, it shows that the bomber's weakness is a more mobile target. The bomber's were primarily lost when the corvette was able to turn and fire its forward facing cannons. 2 hits kill a Goddard. Even though the new XML tells the bomber to change heading and evade at certian times, its still dependant on the bomber's thrust ability. A laden bomber is just gonna sit and spin.

Also for the fun of it, I had loaded some Pacifier's, Pirate thales, and an Aeran Star fortess.
Un officially - the Both XML's absolutely shredded the Thales (3 of them) mostly in 50 sec or less.
The Pacifiers seemed to be the last ships to die compered to the Goddard's(better manueverability?)
After 20min, I gave up on the star fortress. I didn't know it would launch fighters though. The bomber's shredded the 6 nicanders that were launched and had the fortress totally red - but then I got bored.

There's still some fine tuning I want to do with them, but nothing major
Here's the patch files for SVN, if anyone is really bored. (they ought to work for 0.50, but no gauruntees)
(I'm a horrible typer, so if anyone notices a typo, let me know, that would be awesom)
Last edited by denyasis on Sat Apr 18, 2009 2:19 am, edited 1 time in total.
loki1950
The Shepherd
Posts: 5841
Joined: Fri May 13, 2005 8:37 pm
Location: Ottawa
Contact:

Re: Playing with the AI

Post by loki1950 »

Looks like your having fun :wink: And i like your testing results the default AI may be in C++ but i am not sure.

Enjoy the Choice :)
my box::HP Envy i5-6400 @2Q70GHzx4 8 Gb ram/1 Tb(Win10 64)/3 Tb Mint 19.2/GTX745 4Gb acer S243HL K222HQL
Q8200/Asus P5QDLX/8 Gb ram/WD 2Tb 2-500 G HD/GF GT640 2Gb Mint 17.3 64 bit Win 10 32 bit acer and Lenovo ideapad 320-15ARB Win 10/Mint 19.2
denyasis
Hunter
Hunter
Posts: 75
Joined: Thu Mar 19, 2009 10:31 am

Re: Playing with the AI

Post by denyasis »

Many thanks - I just hope this is useful to you all at some point

I still need to rerun the tests though. In the above experiment set, I hand set the AI type in the .mission filem (just to make sure the AI would load and work). Hence VegaPersonalities (which isn't in SVN,, if its even used anymore - anyone know? buehler?), VegaPriorities, and VegaEvents were bypassed.
So for the next round, I'll have to allow the AI types to set to default and see if the Game properly selects the Correct Event.xml to load (via VegaEvents.csv which is rather Spartan at the moment).

My ultimate goal kinda hinges on whether or Not VegaPersonalities is used, as I can use that and custom script AI Events to match the ship type and the faction it belongs too. (For example, Merchants would drop frieght and run easily, while Luddites will fight to the death and try to take you with them when they go). It'll be a lot of work at first, but once some good templates are written, it'll really be a matter of setting the thresholds (ie Military units will not flee as early as a civie unit).

Also of note, I added an Afterburn Evade Script to the patch. The ship will Evade up down left and right using the afterburner, if available.

In practice, the bomber's kinda just sit there and umm jiggle/shimmy (their mass is too large to really move). If you want super laughter, make them do a barrel roll. they just kinda tumble away.... Like Al Gore in the Futurama movie - sorry dorky reference - yay.
denyasis
Hunter
Hunter
Posts: 75
Joined: Thu Mar 19, 2009 10:31 am

Re: Playing with the AI

Post by denyasis »

ok - the defualt AI setting correctly chooses the bomber.agg.xml - yay. I also tweaked some of the distance triggers in the xml and added some more trigger for evasion (mainly new "low shields" triggers). In practice, the Goddards are still to bulky to really change direction quickly while under fire, but now they'll atleast try a little sooner. The pacifiers did ok though and were able to hang with the corvettes a little longer.

I think I'll need to creat a more robust evasion script other than the generic "turn left then right" for the bombers due to their size. I'll have to think on that.

Anyhow, the new .patch file is up top - I'll keep updating it there, yay
tfc_generalKMK
Merchant
Merchant
Posts: 39
Joined: Wed Mar 18, 2009 9:28 pm

Re: Playing with the AI

Post by tfc_generalKMK »

i don't know how complicated this would be but in a real combat situation a plane (closest thing i know to any of these craft) would evade not just left and right but also up and down
denyasis
Hunter
Hunter
Posts: 75
Joined: Thu Mar 19, 2009 10:31 am

Re: Playing with the AI

Post by denyasis »

exactly!

At the moment the SVN has three scripts named evade (according to the wiki): Evade, Evade up down, and Evade left right. Also, according to the wiki, Evade is the same as Evade left right.

What I did (or am trying to do :-P):
I took the original SVN Evade.xml and added commands to it so the ship will evade up, down, left, and right.
I also made an Afterburn Evade, which does the same thing, just with the afterburner on (if the ship has one)

Each script is essentially a different set of movements perfromed by our AI ship. The Event XML's set the conditions that trigger the scripts. (if condition X [damage to shield], then script y [evade for z sec])

hope that helps.

btw - when you all play the game, is there anything that stands out to you about the enemy AI in combat? Anything Good, bad, silly? I seriously doubt everyone has the same flying style, so we might tend to focus on different things - and notice different pacurlarities about the Combat AI.
Kellyc
Insys Pilot
Insys Pilot
Posts: 2
Joined: Wed Apr 15, 2009 12:20 pm

Re: Playing with the AI

Post by Kellyc »

Been playing around with your patch some, I like it though I've only been playing with the game (SVN) for afew months now so not sure I'm qualified to complain.

One thing I would mention about the combat AI is the Koala, any AI driving that ship should flee, not close into boarding range. The Koala is nothing more then fodder, at least until it rams into you that is.

Keep up the good work, and I'll keep testing away.

Thanks
Kelly
denyasis
Hunter
Hunter
Posts: 75
Joined: Thu Mar 19, 2009 10:31 am

Re: Playing with the AI

Post by denyasis »

Thanks for the input!
Atm the moment all I have done is alter the Bomber events. In reality that only affects a few ships at the moment (I think like 5).
The koala, like most of the small freighters is calssified as a "shuttle", and in SVN, it loads the Default Events, which, I agree, doesn't fit at all. (It rams you beacuse its trying to get on your tail and shoot you, but has no guns and poor manuevurability - so splat).

Its on my todo list, no doubt. Just might take a little while. the defualt event set is used by almost everything, from shuttles, to missles, to turrets.
Ideally, I think I would want to break off the shuttle and troop groups from the Defualt events and create thier own for transports.

Let me know if you think of anything else like that too! I'll add it to my list of StuFF to try to work on! :-)

-----
Side note, I wonder if its possible to creat a new Combat role in teh Units.csv for unarmed craft? Hence They could have their own separate Event xml in the AI instructing them to flee. -YaY-

Would altering/adding a combat role break/change anything else that I am unaware of? devs?
ace123
Lead Network Developer
Lead Network Developer
Posts: 2560
Joined: Sun Jan 12, 2003 9:13 am
Location: Palo Alto CA
Contact:

Re: Playing with the AI

Post by ace123 »

I think you can go ahead and add a new role.
I don't recall seeing the list hardcoded into the engine and I can't find the term "bomber" anywhere in the source code (even case insensitive).

I am interested what you come up with. The AI is in need of an overhaul.
denyasis
Hunter
Hunter
Posts: 75
Joined: Thu Mar 19, 2009 10:31 am

Re: Playing with the AI

Post by denyasis »

Thanks for the blessing!
I'm no coder (Trying to think that abstractly seriously confuses me, sadly) , just hacking the xml files, its actually a lot of fun though. I just hope it is something you guys can use :) Any suggestions of what you would like to see are totally welcome!!

I'm about to go on vacation for several weeks, So durring that period, I think I'm gonna try and brainstorm a bit and try and lay out some plans on how I want to organize and do some of the xml's.

I'm kinda envisioning a noticable difference in the comabt behavior of Military/Civie units and unarmed units. It may be a little idealistic, but I'll try to see if I can come up with something useful you you all :-).

Also - SUGGESTIONS/COMMENTS about the AI's combat behavior = 1337 - really, I went there :-P

-----
Ace;
:D while I have your ear :twisted:
I'm really no coder, so forgive my lack of proper terminology - I noticed the XML's in the scripts folder use references found in the Vector.py file and in the mission bindings wiki you pointed me to earlier, like Add, sub and cross various vectors... Hence I can kinda figure out what they do and what is available to use (And I rediscover my hatred of math).

Is there something similar with the XML's in the Events folder? Specifically the condition that triggers a script (bshield,distance, threat), is there a list of those either in the source or Py files?

The Python mission binding page in teh wiki seems spot on (unit class section), but the names of the bindings are slightly different to the ones in teh xml (usually missing the word "data" or "get"). do I really just get rid of data/get?

For example, could I use "GetNumMounts" as "NumMounts" in the XML to determine if a ship is armed:
<NumMounts max=".9" script="Run Away I have no Guns AAAHHHH" .... you get idea...../>

If it is really that easy.....Awesome!

Peace!
ace123
Lead Network Developer
Lead Network Developer
Posts: 2560
Joined: Sun Jan 12, 2003 9:13 am
Location: Palo Alto CA
Contact:

Re: Playing with the AI

Post by ace123 »

Sadly I don't think the AI format is that flexable. You might have to use Python to get that sort of functionality. (you can write AI scripts in python but unfortunately they are a bit slower).

If you have a list of features you think might be useful for the AI, it should be possible to add them into the engine.
denyasis
Hunter
Hunter
Posts: 75
Joined: Thu Mar 19, 2009 10:31 am

Re: Playing with the AI

Post by denyasis »

ok, Thanks for the info! I didn't think it would be that easy, but it was worth a try :-P

I'll have to think a bit about what would be useful for the AI as I don't want to go overboard with suprfluous features. Hopefully, it may be something I can add myself so I don't have to bug you all too much, but looking at some of the source files and .py's, My head starts to hurt :oops:
denyasis
Hunter
Hunter
Posts: 75
Joined: Thu Mar 19, 2009 10:31 am

Re: Playing with the AI

Post by denyasis »

--Updated the patch on Page 1. The bomber should be a bit more aggressive and won't sit infront of the capship - ie infront of the main gun (i hope - its super experimental)

2 questions!

1) In vegastrike / trunk / vegastrike / src / cmd / ai / aggressive.cpp

"Threat" is identified as:

Code: Select all

  345   case THREAT:
  346     value = parent->GetComputerData().threatlevel;
  347     break;
Ok, so Threat is that value - Where does that value come from and what is it's range? I tried searching all over the SVN, but I must be looking in the wrong places... I'm assuming its a 0-1 percentage where the higher number means the AI feels more threatened?

2) Also later in the same file...

Code: Select all

440   case FARMOR_HEAL_RATE:
  441 	value = 0.0;
  442 	break;
  443   case BARMOR_HEAL_RATE:
  444 	value = 0.0;
  445 	break;
  446   case LARMOR_HEAL_RATE:
  447 	value = 0.0;
  448 	break;
  449   case RARMOR_HEAL_RATE:
  450 	value = 0.5;
  451 	break;
I thought armour doesn't heal at all, hence the zero's ecept for the Right Armor - it looks like 50%/sec ??

peace!
Kellyc
Insys Pilot
Insys Pilot
Posts: 2
Joined: Wed Apr 15, 2009 12:20 pm

Re: Playing with the AI

Post by Kellyc »

That armor thing probably is a mistake, last I read is that armor doesn't heal, can only be fixed inport.

I noticed that if you're speed is down (close to zero) the Koala's don't slam into you though I did suffer from
a Dodo impact (the ULN are after me now). Both types of ships still come after you though.
I do like your line of thought on getting the AI to run away.


Keep up the good work
Thanks much
Respectfully
Kelly
denyasis
Hunter
Hunter
Posts: 75
Joined: Thu Mar 19, 2009 10:31 am

Re: Playing with the AI

Post by denyasis »

Thanks friend!

I have the "run-away" event.xml mostly finished (in my head and on a scratch pad). I'm trying to brainston the best way to implement it. Right now dodo's, etc share the same combat role as say, the llama - which can fight. Hence they'll load the same Event file - and act the same.

What I've been thinking:
- Create a new Combat role "unarmed?"
- Edit the Units.CSV, identifying unarmed ships and changing thier combat role
- Create a new set of Unarmed type Event.xml's trying to get the AI to disengage from combat.
- Perhaps order the ship to drop cargo as it runs - (Seems to give pirates a reason to exist ;-P)

The only problems I see with that is:
-Units.csv is used for everything - so I don't want to step on any one's feet
-Even if the ship runs away - It might not spec away - that's handled in Source code

Now back to my vacation :-)
Mr. Bane
Merchant
Merchant
Posts: 35
Joined: Fri Feb 13, 2009 6:42 pm

Re: Playing with the AI

Post by Mr. Bane »

This would be a good reason why the ship organization I suggested is a good idea :D
denyasis
Hunter
Hunter
Posts: 75
Joined: Thu Mar 19, 2009 10:31 am

Re: Playing with the AI

Post by denyasis »

I'll have to find that thread!

It would be great if there were a newb friendly method of exporting the Units file into a GUI/visual format that is easier to handle.
Example that comes to mind is the X model veiwer for the X series - Only it would have to be editable, lol.

I actually think the biggest killer feature would be strong content creation tools - Especially with an FOSS project like this, getting shy members over that initial modding bump would go a long way :-)
loki1950
The Shepherd
Posts: 5841
Joined: Fri May 13, 2005 8:37 pm
Location: Ottawa
Contact:

Re: Playing with the AI

Post by loki1950 »

There is such a viewer but it is not finished and the guy that wrote it did not leave any source code around for others to pick up the pieces :( As for getting models in-game check pyramid's sig for UC it's a Python GUI for mesher and nvcompress and also has provisions for creating the new models units.csv entry it also will launch VS with a special model view mission so you get immediate feedback on whether all the textures a registered right but with pyramid reducing his involvement it will need a new maintainer/developer it uses Python's Tk widget set so it will have very few dependences making it much easier to support cross the various platforms we need to support.

Enjoy the Choice :)
my box::HP Envy i5-6400 @2Q70GHzx4 8 Gb ram/1 Tb(Win10 64)/3 Tb Mint 19.2/GTX745 4Gb acer S243HL K222HQL
Q8200/Asus P5QDLX/8 Gb ram/WD 2Tb 2-500 G HD/GF GT640 2Gb Mint 17.3 64 bit Win 10 32 bit acer and Lenovo ideapad 320-15ARB Win 10/Mint 19.2
Post Reply