Page 1 of 1

MetalHeck BA Tourney for Lua AIs

Posted: 24 Jun 2014, 00:08
by knorke
The amazing AI tourney.

Why:
-To find out if this http://springrts.com/phpbb/viewtopic.ph ... 41#p559241 is working way to manage multiple Lua-AIs that do not want to go into gamebox
-Its fun, make one gadget and let it fight.
-AI competion!!

How Pro:
Not very pro AI required.
It is more for fun. For example a primitive AI that does but build an airlab and combombs is acceptable.

How:
Rules are as simple as possible to have low entry barrier.
For example the map does not require thinking about "where to place mexes", because that is no fun.

1) Game Setup like this:

Image
2) This map: http://springfiles.com/spring/spring-maps/metalheckv2
3) The map has two startposition at bottom and top. The AIs will be placed by hand on them.
The other startpositions will be ignored.
3b) You can decide if your AI should play ARM or CORE, it will be set accordingly.
4) Mod is BA 8.0 - http://springrts.com/phpbb/viewtopic.php?f=44&t=32244
5) engine is 96.0
6) To make it easier, no newer versions of map/engine/mod will be used, even if something is released.
7) Make your Lua-AI and pack it like in the example. If something needs slight adjustment (like LuaAI.info) I will try to make it work and copypaste everything together so AIs can play VS each other.

Cheating:
9) Only do things that human players can do, who play with full LOS.
That means for example...
...Only controlling units of your team!
...No Spring.UnitCreate or other sillyness
10) Using globallos to get position of enemy units etc is okay, to make it easier.
11) If it crashes or lags, it is out.

Example entry:
Nooby Metalheckler version 1 in this post:
http://springrts.com/phpbb/viewtopic.ph ... 60#p559172
DO NOT USE THIS AS EXAMPLE FOR ACTUAL AI LOGIC.
THERE ARE BETTER THINGS FROM WHICH TO LEARN


AIs should have version number in both the getInfo() and file name!
Meaningful filename please, eg "AI_Combomber_v1.sdz"


"Old AIs" such as RAI, KAI, NullAI are not permitted because it would be boring if they always win.
I thought about solving that by using a more original game but then figured "Everybody knows BA, it has all the basic elements of an RTS, why not just BA."


Resources:
How to Lua-AI:
http://springrts.com/wiki/AI:Development:Lang:Lua
Ask if more questions.

BA unit names:
To look up the internal names, like ARM Peewee = "armpw"
http://pastebin.com/aknpV5xR (by Silentwings)

It's on as soon there are two entries. :shock:

Re: MetalHeck BA Tourney for Lua AIs

Posted: 24 Jun 2014, 00:16
by Silentwings
Here's a table of BA humanNames -> names http://pastebin.com/aknpV5xR

I don't know why some got [" "] and some didnt - something wierd in luas table.save.

Re: MetalHeck BA Tourney for Lua AIs

Posted: 24 Jun 2014, 05:21
by Petah
I will enter my does nothing AI (as soon as I bring it up to date with the latest versions):

https://github.com/Petah/bai-lua

Re: MetalHeck BA Tourney for Lua AIs

Posted: 24 Jun 2014, 05:31
by CarRepairer
Silentwings wrote:I don't know why some got [" "] and some didnt
It's applied when it's needed.

Re: MetalHeck BA Tourney for Lua AIs

Posted: 24 Jun 2014, 08:40
by Silentwings
And when is it needed? (All the table keys and values had been through tostring() )

I will try and write an entry, time permitting :)

Re: MetalHeck BA Tourney for Lua AIs

Posted: 24 Jun 2014, 09:29
by PicassoCT
Is there a template?

Re: MetalHeck BA Tourney for Lua AIs

Posted: 24 Jun 2014, 14:29
by knorke
PicassoCT wrote:Is there a template?
Maybe this:
http://springrts.com/wiki/AI:Developmen ... _AI_Gadget

The important part is to find out which team the AI is assigned to.
Spring.GetTeamLuaAI returns the LuaAI-name that lobby as assigned to a team:
So compare that name to the name of your AI and see if they match.
Good idea is imo to put the AI-name in the getInfo() part head of gadget, then read it with stringgadget:GetInfo().name

Code: Select all

for _,t in ipairs(Spring.GetTeamList()) do
 local teamID, leader, isDead, isAI, side = Spring.GetTeamInfo(teamID)
 if Spring.GetTeamLuaAI(teamID) == gadget:GetInfo().name then
...this is my teamID...save it...
In 1v1 games your AI will only play for one team, so can just save your teamID in single variable.

For example when you want to give orders to newly built units:

Code: Select all

gadget:UnitFinished(unitID, unitDefID, unitTeam) 
if unitTeam ~= myAIteamID then return end --this is not one of our units: ignore it!
Spring.GiveOrderToUnit (unitID, ... ...)
It is important to watch your teamID, otherwise you could accidently give commands to enemy units ;)
That would be mean!
Image

If the AI is supposed to controll multiple teams then it gets bit more confusing, but can care about at later stage. Here is something about that: http://springrts.com/phpbb/viewtopic.ph ... 02#p533696

Petah:
ok cool. Noticed all your echos begin with name of your AI like
Spring.Echo("BAI: "..spaces .."(metatable) ")
Think that is good idea.:) If all AI just spam random debug stuff it might be hard to see where it is coming from. No forced rule but recommended ;)

Re: MetalHeck BA Tourney for Lua AIs

Posted: 24 Jun 2014, 14:35
by Jools
When is this tourney held?

Re: MetalHeck BA Tourney for Lua AIs

Posted: 24 Jun 2014, 17:18
by CarRepairer
Silentwings wrote:And when is it needed?
When the table key is not alphanumeric. It would be syntactically wrong otherwise.

Re: MetalHeck BA Tourney for Lua AIs

Posted: 01 Jul 2014, 14:52
by code_man
I hope il find the time to make it in.

Re: MetalHeck BA Tourney for Lua AIs

Posted: 02 Jul 2014, 14:00
by knorke
Jools wrote:When is this tourney held?
As soon as there is a second entry ;)
Then I will make a test-match against my "Nooby Metalheckler" example entry.
Think there is no use to put strict deadlines but maybe we should aim for the next few weeks or so.
Interessted so far: Petah, code_man, knorke, PicassoCT (?)

Re: MetalHeck BA Tourney for Lua AIs

Posted: 09 Jul 2014, 19:35
by code_man
knorke wrote:
PicassoCT wrote:Is there a template?
Maybe this:

The important part is to find out which team the AI is assigned to.
Spring.GetTeamLuaAI returns the LuaAI-name that lobby as assigned to a team:
So compare that name to the name of your AI and see if they match.
Good idea is imo to put the AI-name in the getInfo() part head of gadget, then read it with stringgadget:GetInfo().name

Code: Select all

for _,t in ipairs(Spring.GetTeamList()) do
 local teamID, leader, isDead, isAI, side = Spring.GetTeamInfo(teamID)
 if Spring.GetTeamLuaAI(teamID) == gadget:GetInfo().name then
...this is my teamID...save it...
There is an error in taht code.
Here il post and improved version.

Code: Select all

function gadget:Initialize() 
    for _,t in ipairs(Spring.GetTeamList()) do
        local teamID, leader, isDead, isAI, side = Spring.GetTeamInfo(t)
        if isAI and Spring.GetTeamLuaAI(teamID) == gadget:GetInfo().name then
            ai_id = teamID -- <-- This is my team ID, there are many team IDs but this one is mine
        end
    end
end
I might also post an empty template later on, to spare people some callin copypasting.

Re: MetalHeck BA Tourney for Lua AIs

Posted: 09 Jul 2014, 22:00
by knorke
code_man: What error do you mean?
It looks basically the same to me but maybe I miss something.
The newly added isAI:
if isAI and Spring.GetTeamLuaAI(teamID) == gadget:GetInfo().name
is not needed I think because if this teamID is not controlled by a LuaAI then GetTeamLuaAI() just returns "" (empty string) so the next condition would never be true anyway.

Re: MetalHeck BA Tourney for Lua AIs

Posted: 09 Jul 2014, 22:19
by code_man
knorke wrote:

Code: Select all

for _,t in ipairs(Spring.GetTeamList()) do
 local teamID, leader, isDead, isAI, side = Spring.GetTeamInfo(teamID)
 if Spring.GetTeamLuaAI(teamID) == gadget:GetInfo().name then
...this is my teamID...save it...
local teamID, leader, isDead, isAI, side = Spring.GetTeamInfo(teamID)
teamID referenced before defined.

And im not sure if the IsAI is needed, but i think its probably safer.

Re: MetalHeck BA Tourney for Lua AIs

Posted: 10 Jul 2014, 01:28
by knorke
ah :)
t in the loop is already the teamID, spelling mistake, both variables should have same name.