Joshua

Come in here to talk about your sky-net style world-destroying super bots!

Moderator: Defcon moderators

User avatar
Ace Rimmer
level5
level5
Posts: 10803
Joined: Thu Dec 07, 2006 9:46 pm
Location: The Multiverse

Postby Ace Rimmer » Fri Feb 26, 2010 9:51 pm

Hehe, I tried to use tables, but GetAllUnits() produces a table, and if you limit the Bot (vs full information), it works 'ok'. It's better than nothing. :P

Fine tuning mine now and hoping to see some sporadic naval nuking. :shock:
Smoke me a kipper, I'll be back for breakfast...
User avatar
martin
level5
level5
Posts: 3210
Joined: Fri Nov 19, 2004 8:37 pm
Location: ::1
Contact:

Postby martin » Sat Feb 27, 2010 1:54 am

Yeah, I'm currently getting back the table of all units (just after placing airbases) and then I'm filtering out all the airbases I own, and storing their IDs in a table for future lookup. It seems that Api calls are really slow, so storing their ID and vital information (like position) in Lua allows me fast access.

Can anyone else confirm this slow access suspicion? I drew it because I built a minmax heap, which is building a heap from about 5000 items, that all happens in 1 tick (it's not a long running operation, there is no yielding), that's written in pure Lua and it's bloody fast. Compare this to Getting a list of all my units from the Api, and things start looking slow :(
GENERATION 22:The first time you see this, copy it into your sig on any forum and add 1 to the generation. Social experiment.
User avatar
Ace Rimmer
level5
level5
Posts: 10803
Joined: Thu Dec 07, 2006 9:46 pm
Location: The Multiverse

Postby Ace Rimmer » Sat Feb 27, 2010 4:11 am

martin wrote:Yeah, I'm currently getting back the table of all units (just after placing airbases) and then I'm filtering out all the airbases I own, and storing their IDs in a table for future lookup. It seems that Api calls are really slow, so storing their ID and vital information (like position) in Lua allows me fast access.

The reason for me not using a table with stored info, which is what I originally tried to do, is because I could never figure out a way to remove destroyed object. Plus, you really need to continuously query for new information anyway (so GetAllUnits is still there). Unless you have a really cool way to constantly get a new and valid picture of the Defcon world.

(you do, don't you?!)

All my ground units are stored in tables.
Smoke me a kipper, I'll be back for breakfast...
User avatar
martin
level5
level5
Posts: 3210
Joined: Fri Nov 19, 2004 8:37 pm
Location: ::1
Contact:

Postby martin » Sat Feb 27, 2010 8:32 pm

Yes I do. I pull out all of the information about an object which doesn't change just once and store it in a table, this doesn't eliminate but will at least reduce the amount of API calls.
GENERATION 22:The first time you see this, copy it into your sig on any forum and add 1 to the generation. Social experiment.
User avatar
martin
level5
level5
Posts: 3210
Joined: Fri Nov 19, 2004 8:37 pm
Location: ::1
Contact:

Postby martin » Sun Feb 28, 2010 1:48 am

Well I hit a helluva brick wall today, it seems there is no way to get information about shots. GetAllUnits and GetAllUnitData return tables of all units you currently know about, they never seem to return a gunshot. I'm really not sure what to do about this, without gunshots I can't do the backtracking of defensive volleys to track the locations of enemies, which is one of the coolest things the bot can do.
GENERATION 22:The first time you see this, copy it into your sig on any forum and add 1 to the generation. Social experiment.
User avatar
Montyphy
level5
level5
Posts: 6745
Joined: Tue Apr 19, 2005 2:28 pm
Location: London, England

Postby Montyphy » Sun Feb 28, 2010 2:14 am

martin wrote:Well I hit a helluva brick wall today, it seems there is no way to get information about shots. GetAllUnits and GetAllUnitData return tables of all units you currently know about, they never seem to return a gunshot. I'm really not sure what to do about this, without gunshots I can't do the backtracking of defensive volleys to track the locations of enemies, which is one of the coolest things the bot can do.


What about GetShots?
Uplink help: Check out the Guide or FAQ.
Latest Uplink patch is v1.55.
User avatar
Ace Rimmer
level5
level5
Posts: 10803
Joined: Thu Dec 07, 2006 9:46 pm
Location: The Multiverse

Postby Ace Rimmer » Sun Feb 28, 2010 3:26 am

Montyphy wrote:
martin wrote:Well I hit a helluva brick wall today, it seems there is no way to get information about shots. GetAllUnits and GetAllUnitData return tables of all units you currently know about, they never seem to return a gunshot. I'm really not sure what to do about this, without gunshots I can't do the backtracking of defensive volleys to track the locations of enemies, which is one of the coolest things the bot can do.


What about GetShots?

Or OnEvent, which can and does log gunshots/nuke strikes.
Smoke me a kipper, I'll be back for breakfast...
User avatar
martin
level5
level5
Posts: 3210
Joined: Fri Nov 19, 2004 8:37 pm
Location: ::1
Contact:

Postby martin » Sun Feb 28, 2010 3:23 pm

OnEvent logs hits, I want to be able to track them in motion, and then when they hit I remove that shot from the movement log and do some data analysis to try and backtrack silo positions.

GetShots looks promising, although it's annoying that it's not included in GetAllUnitData, since I already have a framework set up for parsing that data.

edit:: A small setback with GetShots, it doesn't actually exist:

Note that no functions have been removed, although the official function list document does reference some functions (e.g. DebugMoveCamera and GetShots) which do not actually exist in the bot API, and hence cannot be exposed to Lua.
GENERATION 22:The first time you see this, copy it into your sig on any forum and add 1 to the generation. Social experiment.
User avatar
Ace Rimmer
level5
level5
Posts: 10803
Joined: Thu Dec 07, 2006 9:46 pm
Location: The Multiverse

Postby Ace Rimmer » Tue Apr 27, 2010 5:08 pm

I've sent an email regarding GetShots, hopefully it will be added.

Whilst we wait, question; you mentioned API calls being slow, would using GetAllUnits() in a For loop (actually two, one nested) be slow enough to cause an issue where the bot is giving orders bases on previous locations of enemy units?

I.e. "loop through all units, find my carriers, loop through all units, find enemy carriers, if they are too close, move based on enemy carrier position" Using the whiteboard, I found that this method works, but then at times it attempts to make this calculation based on long/lat that contains no unit.

At times, it even seems to try to base it movement on 'empty' sea. There may have been a unit there at one time, but in these cases I don't see any fading explosion or remember any units in that spot (I can't keep track of every unit position, in my brain). This lead me to believe it might be looking at existing units (haven't been destroyed) but they're old location, vs current location. (ships move in battle).

Pic for reference:

'X': Enemy unit bot is responding to.
'Square': Bot unit responding (you can see the whiteboard square in the mass of bot BBs)
'Order (unittype)': Order being give based on enemy unit type. "Invalid" ??? (it's looking for a unittype at the long/lat given, shown by the 'X'.

Image
Image
User avatar
martin
level5
level5
Posts: 3210
Joined: Fri Nov 19, 2004 8:37 pm
Location: ::1
Contact:

Postby martin » Tue Apr 27, 2010 7:16 pm

I don't know, I'm only going off my experience, this is why I think API calls are slow. A loop which did something with the API over a load of units in Joshua was causing the game to hang, I threw in a Yield and all was fine. Now, later on I wrote a method which loops over a load of data and arranges it into a certain order, there were about 5000 points and it did all this sorting (which is pure Lua with no API calls) without a single yield! Doing that much in a single frame is unimaginable if API calls are involved.

As for my instinct on that function, I think it would cause the game to hang. Since you know that the return result of GetAllUnits() will not change while that loop is executing, why not cache the result and save yourself the trouble?
GENERATION 22:The first time you see this, copy it into your sig on any forum and add 1 to the generation. Social experiment.
User avatar
Ace Rimmer
level5
level5
Posts: 10803
Joined: Thu Dec 07, 2006 9:46 pm
Location: The Multiverse

Postby Ace Rimmer » Tue Apr 27, 2010 7:40 pm

martin wrote:As for my instinct on that function, I think it would cause the game to hang. Since you know that the return result of GetAllUnits() will not change while that loop is executing, why not cache the result and save yourself the trouble?

When you say cache the result, what exactly do you mean?
User avatar
martin
level5
level5
Posts: 3210
Joined: Fri Nov 19, 2004 8:37 pm
Location: ::1
Contact:

Postby martin » Tue Apr 27, 2010 10:07 pm

Get the result just once, and store it in a table, and then every time you want to know some data instead of asking the API, simply look in the table.
GENERATION 22:The first time you see this, copy it into your sig on any forum and add 1 to the generation. Social experiment.
User avatar
Montyphy
level5
level5
Posts: 6745
Joined: Tue Apr 19, 2005 2:28 pm
Location: London, England

Postby Montyphy » Tue Apr 27, 2010 10:23 pm

Ace Rimmer wrote:
martin wrote:As for my instinct on that function, I think it would cause the game to hang. Since you know that the return result of GetAllUnits() will not change while that loop is executing, why not cache the result and save yourself the trouble?

When you say cache the result, what exactly do you mean?


Probably means something like at the beginning of the tick populate a table using API calls then throughout that tick only refer to the table. At the beginning of the next tick, overwrite the table.

Really simple pseudocode example:

Code: Select all

function tick() {
   //prepare cache
   unit_cache = []

   //populate cache
   for (unit in all_units) {
      unit_cache[unit] = get_position(unit)   //where get_position represents an API call
   }

   //use cache
   for (unit in unit_cache) {
      //do something
   }

   for (unit in unit_cache) {
      //do something different
   }
}


EDIT: ninja'd due to being distracted :P
Uplink help: Check out the Guide or FAQ.

Latest Uplink patch is v1.55.
User avatar
Ace Rimmer
level5
level5
Posts: 10803
Joined: Thu Dec 07, 2006 9:46 pm
Location: The Multiverse

Postby Ace Rimmer » Tue Apr 27, 2010 10:30 pm

Well, I did try that method originally, just not in that order. I believed not being able to delete a unit from a table (my lack of coding know-how probably) was responsible for errors, so I went to only using API calls. This works, but with the above mentioned issue.

When I say 'not in that order', I mean I was doing both things (getting 'new' unit data and placing in tables, and searching those tables in the same tick). I'll restructure it based on Montyphy's example and see if that solves both issues.

I assumed the startlongtask/yieldlongtask would allow both functions (getnewdata/searchvisibleunits) at the same time without issues.

Thanks both of you.
User avatar
martin
level5
level5
Posts: 3210
Joined: Fri Nov 19, 2004 8:37 pm
Location: ::1
Contact:

Postby martin » Tue Apr 27, 2010 10:57 pm

The important thing is not to cache any data between frames, otherwise the cache becomes stale and you get problems with units in the cache which don't actually exist. If you're doing this in a long task that's a problem, because you have no idea when a new frame starts. I'll have a think about that and see if I can rebuild the task system to inform you when a new task starts.
GENERATION 22:The first time you see this, copy it into your sig on any forum and add 1 to the generation. Social experiment.

Return to “AI Bots”

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest