View topic - Shard 0.35RC2 & 0.31.1 Not So Ballsey



All times are UTC + 1 hour


Post new topic Reply to topic  [ 563 posts ]  Go to page Previous  1 ... 15, 16, 17, 18, 19, 20, 21 ... 29  Next
Author Message
PostPosted: 08 Oct 2011, 17:57 
AI Coder
User avatar

Joined: 14 Sep 2004, 10:32
Location: Cookieland
NTai is evolved code, Shard has a defined structure and design.

NTai still has a lot more in it, if you look back at it you can find many little tricks and behaviours you can steal to make your version of Shard even better!

As a sidenote, if you build your own configs for say BA or Evo that differ from those in the standard distribution, maybe you've decided to take a different approach, I'm perfectly happy for you to release it as a separate AI alongside Shard with a new name, as long as you keep it up to date and make it quite clear it's based on Shard.


Top
 Offline Profile  
 
PostPosted: 08 Oct 2011, 22:10 
AI Coder
User avatar

Joined: 14 Sep 2004, 10:32
Location: Cookieland
Something along these lines:

Code:
UnitTypeCounter = class(Module)

function UnitTypeCounter:Name()
   return "UnitTypeCounter"
end

function UnitTypeCounter:internalName()
   return "TypeCounter"
end

function UnitTypeCounter:Init()
   self.typeCount = {}
end

function UnitTypeCounter:UnitCreated(engineunit)
   if engineunit:Team() == game:GetTeamID() then
      local t = engineunit:Type()
      local name = t:Name()
      local count = 0
      if self.typeCount[name] ~= nil
         count = self.typeCount[name]
      end
      self.typeCount = count + 1
   end
end

function UnitTypeCounter:UnitBuilt(engineunit)
   
end

function UnitTypeCounter:UnitDead(engineunit)
   if engineunit:Team() == game:GetTeamID() then
      local t = engineunit:Type()
      local name = t:Name()
      local count = 0
      if self.typeCount[name] ~= nil
         count = self.typeCount[name]
      end
      self.typeCount = count - 1
   end
end


Put in a file UnitTypeCounter.lua, and include it in modules.lua which is straight forward. Add it to the table which is just a comma separated list, and add in the file at the top with the others


Top
 Offline Profile  
 
PostPosted: 08 Oct 2011, 22:27 
AI Coder
User avatar

Joined: 14 Sep 2004, 10:32
Location: Cookieland
As a note for those with existing code.

Where you see this:

Code:
if unit:Internal():ID() == self.unit:Internal():ID() then


It's faster/quicker to use:

Code:
if unit.engineID == self.unit.engineID then


Also remember to check if the unit is actually on your team if your listening out for a unit in a behaviour other than the unit it belongs to, as it may not be one of Shards units.

Code:
if engineunit:Team() == game:GetTeamID() then



RC2 contains various fixes regarding this check, it appears past versions of Shard added taskqueue behaviours etc to Shards units AND the players units. I've also renamed parameters in some places from unit to engineunit to make it clearer the distinction ( specifically attackhandler )


Top
 Offline Profile  
 
PostPosted: 08 Oct 2011, 23:57 
AI Coder
User avatar

Joined: 14 Sep 2004, 10:32
Location: Cookieland
http://www.darkstars.co.uk/downloads/vi ... 0.35RC2.7z

I've fixed the map features API, I've also fixed some logic errors in the auto reclaim behaviour and included it, however, at the moment I cannot get area reclaim to work. Individual reclaiming of features works however.

I suspect I need to build Shard with a newer version of the C++ Wrapper, but none is provided in the source download, and I'm incapable of generating one by myself ( I've spent hours trying via CMake under windows with little or no progress )


Top
 Offline Profile  
 
PostPosted: 09 Oct 2011, 09:30 
User avatar

Joined: 20 Aug 2009, 19:49
No area reclaim makes me a sad panda.


Top
 Offline Profile  
 
PostPosted: 09 Oct 2011, 18:15 
AI Coder
User avatar

Joined: 14 Sep 2004, 10:32
Location: Cookieland
The alternative is to just figure out which features are the closest and then add them to a queue of features to reclaim. You'd need to modify the behaviour though to follow the new logic

The behaviour will make the unit reclaim the feature at the front of the queue when idle and elect a new behaviour when the queue is empty.

On Update at regular intervals, it will search the local viscinity of say 1000 for features. If none are found do a wider search for the nearest feature and tell the builder to reclaim it.


Top
 Offline Profile  
 
PostPosted: 09 Oct 2011, 19:08 
User avatar

Joined: 20 Aug 2009, 19:49
Normal reclaim order seems to have no effect aswell.


Top
 Offline Profile  
 
PostPosted: 11 Oct 2011, 16:29 
AI Coder
User avatar

Joined: 14 Sep 2004, 10:32
Location: Cookieland
=/

I'll have to see about sourcing a new C++ wrapper from someone

For reference here are the two C++ methods, if anyone can see something wrong below let me know:

Code:
bool CSpringUnit::Reclaim(IMapFeature* mapFeature){
   SReclaimUnitCommand c;
   c.unitId = this->unit->GetUnitId();
   c.toReclaimUnitIdOrFeatureId = mapFeature->ID();

   int e = callback->GetEngine()->HandleCommand(callback->GetTeamId(),-1,COMMAND_UNIT_RECLAIM,&c);
   return (e == 0);
}

bool CSpringUnit::AreaReclaim(Position p, double radius){
   SReclaimAreaUnitCommand c;
   c.unitId = this->unit->GetUnitId();
   c.radius = radius;
   SAIFloat3 pos;
   pos.x = p.x;
   pos.y = p.y;
   pos.z = p.z;
   c.pos = pos;

   int e = callback->GetEngine()->HandleCommand(callback->GetTeamId(),-1,COMMAND_UNIT_RECLAIM_AREA,&c);
   return (e == 0);
}


Top
 Offline Profile  
 
PostPosted: 12 Oct 2011, 00:58 
Evolution RTS Developer
User avatar

Joined: 17 Nov 2005, 02:43
Location: Raegquitting Spring on 04/24/12
Error:

http://pastebin.com/PWtSZfxx << Infolog

Relevant bits:

Code:
[f=0000006] Skirmish AI "Bot1" took over control of team 0
[f=0000147] <SkirmishAI: Shard 3.0 (team 0)>: Error in IGame::GetResource (arg 2), expected 'int' got 'string'
stack traceback:
   [C]: ?
   [C]: ?
   [C]: in function 'GetResource'
   D:\Spring\AI\Skirmish\Shard\3.0\ai\preload\api.lua:114: in function 'GetResource'
   ...\Skirmish\Shard\3.0\ai\EvoRTS\lowenergybehaviour.lua:16: in function 'UnitIdle'
   D:\Spring\AI\Skirmish\Shard\3.0\ai\unit.lua:72: in function 'UnitIdle'
   D:\Spring\AI\Skirmish\Shard\3.0\ai\unithandler.lua:97: in function 'UnitIdle'
   D:\Spring\AI\Skirmish\Shard\3.0\ai\ai.lua:85: in function <D:\Spring\AI\Skirmish\Shard\3.0\ai\ai.lua:75>


Top
 Offline Profile  
 
PostPosted: 12 Oct 2011, 10:58 
AI Coder
User avatar

Joined: 14 Sep 2004, 10:32
Location: Cookieland
Use game:GetResourceByName instead of game:GetResource


Top
 Offline Profile  
 
PostPosted: 13 Oct 2011, 23:54 
Evolution RTS Developer
User avatar

Joined: 17 Nov 2005, 02:43
Location: Raegquitting Spring on 04/24/12
http://pastebin.com/zhE6KQK1

Code:
[f=0004249] <SkirmishAI: Shard 3.0 (team 0)>: ...ring\AI\Skirmish\Shard\3.0\ai\taskqueuebehaviour.lua:120: attempt to index field 'unit' (a nil value)
stack traceback:
        [C]: ?
        [C]: ?
        ...ring\AI\Skirmish\Shard\3.0\ai\taskqueuebehaviour.lua:120: in function 'ProgressQueue'
        ...ring\AI\Skirmish\Shard\3.0\ai\taskqueuebehaviour.lua:110: in function 'wakeup'
        D:\Spring\AI\Skirmish\Shard\3.0\ai\sleep.lua:44: in function 'Wakeup'
        D:\Spring\AI\Skirmish\Shard\3.0\ai\sleep.lua:19: in function 'Update'
        D:\Spring\AI\Skirmish\Shard\3.0\ai\ai.lua:32: in function <D:\Spring\AI\Skirmish\Shard\3.0\ai\ai.lua:24>


Top
 Offline Profile  
 
PostPosted: 14 Oct 2011, 11:42 
AI Coder
User avatar

Joined: 14 Sep 2004, 10:32
Location: Cookieland
I assume you're using the wait command? Quickfix is to remove waiting while I summon up a quickfix for waiting


Top
 Offline Profile  
 
PostPosted: 14 Oct 2011, 12:12 
AI Coder
User avatar

Joined: 14 Sep 2004, 10:32
Location: Cookieland
Try the attached version, I'm not in a position to test at the moment, so if it doesn't work or there's a silly syntax error please post any fixes or missing commas or brackets you find.

Basically I've added a check to see if the unit is still alive, and cleaned up after the waiting objects.

There was also the chance that a wait command would never be cancelled on a units death because the task behaviour never kept track of it properly so it wouldn't kill the wait on unit death. Leading to the error when it tried to progress the taskqueue on a dead unit, meaning it would never be removed, and it would repeat the following frame leading to yet another stack trace.


Attachments:
taskqueuebehaviour.lua [3.81 KiB]
Downloaded 88 times
Top
 Offline Profile  
 
PostPosted: 19 Oct 2011, 13:29 
AI Coder
User avatar

Joined: 14 Sep 2004, 10:32
Location: Cookieland
Linux .so, untested, built using spring 0.82.7.1 under a Ubuntu 11.10 VM


Attachments:
libSkirmishAI.zip [1.23 MiB]
Downloaded 12 times
Top
 Offline Profile  
 
PostPosted: 29 Oct 2011, 17:33 
User avatar

Joined: 20 Aug 2009, 19:49
Does the reclaim work for you by now? I can't get it to work, neither single feature reclaim nor area reclaim

Code:
 self.unit:Internal():Reclaim(feat[target])


yields

Code:
[f=0001113] <SkirmishAI: Shard 0.35RC2 (team 1)>: ...sh\Shard\0.35RC\ai\Void\builderregisterbehaviour.lua:8: attempt to call method 'Internal' (a nil value)


What am I doing something wrong? It works in notsoballsey version.


Top
 Offline Profile  
 
PostPosted: 29 Oct 2011, 23:51 
AI Coder
User avatar

Joined: 14 Sep 2004, 10:32
Location: Cookieland
I can't further diagnose the issue until I know the context of that call.

I'd also keep to the convention of unit vs engineunit. One is the AIs representation of an API object, the other IS an API object. I'd also avoid chaining commands like that as it makes it harder to debug which operation is at fault


Top
 Offline Profile  
 
PostPosted: 29 Oct 2011, 23:58 
AI Coder
User avatar

Joined: 14 Sep 2004, 10:32
Location: Cookieland
Try the attached dll, it's been rebuilt with newer cpp wrapper bindings, I can't vouch for whether it fixed reclaiming however also, make sure you check if the unit is your own unit, and not an enemy unit

Unit Destroyed means a unit was destroyed, not your unit was destroyed, it's up to you to double check these things while I track down any holes for bad values to seep through. ( and its important you let me know the logic path so I know where to look for these things to see if I can help )


Attachments:
SkirmishAI.7z [332.56 KiB]
Downloaded 15 times
Top
 Offline Profile  
 
PostPosted: 30 Oct 2011, 12:11 
User avatar

Joined: 20 Aug 2009, 19:49
Context
Code:
function AutoReclaimBehaviour:Update()
   local f = game:Frame()

   if math.mod(f,500) == 0 then

game:SendToConsole("updating collector targets ------------")
     pos = self.unit:Internal():GetPosition()
     local feat = map:GetMapFeaturesAt(pos,50000)
     local Eval = {}
 
  if #feat > 0 then
   

   for i=1,#feat do

         local e = feat[i]
         posf = e:GetPosition()

           if (e:ResourceValue(0)>0) then --check for metal
      
          --Formula(Distance^2)
             
          local dist= math.sqrt((posf.x-pos.x)*(posf.x-pos.x) +(posf.z-pos.z)*(posf.z-pos.z))
          Eval[i]=dist
   
           else
          Eval[i]=1000000
        end--check for metal

                 
                end
   end --loop over features

      game:SendToConsole("now evaluating table")

   local rec_targ=1
   local rec_val=1000000
   for i=1,#feat do
     if (Eval[i]<rec_val) then
      rec_targ=i
      rec_val=Eval[i]
     end
        end --loop over table

   game:SendToConsole("done evaluating winner is:")
      game:SendToConsole(rec_targ)
      game:SendToConsole("with value")
      game:SendToConsole(rec_val)
         

        self.unit:Internal():Reclaim(feat[rec_targ])
   
  end --#feat > 0
end

Quote:
I'd also keep to the convention of unit vs engineunit. One is the AIs representation of an API object, the other IS an API object. I'd also avoid chaining commands like that as it makes it harder to debug which operation is at fault

I have no idea how, perhaps you could supply some example calls because its pretty hard to derive working calls from nothing.


Top
 Offline Profile  
 
PostPosted: 30 Oct 2011, 15:15 
AI Coder
User avatar

Joined: 14 Sep 2004, 10:32
Location: Cookieland
Hmmm this is not based on the near working auto reclaim behaviour in the 0.35rc2 download?

Your code even if it works would send the unit off reclaiming every 500 frames regardless of what it's currently doing.

Your also not checking to see if the unit belongs to your AI

As for chaining commands

Code:
Self.unit:Internal()Reclaim(feat[x])


Versus

Code:
Local unit = self.unit
Local engineunit = unit:Internal()
If engineunit ~= nil then
    Local feature = feat[x]
    Engineunit:Reclaim(feature)
End


Top
 Offline Profile  
 
PostPosted: 30 Oct 2011, 16:18 
User avatar

Joined: 20 Aug 2009, 19:49
Quote:
Your code even if it works would send the unit off reclaiming every 500 frames regardless of what it's currently doing.

That is intended.

Reclaim commands as such are not working neither area nor single feature.


Top
 Offline Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 563 posts ]  Go to page Previous  1 ... 15, 16, 17, 18, 19, 20, 21 ... 29  Next

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.