View topic - How to handle units getting stuck?



All times are UTC + 1 hour


Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: 21 Apr 2012, 09:42 

Joined: 20 Aug 2011, 19:21
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!


Top
 Offline Profile  
 
PostPosted: 21 Apr 2012, 15:26 
Spring Developer

Joined: 08 Oct 2006, 15:58
The development build of Spring has a fix for the infinite-bouncing bug.

Quote:
Also, is there a setting in spring to disable wreckage?


That's mod-controlled, but you can always edit mod files for local testing.


Top
 Offline Profile  
 
PostPosted: 23 Apr 2012, 15:22 
Moderator
User avatar

Joined: 22 Feb 2006, 01:02
Location: cheap kitchen
Quote:
Also, is there a setting in spring to disable wreckage?
if the game is BA, there is a modoption for that.
key = "mo_nowrecks",
name = "No Unit Wrecks",
desc = "Removes all unit wrecks from the game",
Quote:
I don't know how to detect when the commander is actually 'helping' the factory to construct units
Can you detect if the commander is using metal? If yes, he is building something.


Top
 Offline Profile  
 
PostPosted: 23 May 2012, 18:12 
User avatar

Joined: 23 May 2012, 17:36
Quote:
Can you detect if the commander is using metal? If yes, he is building something.


This solution is not perfect - you may have a worker (not neccessarily the com) which is stockpiling projectiles but not building.

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:
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


Another idea is to manually check if a unit is inside a collision volume of a feature on a given position.


Top
 Offline Profile  
 
PostPosted: 30 May 2012, 15:44 
AI Coder

Joined: 17 Mar 2008, 19:03
Location: RF
If unit can't do smth it gets idle. Catch the event.


Top
 Offline Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group

Site layout created by Roflcopter et al.