I created a Skirmish AI that plays BA for my thesis. I'm pretty much done and quite happy with it except for one issue. Every few games or so the commander will get stuck on a solar panel flap and just keeping 'bouncing' into it forever. This kills the game. I need to run several hundred games to collect data for my experiments, so preventing the commander from getting stuck would really help.
There are many other situations of units getting stuck (for example, in wreckage), and I'd love to fix the problem. But I understand it is pathing related and likely the only way I'll find a good solution is to rewrite the pathinding myself or wait for the new QTPFS to be finished.
But I need to graduate in June, so rewritting the pathing is not an option. I would be happy just to add some code to my agent to detect when the commander is stuck and adjust. I only give the commander 2 commands. Build and guard (specifically, guard a factory to help construct units faster).
For the 'build' commands, I can track the commanders position, the frame the build command was given, and if the commander started building yet (via unit_created event). During update events, I can check (say every 120 frames--4 seconds) if the commander hasn't started building yet, did he at least make some progress in moving from the previous position? If not, issue a new command.
For the 'guard' commands, I'm not sure what to do. I can track the commanders position, and every 120 frames, see if he make movement progress from the last update, but obviously, he will stop when he gets close enough to the factory to use his nano spray. I don't know how to detect when the commander is actually 'helping' the factory to construct units (in other words, that he is stationary because he arrived close enough to the factory and not because he is stuck on a solar panel).
What do you think is the best way to detect when the commander is really stuck? Also, is there a setting in spring to disable wreckage?
Thanks for your help!
How to handle units getting stuck?
Moderators: hoijui, Moderators
Re: How to handle units getting stuck?
The development build of Spring has a fix for the infinite-bouncing bug.
That's mod-controlled, but you can always edit mod files for local testing.Also, is there a setting in spring to disable wreckage?
Re: How to handle units getting stuck?
if the game is BA, there is a modoption for that.Also, is there a setting in spring to disable wreckage?
key = "mo_nowrecks",
name = "No Unit Wrecks",
desc = "Removes all unit wrecks from the game",
Can you detect if the commander is using metal? If yes, he is building something.I don't know how to detect when the commander is actually 'helping' the factory to construct units
Re: How to handle units getting stuck?
This solution is not perfect - you may have a worker (not neccessarily the com) which is stockpiling projectiles but not building.Can you detect if the commander is using metal? If yes, he is building something.
Can you not check if the commander proceeds in his last task?
This would solve any stuck issues and can easily be extended.
An unfinished example which requires a history about the actions
Code: Select all
function isStuck( unit )
local task = unit.getCurrentTask()
local type = task.getType()
if type = "move" then
local position1 = unit.getLastPosition() or { -1, -1, -1 }
local position2 = unit.getCurrentPosition()
if notTheExpectedDifference( position1, position2 ) then return true end
unit.setLastPosition( position2 )
end
if type = "build" then
local hp1 = unit.getLastHP() or -1
local hp2 = unit.getCurrentHP()
if hp1 = hp2 then return true end
unit.setLastHP( hp2 )
end
end
Re: How to handle units getting stuck?
If unit can't do smth it gets idle. Catch the event.