Joshua
Moderator: Defcon moderators
- Ace Rimmer
- level5
- Posts: 10803
- Joined: Thu Dec 07, 2006 9:46 pm
- Location: The Multiverse
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
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.
- Ace Rimmer
- level5
- Posts: 10803
- Joined: Thu Dec 07, 2006 9:46 pm
- Location: The Multiverse
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...
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.
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.
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?
- Ace Rimmer
- level5
- Posts: 10803
- Joined: Thu Dec 07, 2006 9:46 pm
- Location: The Multiverse
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...
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:
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.
- Ace Rimmer
- level5
- Posts: 10803
- Joined: Thu Dec 07, 2006 9:46 pm
- Location: The Multiverse
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'.
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'.
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?
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.
- Ace Rimmer
- level5
- Posts: 10803
- Joined: Thu Dec 07, 2006 9:46 pm
- Location: The Multiverse
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?
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
- Ace Rimmer
- level5
- Posts: 10803
- Joined: Thu Dec 07, 2006 9:46 pm
- Location: The Multiverse
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.
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.
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.
Who is online
Users browsing this forum: No registered users and 4 guests