what is an example of a good but simple Lua AI?
Moderators: hoijui, Moderators
what is an example of a good but simple Lua AI?
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.
Re: what is an example of a good but simple Lua AI?
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
If you do not count chicken variants, thats it I think.
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

If you do not count chicken variants, thats it I think.
Re: what is an example of a good but simple Lua AI?
I'll maybe take a look at the one in Kernel Panic. But man, LuaAI is hard.
Re: what is an example of a good but simple Lua AI?
If you can, take an an old one. The new ones have all sort of weird quirk added.
-
- Moderator
- Posts: 2464
- Joined: 12 Oct 2007, 09:24
Re: what is an example of a good but simple Lua AI?
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.
If you want to look at CAI I could go through how it works.
Re: what is an example of a good but simple Lua AI?
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.
Re: what is an example of a good but simple Lua AI?
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
Re: what is an example of a good but simple Lua AI?
Dice rolls.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.
-
- Moderator
- Posts: 2464
- Joined: 12 Oct 2007, 09:24
Re: what is an example of a good but simple Lua AI?
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.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.
CAI is a slighty more advanced than zwzsg's, it uses weighted dice rolls

Re: what is an example of a good but simple Lua AI?
ok. Knorke's Schwarm used a hardcoded build script.
Re: what is an example of a good but simple Lua AI?
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

http://code.google.com/p/conflictterra/ ... queues.lua
Re: what is an example of a good but simple Lua AI?
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
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
Re: what is an example of a good but simple Lua AI?
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
Re: what is an example of a good but simple Lua AI?
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.
Re: what is an example of a good but simple Lua AI?
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
I've already detailed how to implement miners, all that's left is morphing
Re: what is an example of a good but simple Lua AI?
Having ALOT of trouble with this.knorke wrote: 2) engineers that have nothing to do should basically always morph to mining towers to get resources.
You have? cause Knorke has code for the morphing.AF wrote: I've already detailed how to implement miners, all that's left is morphing
Re: what is an example of a good but simple Lua AI?
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)
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)
Re: what is an example of a good but simple Lua AI?
maybe constants like this number should be defined in a Lua file that is then included in all other files where it is used.
Re: what is an example of a good but simple Lua AI?
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?
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?
Re: what is an example of a good but simple Lua AI?
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.knorke wrote:giving a morph order works like:
Spring.GiveOrderToUnit(unitID, 31210,{UnitDefNames["kdroneminingtower"].id},{"shift"})
But more importantly, is it possible to make Shard work with CT? How so? is adding mining all that's needed?