Shard 0.4/dev - Page 37

Shard 0.4/dev

Here is where ideas can be collected for the skirmish AI in development

Moderators: hoijui, Moderators

User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey

Post by AF »

I should note I'm not the one who wrote the BA specific stuff in Shard, but task queues in Shard are for construction. They're lists of unit names that should be built. If a unit name is a function rather than a string, then it's expected a unit name is the return value of that function.

From the sounds of it, what would be better, is to make use of the behaviour system. Units have behaviours attached to them depending on the type of unit. Most construction units only have the taskqueuebehaviour, but here it sounds like you need to implement a reclaimbehaviour.

When a unit is idle, or a behaviour yields control ( e.g. your reclaim behaviour when it's decided it can take a break or there is nothing left to do ), all the behaviours in a unit are ranked by priority, they're each asked, "do you need to do anything?" and "what is your current priority?". The highest ranking behaviour is then handed full control of the unit, to do as it pleases until such a time it relinquishes control or the unit finishes a task. At this pint the behaviour may say "I did my stuff but there's more to do", and return a high priority to keep control. A "run away" behaviour may trigger this process and declare it has a huge priority and give an order to run away

For centralised systems, implement a module that organises and commands units, and give the units a behaviour that acts as a proxy. This is how attacking works, an attack behaviour tells the module that this unit is an attacker, and it's ready to go. The module then decides to group attackers together and send them off on their business. At this point the attack behaviour tells the module it is now attacking and unavailable for skirmishes, and sets about sending the unit off to the enemy and takes control of that unit as the primary behaviour ( high priority behaviour! we have stuff to kill ).

When enemy units in that area are dead the attack behaviour sets its priority to low and yields control of the unit, and pings the attack module to say it's now available for attacking. Other behaviours attached to the unit then have the opportunity to do things. Otherwise the unit becomes idle.


If you really, really wanted to use taskqueues for this, I would modify the taskqueuebehavior to detect when 'yield' is returned. In the task queue you can then signal to a reclaim behaviour to do its job and raise its priority, but I don't recommend doing any of this, it's kind of hackish
Antti
Posts: 2
Joined: 23 Oct 2015, 23:49

Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey

Post by Antti »

Hello. First I would like to say that I have no experience of Spring or Shard yet.

TLDR: Does Spring+Shard allow for fully dynamic evolving/learning unit-specific AI behavior? Either real time or by placing a unit in standby during learning/evolution?

I'm planning to make an RTS or RTS-like game with rather few and unique units, that have unique evolving AI. This means units, both your own non-selected ones and enemy units, are initially somewhat stupid but as units level up their AI is improved using some optimization method like genetic programming. Also level of development would be represented by some change in unit texture(s). Can it be done with Spring+Shard? Or rather, I know everything is possible with an infinite amount of work but would it be reasonable to do it? Or am I better off making a new AI or looking at some other.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey

Post by AF »

It's possible yes, but you'd have to implement the stupid -> clever mechanic yourself. You're probably best using a lua gadget to define said behavior though, Shard will let you determine behaviors, but how smart a unit is at that behaviour right now is dependent on the game engine. For additional smarts you'll need additional logic.

If you're looking for a cookie cutter out of the box thing you can just plug some values into, you'll won't find that here, or likely anywhere else. Some Ai development on your part will be necessary

Also keep in mind that Shard was built as an opponent AI, you can't just apply it to a handful of your own units without some modification. Perhaps if you implemented the lua gadget API as a backend for shard and wrote a gadget to run an instance of Shard and pass it specific units it could be done

As for machine learning and genetic algorithms, sure you can use those, but you'll have to build them. Everything here is opensource, and Shard and most of the game content is written in Lua that you have direct control of. The question is not does it support XYZ, the question is are you willing to build XYZ
Antti
Posts: 2
Joined: 23 Oct 2015, 23:49

Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey

Post by Antti »

Thanks for the comprehensive answer :) I will start looking deeper into it.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey

Post by AF »

Post back your findings too, some of my suggestions have overlap with things other people wanted to do, you may find help depending on what you do/find
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey

Post by AF »

So I did some initial work, still WIP, will need some attention from those more knowledgeable, but the result is:

https://github.com/Tarendai/Shard/tree/ ... spring_lua

There are now unit and unittype objects that can act as wrappers, in this particular case, wrappers around the spring lua API. They're incomplete, and most methods return nil or false, but that can be fixed

The concept being that you can create the Shard AI object in your Lua AI, then pass it unit object from Spring by calling a function to make it safe for Shard like this:

Code: Select all

unit = shardify_unit( unitid )
ai:UnitCreated( unit )
There are some stumbling blocks I will need help with though:
  • The standard lua AI has no equivalent to closestbuildsite in the native AI interface, something will need to be added to make build methods work
  • Shard uses the include paths to conditionally load files in subfolders depending on the current game, perhaps the require statements should be swapped out or modified to remove this functionality and make it more portable and less dependent on that kludge of the C++ API I built
  • Where exactly would I store the files in an archive? I have a get config folder method that needs to return a path, and I'm unsure what would be best practice here, is it something that would change on a use by use basis?
For the most part, the rest is a basic todo list of adding the necessary methods to the objects that are implemented in the C++ version so that things aren't broken, adding a map feature wrapper, and resource object wrappers ( pretty basic to do ), and setting up a test lua AI that loads Shard and verifies all is working as expected. A function that returns the engine native data, without the Shard wrapping would be handy. It's not hard work but it's stuff I'm not thoroughly familiar with. I've made a start and will try to do what I can, but there are bound to be parts that don't work as I think they do, or fail subtly, or need some expertise to resolve

The benefit of this is that it also simplifies implementing the API to get the AI working on non-Spring game RTS engines,
User avatar
1v0ry_k1ng
Posts: 4656
Joined: 10 Mar 2006, 10:24

Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey

Post by 1v0ry_k1ng »

I'm looking to continue the Shard ZK config, to help spark the growing AI competition there.

Is there any kind of GUI/config editor, like there used to be? Or are we now down to editing the text files?

Cheers!
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey

Post by AF »

Back to the lua files, I'm surprised there's no standard lua format for defining a build order, but I guess the things in taskqueues.lua is the closest I'm aware of. If there was, why hasn't anyone built a widget to record them!

If you've any lua knowledge though, I'd appreciate any help I can get in filling in the various empty API calls with the spring gadget versions, priority number 1 right now is to get Shard up as a lua AI so that content devs can do as they please without distributing binaries around
User avatar
1v0ry_k1ng
Posts: 4656
Joined: 10 Mar 2006, 10:24

Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey

Post by 1v0ry_k1ng »

Is there any documentation?
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey

Post by AF »

For taskqueues? Or for converting to Spring? Or more in depth? There's a lot of stuff in and around this thread, there may be some stuff on darkstars.co.uk, I really need to compile it all into one place :/ Ofcourse you could always just ping me on whichever IM network you prefer
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey

Post by AF »

I've started collecting various Shard docs and sayings from this thread at http://shard.tomjn.com as well as some things from darkstars.co.uk. I'm categorising as I go along, and will be updating over the week, there's 4 or 5 posts so far covering the basics. Anything not in this thread people have, if you can help me out by linking to it that'd be awesome, or if there's something people would like me to cover specifically or a how to?

I'm also considering once the LuaAI changes are tested and working, to move the version number to Shard 1.0 Tolerating Kitten
User avatar
1v0ry_k1ng
Posts: 4656
Joined: 10 Mar 2006, 10:24

Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey

Post by 1v0ry_k1ng »

A high level breakdown of how eg. the BA shard profile works would be lovely, as that is going to be my start point.

My objective is to make a simple but robust AI for ZK that likes to amass groups of medium tanks and flatten things with them.

Behaviors I would like to implement below- are these possible with current framework?

When using a certain raider, AI tries to move unit as close as possible to target.

When commander, economy or artillery unit is attacked, all units within a radius receive a fight command to its position.

Intelligently withdraw units with below 50% HP and repair them with the closest con, and retreat groups after they take a certain number of losses.

Build fighters and keep them at base. When enemy air unit is detected, air units receive attack order on enemy air units if in an area with low threat - and grounded at base if in area with high threat (to prevent flying over enemy porc).

At certain steps in the game, stop sending attack waves and amass a much bigger wave before attacking.
User avatar
Anarchid
Posts: 1384
Joined: 30 Nov 2008, 04:31

Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey

Post by Anarchid »

All of this is possible. The real oppression is figuring out why recent games with Shard desync in ZK.
User avatar
Anarchid
Posts: 1384
Joined: 30 Nov 2008, 04:31

Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey

Post by Anarchid »

All of this is possible. The real oppression is figuring out why recent games with Shard desync in ZK.
lamer
Posts: 153
Joined: 08 Mar 2014, 23:13

Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey

Post by lamer »

The real oppression is figuring out why recent games with Shard desync in ZK.
sethaven is an issue (it's probably not something sent across network to other clients). UI CMD_sethaven should be invoked somehow instead, but i don't see how to do it.

What bothers me is this spam in ZK:

Code: Select all

[f=0016584] <SkirmishAI: Shard  (team 2)>: ....0/AI/Skirmish/Shard/dev/ai/ZK/attackerbehaviour.lua:48: attempt to index a nil value
stack traceback:
	[C]: ?
	[C]: ?
	....0/AI/Skirmish/Shard/dev/ai/ZK/attackerbehaviour.lua:48: in function 'AttackCell'
	...ine/100.0/AI/Skirmish/Shard/dev/ai/attackhandler.lua:102: in function 'DoTargetting'
	...ine/100.0/AI/Skirmish/Shard/dev/ai/attackhandler.lua:19: in function 'Update'
	....spring/engine/100.0/AI/Skirmish/Shard/dev/ai/ai.lua:34: in function <....spring/engine/100.0/AI/Skirmish/Shard/dev/ai/ai.lua:26>
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey

Post by AF »

AI chat messages are not real chat messages. They're unsynced and local entirely to the instance the AI is running on, and shouldn't be used to communicate with gadgets and widgets in Spring.

There are also fundamental issues with the sendtocontent function. It currently does not work, and I do not understand why, but I know the problem is somewhere inside AI interface, be it at the engine side, or the wrapper side, but nobody has ever gotten it working in Shard, all the examples are provided as is with no explanation, and make use of a completely different API ( I use the C++ API, all the examples use the legacy C API ). It's beyond my current area of expertise to fix

If your gadgets are expecting to pick up the sethaven message, then they will never receive it. I anticipate this is a problem for all AIs that run via the native API.

I'm also not intimately familiar with how the ZK and BA subfolders work, they have modifications I haven't looked at yet as i wasn't the person who wrote them, so I can't give an authoritative overview on them

A purely ZK based solution will be necessary for Shard in its current incarnation to work with the sethaven message (aka not require Shard to send it)
lamer
Posts: 153
Joined: 08 Mar 2014, 23:13

Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey

Post by lamer »

There are also fundamental issues with the sendtocontent function. It currently does not work, and I do not understand why
Tested with 100.0 engine, added "Spring.Echo("Hello sethaven!")" into gadget (ZK) that expects sethaven and "Hello sethaven!" was printed. My conclusion: sendtocontent works.
Steps to reproduce (sorry, too lazy to write clean example):
1) $ cd ~/.spring/games && git clone https://github.com/ZeroK-RTS/Zero-K.git Zero-K.sdd
2) Add Spring.Echo("Hello sethaven!") into Zero-K.sdd/LuaRules/Gadgets/cmd_retreat.lua (in HandleLuaMessage function)
3) Run "Zero-K $VERSION" game and as soon as AI finishes caretaker "Hello sethaven!" will appear in console

Or did you mean sendtocontent doesn't work with dev version of engine?
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey

Post by AF »

I'm unfamiliar with the gadget end of that equation, it may not be the correct callin. Can you set it to print out a piece of information that could only have come from Shard rather than a hardcoded string?

e.g.

Code: Select all

function gadget:RecvSkirmishAIMessage(aiTeam, dataStr)
	Spring.Echo( dataStr )
	HandleLuaMessage(dataStr, aiTeam);
end
My understanding is that anything synced that needs to happen needs to be done in the gadget, the message itself shouldn't be the synced command, ofcourse I may be mistaken. My official recommendation would be to build things so that using sendtogamecontent is unnecessary to begin with
lamer
Posts: 153
Joined: 08 Mar 2014, 23:13

Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey

Post by lamer »

Bad hardcoded example, sorry.
Tested Spring.Echo( dataStr ) in RecvSkirmishAIMessage - console displays everything i send with game:SendToContent( dataStr ). Thus again, it works.
I'm not strong in synced/unsycned code, but my assumption is that sethaven must be synced with other clients. To achieve that either gadget after recieving "sethaven" from nativeAI must send some command over network, or nativeAI must send it somehow without even calling sendtogamecontent (like Unit::ExecuteCustomCommand).

Therefore to me Lua<->nativeAI interaction seems only valuable for reading data (99.0+ can return strings), not writing.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey

Post by AF »

My thoughts are that when the gadget receives the message, it issues the command, and it's the command that does the functionality. If it makes the changes directly, no command is sent, so the other clients never recieve the command, and never act upon it. Meaning that the machine the AI runs on acts on the AI message, but the others don't
Post Reply

Return to “AI”