AI Coding in General

AI Coding in General

Here is where ideas can be collected for the skirmish AI in development

Moderators: hoijui, Moderators

Post Reply
cab
Posts: 2
Joined: 27 Feb 2009, 13:49

AI Coding in General

Post by cab »

Hi


I am a TAspring fan but I also can program a few things in C , C++ and php perl (I am on linux of course)
And right now I am really interested in AIs but I really don't know where I should start
And I am just impressed by what you guys have done in Spring
like KAAIK and Rai (every time I play against these bots I lose)
So I would like to ask some advice, I won't program on Spring yet because it seems to difficult at the moment. And I am really desperate because there's nothing understandable when I google (of course I read all the tutorials in this site)

Here are a few questions :
-How did you manage to create bots which could plan?
-For example in Spring, how do you choose to build a few light laser tower to protect your base, how does your bot know that mexxes are a priority. My question is once everything is quantified (defense power, attack power, energy level, consumption): what do you do next?
-Another good example would be concerning ogamelike games
which are more simple than Spring, how would a bot behave to developp itself and defend itself correctly?

Thanks for you help
As you see I really AM a noob concerning AIs


Cab
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: AI Coding in General

Post by AF »

Our bots dont really 'plan' so much as follow sets of rules and algorithms we coded into them.

Early on things would go along the lines of, check fi we need energy, if so look at what makes the msot energy in our build menu and build it, otherwise do we need metal if so...etc etc etc

Other AIs such as my own and AIs such as SAI reverted to lists of things to build which evolved into lists of rules and things and so on

Eventually they got more complex and tried to say 'if well run out fo energy in 5 minutes build enegry' rather than ' if weve ran out of energy build energy', and so on.

AAI had defence placement routines where initially it built defences in a perimeter around its base. NTai had no cocnept of a base and randomly built them here there and everywhere when told to. KAI IIRC relied on a system to space defences out in critical places, and had an algorithm to detect chokepoints.

As for what to build, this again developed over time. Initially AIs hardcoded what t o build, a popular one is telling your first AI to build a solar collector hardcoded as a test. NTai relied on the user to tell it what to build, or what kinds of things to build. AAI relied on statistics on unit kill losses, and most AIs devised algorithms to determine a units efficiency at doing soemthing, or went the random path.

What to do next? Well many AIs seperated out attacking scouting and building initially. Over time they all came together slowly bit by bit. In AAI a units effectiveness in combat would change its statistics in the build tables reflecting what was built.

NTai for example had search algorithms that made scouters visit mex positions, and JCAI initially had an algorithm based on an influence map of what had been seen.

Naturally as things get built, attackers accumulate in your base, and are handled by attacking code. Most AIs amassed units in a group and atatcked when they reached a threshold. In NTai this was determined initially by the number of units then by the threat they generated comapred to the target. AAI used a similar ssytem iirc.

Both AAI and NTai relied on threat maps to figure out where to atatck. A grid of sectors representing the map was made each with a value. Enemy units would make the values rise, and the positions with the highest value were marked as targets, and attacked accordingly.

JCAI and OTAI followed a similar system, KAI on the other hand used a totally different system I am not very familiar with.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: AI Coding in General

Post by zwzsg »

If you are interested into AI coding, but feel a bit newbish, I suggest considering Lua based Spring AI. You might no have the raw power of C++, but they are incomparably easier to develop, and still get the job done.

Have a look at Kernel Panic Lua AI: It plays so well it sometimes beats me, it knows how to effectively use the KP special abilities (which a mod agnostic AI would have been unable to), yet all that was used to program it was Notepad++!

Granted, the AI job is simplified by how in Kernel Panic the only buildable spots are the geo. So the AI starts by listing all the geos. It keeps track on geos which are built upon by enemies, allies, or left free. When it has an idle cons, it tells it to build on the nearest free geo (with a bit of randomness thrown in to make it less predictable). When it has gathered a little group of attack units, it sends them to occupy free geo or attack enemy owned geos.

KDR_11k made some neat code where each geo is assigned a "weight", depending on the geo state (enemy covered, ally covered, or free (not counting mobile units), the distance to the homebase, and how many units are already assigned to it. Then units go the the geos with the highest weight. Each geo has a little list of all AI units assigned to it, and when units are told to move to another geo, those lists are updated. I don't fully understand how his equation works, but it basically results in units getting attacted by the front line border, first on the ally own side, then jumping to the enemy side of the border when enough units.

There is also some special code to handle special stuff, for instance:
  • The bug flip into exploit when there are enemy in exploit weapon range but not too close:
    • For every "bug", if there are enemy in a 1000 range, and the closest is furthest than 600, then flip into exploit
    • For every "exploit", if there are no enemy in a 1100 range, or if there are enemy in the 500 range then flip back into bug
  • Every time a AI unit is (significatively) damaged, its position is stored.
  • Periodically, firewall count the unit around the "last damage" position. If there are at least 7 allied in a 300 radius and at least 3 enemies in a 500 radius, then it casts.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: AI Coding in General

Post by Tobi »

You may also want to look at C.R.A.I.G., which is my in-development LUA AI for S44 (and soon SWIW!). The code's not too complex at this moment, but at the same time it does manage to beat even good players on hard.

(yes, it does cheat itself infinite resources :-))

http://github.com/tvo/craig/tree/master

The main feature is that it uses a waypoint profile which has to be made for each map to make it play a bit good on it. It uses this for capping flags and planning multiple attack routes into the enemies' base.

If you have any specific questions feel free to PM me on this forum or on the lobby. ([RoX]Tobi)
User avatar
1v0ry_k1ng
Posts: 4656
Joined: 10 Mar 2006, 10:24

Re: AI Coding in General

Post by 1v0ry_k1ng »

AF wrote: Both AAI and NTai relied on threat maps to figure out where to atatck. A grid of sectors representing the map was made each with a value. Enemy units would make the values rise, and the positions with the highest value were marked as targets, and attacked accordingly.
they would play so much better if they attacked the areas of low threat rather than homing in on any inpenetrable porc
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: AI Coding in General

Post by AF »

the algorithms got much more in depth than what I said but I thought my post was already far too long
User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

Re: AI Coding in General

Post by yuritch »

All of that means a 'general' AI would have less use with every new mod released (KP, S'44, SWIW, PURE and probably more) since every mod has its own tricks (lua or bos, doesn't matter much) which the AI must know how to use to be able to play it.
Or course some (rather large) parts of code could be similar between most mod-specific AIs.
1v0ry_k1ng wrote:they would play so much better if they attacked the areas of low threat rather than homing in on any inpenetrable porc
AAI sort of avoids that problem - the only way it gets threat values is by scouts, and scouts tend to die before entering a heavy porced area, so those strongpoints might end up not being attacked if the AI never gets to see them.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: AI Coding in General

Post by AF »

AAI and NTai tend not to attack posirtions whose power/threat is larger than the threat of the group its sending to attack, in order to avoid david v goliath scenarios
Post Reply

Return to “AI”