AI

AI

A fresh perspective on battle for control of Earth, brought to you by Sanada and Snoop.

Moderators: Moderators, Content Developer

Post Reply
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

AI

Post by AF »

Okay, we can see that actual changes to the game are occurring because of the lack of AI, but as of yet, Im not aware of any thread post describing what the problem actually is, or what actually needs doing.

For example, myself, all I have lately is "come use your powers to fix Shard for CT"

To which I have only one answer:
"insufficient vesphene gas details"
In the past any attempts to gain more details leaves me with a feature list, not details, which cna eb a little frustating =(

So my current guess is that its something to do with resource collection, which Ive asked about before, and gotten either "we do starcraft style harvesting now" ( yes but how?! Im not a CT player or a CT lua dev! ), or, "units attack things and that adds resources".

But that doesnt tell me:
  • how to issue a harvest command
  • figure out what resource is harvestable
  • know which units are capable of harvesting
  • know when resources are harvested aka some kind of 'dropped off resource' event
  • where harvestable resources are
  • what is harvestable and what isnt
  • How much I get on each dropoff
  • How long between harvester go mine, and harvester comes back, aka how long does one bought of mining actually take before the miner comes back with shiny stuff
  • How many times can a harvestable mine?
  • Can it be mined by more than one miner at a time?
  • How do I know when a harvestable appears
  • How do I know when a harvestable dissapears
  • How do I know if a unit is currently mining? aka its current state
  • How do I know if a harvestable dissapears because it has been completely mined
Which are some of the fundamental questions needed. Currently harvestings implementation to those not in the know is a big opaque box with no API and no documentation. We have the small tidbit that it somehow involves weapons fire and attacking, but I need a little help if I'm to make any progress!
Last edited by AF on 10 Nov 2010, 20:15, edited 1 time in total.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: AI

Post by smoth »

considering the fact that they are looking at ripping up the econ might be too early for them to say.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: AI

Post by AF »

Possibly, but people are asking about it, and Ive personally been asked in private. I think a public discussion might be more productive since half the time Im referred to other people anyway and Im not always on msn to answer stuff
User avatar
SanadaUjiosan
Conflict Terra Developer
Posts: 907
Joined: 21 Jan 2010, 06:21

Re: AI

Post by SanadaUjiosan »

I can proudly say I have no idea how the harvesting works as far as nuts and bolts go. That is knorke's realm.

But, I will say that snoop and I talked yesterday and were trying to come up with a solution. Honestly I think the larger hurdle is AI being able to use morph, because currently you need to morph to build units and be any threat at all. RAI, for example, harvests just fine. A secondary builder unit could fulfill the building needs. What AI support for CT is lacking now is the ability to morph.

Snoop, as always, is more the person to talk to concerning AI for our game. I handle different responsibilities. Some kind of discussion would be nice.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: AI

Post by knorke »

# how to issue a harvest command
harvesting is attacking.

# figure out what resource is harvestable
harvestable resources have a custom parameter tag in unitdef:
is_mineable=1

# know which units are capable of harvesting
custom paremeter:
is_miner=1
atm it is only the "bminer" unit
Dropoffs are currently hard coded, but will be changed to have a custom parameter:
is_dropoff=1
or similiar

# know when resources are harvested aka some kind of 'dropped off resource' event
UnitDamaged, then do if attacker=miner and attacked unit = mineable blabla then stuff was mined
no 'dropped off resource' event atm

# where harvestable resources are
all resources are visible outside LOS by alwaysvisible=true, so GetTeamUnits (GaiaTeam) should get them all

# How much I get on each dropoff
damage done = resources harvested
how much a miner can carry is defined by a custom tag:
max_cargo=25

# How long between harvester go mine, and harvester comes back, aka how long does one bought of mining actually take before the miner comes back with shiny stuff
the actual mining takes ~2 seconds and time to return depends on distance.
maybe this is helpfull:
http://springrts.com/phpbb/viewtopic.ph ... 3&start=52

# How many times can a harvestable [be] min[ed]?
depends on maxdamage (health) of the harvestable unit.
ie if maxdamage of a "bminerals" is 500 and a "bminer" carries a cargo of 25 then this resource can be mined 20 times before its depleted.

# Can it be mined by more than one miner at a time?
yes, but too many miners (> 4) and they tend to clog up. better to spread them out a bit.

# How do I know when a harvestable appears
# How do I know when a harvestable dissapears
UnitCreated/Unitdestroyed, check if the new/dead unit has is_mineable=1

# How do I know if a unit is currently mining? aka its current state
if its "attacking" then its mining.
there also is a table of miners in the mining widget:
miners[unitID].cargo [0 to maxcargo]
and
miners[unitID].status ["gotodropoff", "gotores", "searchres" or something like this]
eventually that will be changed into a custom parameter "cargo" so that all widgets/gadgets can read this info more easily.

# How do I know if a harvestable dissapears because it has been completely mined
Atm the only thing that causes them to disappear is being completly mined out.


Miners already work on their own, they automagically search for new resources, return to the nearest drop offs etc. So basically all an AI has to do is:
-build a miner unit then leave it alone -> it will start to harvest and its stuff
-place depots near the resources so the travel paths are shorter for the miners. miners will go to the nearest depot on their own.
-> AI must be able to morph units to use depots!
(must also be able to use morph to make attack units)

The AIs I tested (dont remember) failed because they would always asign new attack commands to the miners, never letting them return.

Some workaround solutions for this were briefly talked about but I wasnt a fan of them really. ie giving the AI different (start) units and combining my KTAI ("knorkes test ai") and another AI in one team, KTAI doing the placing of depots and another AI doing the fighting stuff. Um yeah lol...

I think if an AI only ever "touches" the miners if it needs them to build something, then thats half the solution. Yes, maybe its bad practice that "miner AI" and "miner resource logic" are mixed in one gadget instead of "miner AI" being in a widget so that players can make their own optimizezed miner AIs but really wtf doesnt matter. Isnt really needed for the AI to know that much details about the miners as they kind of work on their own.

I had not really thought about AIs so much but my idea was to just ask an AI dev what kind of info they need to get their AI working with CT blablabla and I hope this post is somewhat helpful with that.
Last edited by knorke on 11 Nov 2010, 00:42, edited 1 time in total.
User avatar
Wombat
Posts: 3379
Joined: 15 Dec 2008, 15:53

Re: AI

Post by Wombat »

knorke wrote:# how to issue a harvest command
harvesting is attacking.
why not patrol ? just asking i got no idea how to do it either
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: AI

Post by knorke »

"attacking" is the act of a unit dealing damage to another unit.

"patrolling" is the unit circling on a path and attacking any near units. so yes, you could set a miner on patrol around your base and if meteors land near his path he would start mining them.
User avatar
Wombat
Posts: 3379
Joined: 15 Dec 2008, 15:53

Re: AI

Post by Wombat »

oh ok nvm then <3
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: AI

Post by AF »

To make shard leave a unit alone, simply create a behaviour called 'NullBehaviour' and make sure it has no logic of any kind in it, aka empty functions. Then manually assign it to bminer in the behaviours.lua, and Shard will let it do as it pleases for the remainder of the game.

Thanks for the info knorke
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: AI

Post by knorke »

ok sounds like an idea.
thing is, the miners are also construction units (ie like in starcraft or age of empires)
so with an empty behaviour, will shard still use the units for constructing?
also how will it know that a unit that "generates" no metal, is not an extractor etc. will give metal income?
also it must build/fly depots near the mineable rocks, can that be done via a suitable shard config too?
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: AI

Post by AF »

Positioning will be tricky, as will construction

Here's a Null behaviour:

http://pastebin.com/4ApRiGZz

My suggestion for the moment is to do a random thing with a function that returns a task queue. Coupled with a counter, it can make the first miner go off build things, then randomly alternate between returning null and returning a valid taskqueue depending on the unit.

I'll need to think hmmmm
User avatar
oksnoop2
Posts: 1207
Joined: 29 Aug 2009, 20:12

Re: AI

Post by oksnoop2 »

I guess i'll take a moment to explain my hackish ideas for an AI.

Start with a native AI, Shard, e323ai, rai, ect.

We have a gadget that detects if an AI is in control of the team and swaps out flagship for the mobile headquarters for that team.
http://code.google.com/p/conflictterra/ ... _spawn.lua

Code: Select all

local function SpawnStartUnit(teamID)
        local startUnit = string.lower(GetStartUnit(teamID))
        if (startUnit and startUnit ~= "") then
                local teamNum,leader,isDead,isAiTeam,side,allyTeam = Spring.GetTeamInfo(teamID)
                if isAiTeam then
                        if startUnit=="bflagship2" then
                                startUnit="bflagshipbase2"
                        end
                end
Instead of spawning a bflagshipbase2 it could spawn a blflagshipbaseAI which would have the ability to build miners and engineers that did were not able to mine. So the base spawns, shard builds both miners and non miners. The mining gadget takes over the miners and the AI takes over the non miners.

So that initial hurdle is over.

But how will they mine?
http://code.google.com/p/conflictterra/ ... mining.lua

Luckily enough, the miners just kind of do it all by their lonesome with out any prompting.

The part i'm least sure about is this. Modifying this:
http://code.google.com/p/conflictterra/ ... p_KTAI.lua for the cruiser factories. With that I think the cruisers could act like this:
http://www.youtube.com/user/knorker#p/a/u/0/aOtnOEOtVTM
So Shard builds cruiser, gadget takes over cruiser, morphs it into a factory, AI takes over factory again, starts making units.

Presto! that is my idea.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: AI

Post by AF »

Your issue at the moment is that the taskqueuesbehaviour being the default implementation of construction in Shard is based on the classic NTai model with a few twists such as custom logic. A major component of the NTai model was that it built and built as quickly as possible in order to aggressively expand, which is what made NTai so successful when it came out.

Your now faced with the issue of when do we mine, and when do we build? This is something you can solve right now using the shard APIs, but it may require a custom heavily modified taskqueuebehaviour, or a complete alternative.

It is something I've thought about as it impacts EvolutionRTS too, in that shard doesn't wait for resources, it just builds. Granted this would lead to humonguous unbeatable expansion if the necessary resources were present, but in practise it does not turn out this way, and leads to a near optimal but not perfect strategy. My thoughts here were to add in keywords that indicated to shard to wait a little while before resuming. I'll have to see what I can do at the weekend though, I've work in the morning. It would be too hard to do though, a 15 minute job tops.

e.g.

Code: Select all

local factory = {
   "eengineer5",
   "eengineer5",
   { id="wait",clicks=32}, -- wait 32 frames
   "elighttank3",
   "elighttank3",
   "elighttank3",
etc
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: AI

Post by AF »

Also of note, i oksnoop is correct, setting miner units to hold pos by default should fix order disobeying. There are widgets that autoset this that you can nab the code from for a gadget, and IIRC theres even a unitdef tag for it
Post Reply

Return to “Conflict Terra”