Thursday, April 12, 2012

AI Modding(FA):Forcing AI to specific ordering of structures

[:1]I'm attempting to create a new AI, hopefully featuring machine learning (if lua and engine/AI framework allow it). While i am still getting familiar with the AI framework provided with FA i'm working on some smaller modifications and i could use some assistance.



Right now i am looking at the possibility of forcing the AI to build structures with specific predefined layouts or ordering (resembling the work of human players). By this i am hoping to be able to force the AI to build proper forward defense mechanisms in front of his base and at expansion bases instead of randomly placed lines or chunks of t1/t2 stuff placed awkwardly in strategic sense. If he cannot find places himself to build this due to terrain or general inability to calculate it's placement intelligently out this feature can easily be realized with the assistance of well placed defense markers (would have to be manually placed or edited by map makers).



The idea is that once we place the first structure the remaining structures are placed relative to the first one. So as long as the defense markers are properly placed and/or we can calculate that our template does indeed fit the build spot this should be easy as long as we can order the ai to actually build the structures with specific ordering.



So now here's the question. Is this possible (ordering ai to build structures at precise locations and with precise ordering) and if so. Could someone point me in the right direction.|||theres a file called basetemplates.lua in the main lua folder. I have never really played with it, but I belive this will do what you ask although Im not sure how it works. Also check out the EngineerBuildAI in the platoon.lua file and the aibuildstructures.lua file.|||i'm pretty certain you can do that; i've seen a few functions that order engineers to build specific structures at specific locations.



maybe the buildtemplate code that players use might be worth investigating if the stock AI stuff doesn't pan out.|||thank you for your response. I've been studying the framework and documenting functions and the framework itself (in latex). I might release this at some point if this project goes off.|||It's very difficult to figure out how the basetemplates work in basetemplates.lua. At least i do not see a pattern between the type list and then the coordinates. However by creating base templates (in the game) myself and extracting the template list from that file i've managed to get a "template" list with types and relative coordinates to the first structure explicitly laid out. If i can manage to modify the AI build code to accept these templates i can make them build any type of base i like by just building it myself in the game and saving it as a template. Then implement it into a database the AI can choose from and use to form his base and extension bases.|||:shock:



awesome



I was thinking, if this is possible one could save the AI quite some commands and thus increase the gamespeed ;)|||I did notice some things that could potentially increase the simulation speed at later points in the game.



I noticed that all sorting is done with selection sort which is a O(n^2) algorithm. Sorting things such as threatpriorities, buildpriorites and so on. So during the later stage if this is done very often and contains many units we then we are talking about a very ineffecient way to sort these lists.



A list with 100 units would be n = 10000 while a O(n log n) algorithm such as mergesort would be 100*log(100) = 200. Which means mergesort would be 50 times quicker to sort these lists compared to the algorithm currently used. It's on my todolist to rewrite them and see if it does make a difference. Overall the gain might be so small though that it wont be noticable but that depends on how often these lists are sorted and with how many units.|||Hi Steinar;



In response to your first question about how the AI positions it's buildings;



The basetemplates are comprised of an entry for each faction UEF, AEON, CYBRAN and SERAPHIM.



Within each entry you have a structure list - followed by a table of relative positions.



When a series of structures is built in a single command, the first structure determines which table of positions will be used. That building will use the first relative position from it's corresponding table of positions.



Each following building will use the NEXT relative position. As best as it can. You get odd behaviour when the building won't fit within the space provided by the co-ordinates - BUT - you can make custom basetemplates (edit the original basetemplates.lua) or create entirely seperate basetemplate files.



In the second case - be sure to specify the BaseTemplateFile and the BaseTemplate you wish to use in any specific platoon;



Example;



Builder {BuilderName = 'T3 Base D Engineer - Perimeter - UEF',

PlatoonTemplate = 'T3EngineerBuilder',

Priority = 925,

BuilderConditions = {

{ MIBC, 'FactionIndex', {1, 1} },

{ EBC, 'GreaterThanEconEfficiencyOverTime', { 0.8, 1.2 }},

{ IBC, 'BrainNotLowPowerMode', {} },

},

BuilderType = 'Any',

BuilderData = {

NumAssistees = 3,

Construction = {

Radius = 60,

BuildClose = false,

NearBasePatrolPoints = true,

BaseTemplateFile = '/lua/loudbasetemplates.lua',

BaseTemplate = 'T3PerimeterDefenseTemplates',

BuildStructures = {

'T2EngineerSupport',

'T3AADefense',

'T2Artillery',

'T2MissileDefense',

'T3GroundDefense',

'T2StrategicMissile',

'T3GroundDefense',

'T3AADefense',

'T2MissileDefense',

'T2ShieldDefense',

},

Location = 'LocationType',

}

}

},|||thank you for your response. I have 1 question though about the coordinates. After the list of buildings therescomes a huge list of coordinates which outnumbers the amount of buildings by a factor of 13-18 depending on template. How are buildings matched to relative locations and why do the coordinates outnumber the amount of buildings by different numbers.|||The list of co-ordinates is certainly very large - but it doesn't need to be. I trust that it's that large simply because that list is referred to everytime an engineer looks for a place to build. So - in that case - it's very long in order to accomodate truly huge bases.



For your custom purposes - it can be as long as you need it to be. There is no direct relation between the number of structures listed - and the number of co-ordinates.



In normal use, the logic will use the list of co-ordinates which follows the list that includes the structure you are trying to build.



It's not the clearest mechanism - but if you're going to do custom work - make your own. There is no need to have multiple lists of structures and co-ordinates.

No comments:

Post a Comment