what is an example of a good but simple Lua AI?

what is an example of a good but simple Lua AI?

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

Moderators: hoijui, Moderators

yanom
Posts: 323
Joined: 10 Jul 2009, 23:34

what is an example of a good but simple Lua AI?

Post by yanom »

I've been trying to help the game Conflict Terra get good working Lua AI, but I need some example Lua AI's to study. I need some good ones (for whatever game) that are short in terms of how much code they contain.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: what is an example of a good but simple Lua AI?

Post by knorke »

There are not many released Lua AIs.
You already know the ones in CT, there also is:

-the one in zero-K (named CAI?)
(also has a skirmish widget AI that helps with microing your units)

-C.R.A.I.G. in Spring S44

-the one in Kernel Panic

-Borked Advancer in Spring Tanks :roll:

If you do not count chicken variants, thats it I think.
yanom
Posts: 323
Joined: 10 Jul 2009, 23:34

Re: what is an example of a good but simple Lua AI?

Post by yanom »

I'll maybe take a look at the one in Kernel Panic. But man, LuaAI is hard.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: what is an example of a good but simple Lua AI?

Post by zwzsg »

If you can, take an an old one. The new ones have all sort of weird quirk added.
Google_Frog
Moderator
Posts: 2464
Joined: 12 Oct 2007, 09:24

Re: what is an example of a good but simple Lua AI?

Post by Google_Frog »

Kernel Panic AI is the one I looked at to get started and it is reasonably simple, although I looked at it from knowing how to write gadgets and I really just wanted to see the syntax for the bits that make a gadget an AI.

If you want to look at CAI I could go through how it works.
yanom
Posts: 323
Joined: 10 Jul 2009, 23:34

Re: what is an example of a good but simple Lua AI?

Post by yanom »

mmm. well what I'm after here is the bits that control unit production, deciding what unit to build when, and building it. This has been a hard project, though, because it's the first Spring Gadget I've worked with. I appreciate your help.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: what is an example of a good but simple Lua AI?

Post by AF »

You can refer to Shard for structure and logic, although keep in midn that Shard doesn't use the Spring Gadget APIs so you would substitute the Shard API calls for Spring engine API calls
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: what is an example of a good but simple Lua AI?

Post by zwzsg »

yanom wrote:mmm. well what I'm after here is the bits that control unit production, deciding what unit to build when, and building it.
Dice rolls.
Google_Frog
Moderator
Posts: 2464
Joined: 12 Oct 2007, 09:24

Re: what is an example of a good but simple Lua AI?

Post by Google_Frog »

yanom wrote:mmm. well what I'm after here is the bits that control unit production, deciding what unit to build when, and building it. This has been a hard project, though, because it's the first Spring Gadget I've worked with. I appreciate your help.
There isn't anything this high level hardcoded for lua AI. You decide how you want it to decide what to build and must implement it by giving commands to units with your gadget.

CAI is a slighty more advanced than zwzsg's, it uses weighted dice rolls :wink: .
yanom
Posts: 323
Joined: 10 Jul 2009, 23:34

Re: what is an example of a good but simple Lua AI?

Post by yanom »

ok. Knorke's Schwarm used a hardcoded build script.
User avatar
oksnoop2
Posts: 1207
Joined: 29 Aug 2009, 20:12

Re: what is an example of a good but simple Lua AI?

Post by oksnoop2 »

AF frowned when I showed him how I set up shard's build que, but it's simple enough that it made sense to me :-) . Uhm basically it was just a random selection organized by cost. Cheaper things showed up more on the list than expensive things.

http://code.google.com/p/conflictterra/ ... queues.lua
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: what is an example of a good but simple Lua AI?

Post by knorke »

use
elseif r > 3 then ...
instead of the endless
if r == 4
if r == 5
if == 6
...

---general blabla incoming---

Kernel Panic is relatively easy for AI because it is easy to play.
Not easy to be good at but be decent at and "generally avoid total failure:"
In the sockets (factories) you can only make one type of unit, so obviously you spam this.
In your mainbuilding you have some special units but which one of them you make is not that criticial. There is no way to end up with a bunch of "useless" units like making only AA bots in *A mods.
Also no resources means the AI does not need to worry about stalling. Just make a constructor from time to time, send it to free geovents and thats it.
Apart from walls (no really needed) that is also the only base building you need to worry about, compare to *A where base building and building placement (turrets) is very important.
For the military side, just give a fight command for all units to nearest enemy socket.

Of course later on you might want more strategy, retreating units etc but for the start I find it helpful if you think what is the dumbest possible way to play this game.
ie for Spring Tanks:
1) select all your units and send them to the nearest enemy flag.
2) If you manage to pick up a flag, return to base.
Those 2 rules alone allow you/an AI to play the game.
Now add something like
3) if a unit is too far away from allies, go to the nearest ally
and units will try to stick together, like they want to attack in a team or something.
That is all ST's AI does for now.
If there was something to
4) avoid enemies
it would be pretty good I guess.


For CT drones faction
, there are not that many options either when it comes to unit building.
1) at start, you get one engineer.
Now you can either
a) morph to a mining tower b) clone him c) make a factory
-> a) makes no sense if it is your only/first unit [and you have resources]
b) & c) are kind of similiar

2) engineers that have nothing to do should basically always morph to mining towers to get resources.

3) only two factories: ground & air. It does not matter that much which unit you make, basically any type will do. (apart from shields, if you spam only those its useless)

again, dumbest posssible way to play.
for example building placement for CT drones:
mining towers: obviously near resource rocks.
If you deploy at the nearest rocks, at rocks not occupied by the enemy or at rocks on high ground does not matter for start.
Later you might want not to suicide engineers into the enemy base but to get it working, it does not matter that much.
Same for factories: does not really matter where you put them.
Pro points if you hide them from enemy but for start it is more important that you have some factories instead of where they are.

Also see:
I found the ultimate build queue!

Weapon v unit bonus
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: what is an example of a good but simple Lua AI?

Post by AF »

oksnoop2 wrote:AF frowned when I showed him how I set up shard's build que, but it's simple enough that it made sense to me :-) . Uhm basically it was just a random selection organized by cost. Cheaper things showed up more on the list than expensive things.

http://code.google.com/p/conflictterra/ ... queues.lua

You had based it on an earlier version of the file which had inferior syntax, I changed that file later to have easier to understand syntax
yanom
Posts: 323
Joined: 10 Jul 2009, 23:34

Re: what is an example of a good but simple Lua AI?

Post by yanom »

oh, AF, is it possible to add custom Lua code to Shard? because if we added Knorke's economy code and the existing CT config for shard together, we could maybe get shard to work for CT.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: what is an example of a good but simple Lua AI?

Post by AF »

Shard code is lua yes, but there is no spring gadgets API in the current version, and my own code to export the gadget API isn't reliable ( and would be slow if it worked perfectly anyway ).

I've already detailed how to implement miners, all that's left is morphing
yanom
Posts: 323
Joined: 10 Jul 2009, 23:34

Re: what is an example of a good but simple Lua AI?

Post by yanom »

knorke wrote: 2) engineers that have nothing to do should basically always morph to mining towers to get resources.
Having ALOT of trouble with this.
AF wrote: I've already detailed how to implement miners, all that's left is morphing
You have? cause Knorke has code for the morphing.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: what is an example of a good but simple Lua AI?

Post by knorke »

giving a morph order works like:
Spring.GiveOrderToUnit(unitID, 31210,{UnitDefNames["kdroneminingtower"].id},{"shift"})

this number is defined in the morph gadget. if it gets changed in gadget, it must be changed in AI too.
what unit to morph to.

I dont kow how that looks like in Shard Lua or what else is needed (morph gadget is the one from zerok)
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: what is an example of a good but simple Lua AI?

Post by hoijui »

maybe constants like this number should be defined in a Lua file that is then included in all other files where it is used.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: what is an example of a good but simple Lua AI?

Post by knorke »

definitely.
Actually I think I once saw such file in zk?
Not sure if it was just a hand-written "note" or real config though.
Also not sure if Shard could read it?
yanom
Posts: 323
Joined: 10 Jul 2009, 23:34

Re: what is an example of a good but simple Lua AI?

Post by yanom »

knorke wrote:giving a morph order works like:
Spring.GiveOrderToUnit(unitID, 31210,{UnitDefNames["kdroneminingtower"].id},{"shift"})
I know how to make engineers morph, but I don't know how to figure out when they aren't needed and then make them go mine. SendOutIdleEngineers() doesn't work.


But more importantly, is it possible to make Shard work with CT? How so? is adding mining all that's needed?
Post Reply

Return to “AI”