ta3d AI

Everything related to the code /
Tout ce qui touche au code
Post Reply
xpoy
Posts: 669
Joined: Mon Sep 22, 2008 3:55 am

ta3d AI

Post by xpoy » Thu Apr 23, 2009 2:06 pm

:D
I back.
Tell me what need to do.

User avatar
zuzuf
Administrateur - Site Admin
Posts: 3281
Joined: Mon Oct 30, 2006 8:49 pm
Location: Toulouse, France
Contact:

Post by zuzuf » Thu Apr 23, 2009 4:22 pm

hm, you could start by telling us what you need to develop a good AI :D

For now AI can be scripted but there are very few possibilities because the current Lua AI API doesn't interact much with the engine ... currently I don't really know what would be useful in such an API.
=>;-D Penguin Powered

hirsoft
Posts: 75
Joined: Tue Sep 23, 2008 8:33 am

Re: ta3d AI

Post by hirsoft » Fri Apr 24, 2009 6:45 am

I think AI just need be devlop qucikly.

xpoy
Posts: 669
Joined: Mon Sep 22, 2008 3:55 am

Re: ta3d AI

Post by xpoy » Fri Apr 24, 2009 6:57 am

AI will crazy push and grow more crazy. :D

I think AI need those API:
Got the units Num in some section that belong someone.
Got the units Properties,for example, CON(Factory should belong CON)/build what(build/units)/SHIP/AIR/WEAPON/LAND/COMMDER/MadeTime/Cost/health/Climbing ability/Draft degrees/Attack from
Order the units Num in some section that belong self.
Got the Surface Properties,for example:Metal production/Gradient(lava Gradient=255,lol)/Water Depth

milipili
Posts: 545
Joined: Thu Nov 02, 2006 8:52 am
Location: Paris (France)
Contact:

Re: ta3d AI

Post by milipili » Sat Apr 25, 2009 7:51 pm

A Quadtree may be useful too. But I don't know what kind of algo you want to implement.
Damien Gerard
Ta3d & Yuni Developer

User avatar
zuzuf
Administrateur - Site Admin
Posts: 3281
Joined: Mon Oct 30, 2006 8:49 pm
Location: Toulouse, France
Contact:

Re: ta3d AI

Post by zuzuf » Sat Apr 25, 2009 8:41 pm

I also planned to implement some algorithms used in computer vision (this is my field :p) like k-means (which could be used to get the number and the position of enemy/ally bases), as well as a few things related to machine learning (like neural networks, TA3D already has the classes for that).
=>;-D Penguin Powered

xpoy
Posts: 669
Joined: Mon Sep 22, 2008 3:55 am

Re: ta3d AI

Post by xpoy » Sun Apr 26, 2009 8:16 am

:D
I just want made some routine that useful in fight.For example,build defence based on metal and surface access.

User avatar
zuzuf
Administrateur - Site Admin
Posts: 3281
Joined: Mon Oct 30, 2006 8:49 pm
Location: Toulouse, France
Contact:

Re: ta3d AI

Post by zuzuf » Fri May 01, 2009 6:20 pm

Ok, I've added several functions that should fill most of your needs, except there is no map related function yet (you can get information about units, their type, build list, name (for debugging it may help), etc ...).
Have a look at lua_prototypes in SVN and tell us what is missing.
=>;-D Penguin Powered

xpoy
Posts: 669
Joined: Mon Sep 22, 2008 3:55 am

Re: ta3d AI

Post by xpoy » Fri May 01, 2009 6:35 pm

A group API,that group some units for order. :)
And a API that return weather Units group is Ok to pass some ground.
And that Metal surface....

User avatar
zuzuf
Administrateur - Site Admin
Posts: 3281
Joined: Mon Oct 30, 2006 8:49 pm
Location: Toulouse, France
Contact:

Re: ta3d AI

Post by zuzuf » Fri May 01, 2009 7:07 pm

grouping should be implemented in Lua because it involves reading an array which is not really fast from C code. Maybe you could write some interface functions in Lua that would call C functions for all units in an array, naming them like:

Code: Select all

add_attack_mission_group( array_of_unit_index, ... normal parameters)
=>;-D Penguin Powered

xpoy
Posts: 669
Joined: Mon Sep 22, 2008 3:55 am

Re: ta3d AI

Post by xpoy » Sat May 02, 2009 6:12 am

Ok,i will write some LUO lib for devlop.

xpoy
Posts: 669
Joined: Mon Sep 22, 2008 3:55 am

Re: ta3d AI

Post by xpoy » Wed May 06, 2009 8:10 am

Code: Select all

NewGroup
GroupAdd
GroupOrder
GroupExist

function NewGroup (GroupID)
 GroupID.Num= 0
 GroupID.invalid= 0
 return GroupID
end

function GroupAdd (GroupID, UnitID)
 if GroupID.invalid= 0
    then
      GroupID["Unit" .. GroupID.Num]= UnitID
      GroupID.Num= GroupID.Num+ 1
    else
      GroupAdd (NewGroup (GroupID), UnitID)
 end
 return GroupID
end

function GroupMove (GroupID, pos_x, pos_z)
 for (i=0; i< GroupID.Num; i= i+ 1)
  add_move_mission ( GroupID["Unit" .. i], pos_x, pos_z )
 end
end

function GroupAttack (GroupID, target_id)
 for (i=0; i< GroupID.Num; i= i+ 1)
  add_attack_mission ( GroupID["Unit" .. i], target_id )
 end
end

function GroupGuard (GroupID, target_id)
 for (i=0; i< GroupID.Num; i= i+ 1)
  add_guard_mission ( GroupID["Unit" .. i], target_id )
 end
end

function GroupPartrol (GroupID, pos_x, pos_z)
 for (i=0; i< GroupID.Num; i= i+ 1)
  add_patrol_mission( GroupID["Unit" .. i], pos_x, pos_z )
 end
end

function GroupExist (GroupID)
 if GroupID.invalid= 0 then
 for (i=0; i< GroupID.Num; i= i+ 1)
   if has_unit( Me, GroupID["Unit" .. i])==false
     local tmp= i+ 1
     GroupID["Unit" .. i]= GroupID["Unit" .. tmp] 
     GroupID["Unit" .. tmp]= nil
   end
 end
 return ture
 end
 return false
end
When I start write a moment,there are a blabla problem,I don't know what' time ta3d will call lua.
I think there maybe series of groupAPI can be call, thus it will eazy to Control units

User avatar
zuzuf
Administrateur - Site Admin
Posts: 3281
Joined: Mon Oct 30, 2006 8:49 pm
Location: Toulouse, France
Contact:

Re: ta3d AI

Post by zuzuf » Wed May 06, 2009 6:41 pm

In Lua functions do not need to be declared like in C/C++, so your first 4 lines raise an error.

For loops are constructed like this: for var = start, end[, step do] ... end
since tables are a mix of arrays and hash tables, it's better to use the array when possible (which starts at 1 not 0 ...)

I rewrote your code in a way that should not raise errors:

Code: Select all

function NewGroup ()
    local GroupID = {Num = 0,               -- starts with 0 units in the group
                    Add = GroupAdd,         -- allows object like calling convention: group:Add(myUnitID)
                    Move = GroupMove,
                    Attack = GroupAttack,
                    Guard = GroupGuard,
                    Patrol = GroupPatrol,
                    Exist = GroupExist};
    return GroupID
end

function GroupAdd (GroupID, UnitID)
    if GroupID ~= nil
        then
          GroupID.Num = GroupID.Num + 1
          GroupID[GroupID.Num] = UnitID
        else
          GroupID = GroupAdd (NewGroup (), UnitID)
    end
    return GroupID
end

function GroupMove (GroupID, pos_x, pos_z)
    for i = 1, GroupID.Num do
      add_move_mission ( GroupID[i], pos_x, pos_z )
    end
end

function GroupAttack (GroupID, target_id)
    for i = 1, GroupID.Num do
      add_attack_mission ( GroupID[i], target_id )
    end
end

function GroupGuard (GroupID, target_id)
    for i = 1, GroupID.Num do
      add_guard_mission ( GroupID[i], target_id )
    end
end

function GroupPartrol (GroupID, pos_x, pos_z)
    for i = 1, GroupID.Num do
      add_patrol_mission( GroupID[i], pos_x, pos_z )
    end
end

function GroupExist (GroupID)
    if GroupID ~= nil then
        for i = 1, GroupID.Num do
           if not has_unit( Me, GroupID[i]) then
             local tmp = i + 1
             GroupID[i] = GroupID[tmp]
             GroupID[tmp] = nil
             i = i - 1
           end
        end
        return true
    end
    return false
end
then you can do:

Code: Select all

group = NewGroup()
group:Add(1)
GroupAdd(group, 2)
You can also create a generic function, then create functions that will call it with a parameter

Code: Select all

function GroupCall (GroupID, F, ...)
    for i = 1, GroupID.Num do
      F ( GroupID[i], ... )
    end
end

GroupMove = function (GroupID, ...) GroupCall (GroupID, add_move_mission, ...) end
AI scripts will be started by the thread that monitors players (the last thread to be started), so it'll start in game (not at loading time).

I hope it helps :)
=>;-D Penguin Powered

xpoy
Posts: 669
Joined: Mon Sep 22, 2008 3:55 am

Re: ta3d AI

Post by xpoy » Wed May 06, 2009 7:50 pm

There a big problem,when the units dead or lose by other ways,how to got this and delete this UnitID form GroupID.

User avatar
zuzuf
Administrateur - Site Admin
Posts: 3281
Joined: Mon Oct 30, 2006 8:49 pm
Location: Toulouse, France
Contact:

Re: ta3d AI

Post by zuzuf » Wed May 06, 2009 8:53 pm

Units have an ID which identifies them in the engine data structures and a UUID (Unique Unit ID) which identifies a unit for the whole game as opposed to ID which is a slot in an array (if the unit dies it can be replaced which is confusing ... but the new unit will have a higher UUID).

You can use get_unit_data (which returns a table when the unit exists), it'll return nil if the unit doesn't exist, and the UUID will be different if the unit has changed.
=>;-D Penguin Powered

xpoy
Posts: 669
Joined: Mon Sep 22, 2008 3:55 am

Re: ta3d AI

Post by xpoy » Wed May 06, 2009 8:59 pm

Units have an ID which identifies them in the engine data structures and a UUID (Unique Unit ID) which identifies a unit for the whole game as opposed to ID which is a slot in an array (if the unit dies it can be replaced which is confusing ... but the new unit will have a higher UUID).
It's cool!
Nice set,i think it made AI libs more eazy!
How about Build?Will unit auto put metal Collector on above metal?The AI must build defence in the light of metals.

User avatar
zuzuf
Administrateur - Site Admin
Posts: 3281
Joined: Mon Oct 30, 2006 8:49 pm
Location: Toulouse, France
Contact:

Re: ta3d AI

Post by zuzuf » Wed May 06, 2009 9:50 pm

In the C API there is a function that finds the best place for buildings, with some specific code for metal extractors. I'll add a similar one in the Lua API.
=>;-D Penguin Powered

xpoy
Posts: 669
Joined: Mon Sep 22, 2008 3:55 am

Re: ta3d AI

Post by xpoy » Sun May 10, 2009 4:03 am

Keep wait,when it finshed there will be a test AI, :P

xpoy
Posts: 669
Joined: Mon Sep 22, 2008 3:55 am

Re: ta3d AI

Post by xpoy » Sun May 17, 2009 11:37 am

There's a reason there are fruit
What's the time that TA3D call AI?
Just work as a thread?Or some matter made TA3D returen AI.

And some API are needed:
Section units enum,got a list,then be able to got how many enemy and the num of owner.Better the API be able to selecet spec type into list. Look like:

Code: Select all

section = 
{
   nw_x= 0;
   nw_y= 0;
   se_x= 0;
   se_y= 0;
}
SecUnits (localplayer (), CORCA, section)
Got the player's energy and metal income/expand
Got one unit goto a pos through the length.
And i added a item to UnitID, UnitID.Group,will that work when I check the unitID's Group?

Code: Select all

function GroupAdd (GroupID, UnitID)
    if GroupID ~= nil
        then
          GroupID.Num = GroupID.Num + 1
          GroupID[GroupID.Num] = UnitID
          UnitID.Group = GroupID --xp addtion
        else
          GroupID = GroupAdd (NewGroup (), UnitID)
    end
    return GroupID
end
I don't know what's the x/y mean.Like x/y isn't pixel,do the x/y mean the waraframe?
Thus i just need addbuild to intent waraframe,Had i got it?
And i'm write a set of Got SPEC BUILD: veh/kbot/air ,adv veh/kbot/air, most suitable Energy maker/metal maker.Use the (HP*2+ DPS)/(energy/60+ metal+ time/10) to seek Best unit,every List should had own The best choice.


Something temporarily can not remember.Will added.

User avatar
zuzuf
Administrateur - Site Admin
Posts: 3281
Joined: Mon Oct 30, 2006 8:49 pm
Location: Toulouse, France
Contact:

Re: ta3d AI

Post by zuzuf » Sun May 17, 2009 12:30 pm

Yes, AIs run as separate threads.
You can add everything you want in a UnitID table, but beware that it won't change the way C API will behave : it'll still create the same kind of UnitID tables, so be careful because it might overwrite some needed information.
I'll add the required functions to the API when I have time.
=>;-D Penguin Powered

xpoy
Posts: 669
Joined: Mon Sep 22, 2008 3:55 am

Re: ta3d AI

Post by xpoy » Sun May 17, 2009 3:16 pm

:D
I just made a mark in the missing API.So it's np.
I think separate threads mean AI couldn't got thing without driving call.
There are a series of "Prototypes for global environment manipulation",what AI can do by that?

User avatar
zuzuf
Administrateur - Site Admin
Posts: 3281
Joined: Mon Oct 30, 2006 8:49 pm
Location: Toulouse, France
Contact:

Re: ta3d AI

Post by zuzuf » Sun May 17, 2009 7:07 pm

AIs could share information for example, coordinate their attacks, etc ... or they could be given some instructions by scenario scripts since all Lua scripts can access the global environment
=>;-D Penguin Powered

xpoy
Posts: 669
Joined: Mon Sep 22, 2008 3:55 am

Re: ta3d AI

Post by xpoy » Mon May 18, 2009 7:33 pm

share information by global environment manipulation?
Does set a missing global environment mean create new one?

User avatar
zuzuf
Administrateur - Site Admin
Posts: 3281
Joined: Mon Oct 30, 2006 8:49 pm
Location: Toulouse, France
Contact:

Re: ta3d AI

Post by zuzuf » Mon May 18, 2009 10:41 pm

yes, it does. Currently tables are not supported by this global environment, if needed I'll add support for them.
=>;-D Penguin Powered

xpoy
Posts: 669
Joined: Mon Sep 22, 2008 3:55 am

Re: ta3d AI

Post by xpoy » Tue May 19, 2009 5:33 am

:D
Really cool job.
I'm considing AI ally,and some share for improve the performance of game.For example, share total units/build list/most info

Post Reply

Who is online

Users browsing this forum: No registered users and 30 guests