MetalHeck BA Tourney for Lua AIs

MetalHeck BA Tourney for Lua AIs

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

MetalHeck BA Tourney for Lua AIs

Post 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:
Last edited by knorke on 24 Jun 2014, 14:30, edited 1 time in total.
User avatar
Silentwings
Posts: 3720
Joined: 25 Oct 2008, 00:23

Re: MetalHeck BA Tourney for Lua AIs

Post 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.
User avatar
Petah
Posts: 426
Joined: 13 Jan 2008, 19:40

Re: MetalHeck BA Tourney for Lua AIs

Post 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
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: MetalHeck BA Tourney for Lua AIs

Post by CarRepairer »

Silentwings wrote:I don't know why some got [" "] and some didnt
It's applied when it's needed.
User avatar
Silentwings
Posts: 3720
Joined: 25 Oct 2008, 00:23

Re: MetalHeck BA Tourney for Lua AIs

Post 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 :)
User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10450
Joined: 24 Jan 2006, 21:12

Re: MetalHeck BA Tourney for Lua AIs

Post by PicassoCT »

Is there a template?
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: MetalHeck BA Tourney for Lua AIs

Post 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 ;)
Last edited by knorke on 02 Jul 2014, 13:54, edited 1 time in total.
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Re: MetalHeck BA Tourney for Lua AIs

Post by Jools »

When is this tourney held?
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: MetalHeck BA Tourney for Lua AIs

Post by CarRepairer »

Silentwings wrote:And when is it needed?
When the table key is not alphanumeric. It would be syntactically wrong otherwise.
User avatar
code_man
Posts: 260
Joined: 19 Jan 2014, 13:10

Re: MetalHeck BA Tourney for Lua AIs

Post by code_man »

I hope il find the time to make it in.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: MetalHeck BA Tourney for Lua AIs

Post 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 (?)
User avatar
code_man
Posts: 260
Joined: 19 Jan 2014, 13:10

Re: MetalHeck BA Tourney for Lua AIs

Post 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.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: MetalHeck BA Tourney for Lua AIs

Post 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.
User avatar
code_man
Posts: 260
Joined: 19 Jan 2014, 13:10

Re: MetalHeck BA Tourney for Lua AIs

Post 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.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: MetalHeck BA Tourney for Lua AIs

Post by knorke »

ah :)
t in the loop is already the teamID, spelling mistake, both variables should have same name.
Post Reply

Return to “Lua Scripts”