Shard 0.4/dev - Page 16

Shard 0.4/dev

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

Moderators: hoijui, Moderators

User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Shard

Post by knorke » 29 Aug 2011, 20:50

keep the drama thread to the drama thread

There is chance that the thread might be usefull to some.
Maybe in some time somebody wants to read about Spring AIs and it would be pretty embarrassing if that person has to wad through all this ot crap?
/edit
yea lol, now it looks like i deleted all that posts?
I did not. When I delete stuff I always put a note and it would be nice if others could do that too..
0 x

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

Re: Shard

Post by AF » 31 Aug 2011, 13:21

Shard has been re-continued due to recent advances.

Details will be posted shortly.
0 x

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

Re: Shard 0.31.1 Not So Ballsey

Post by AF » 01 Sep 2011, 18:30

http://darkstars.co.uk/2011/shard-0-31- ... o-ballsey/

The missing equals sign has been fixed, the BA config is now indented, Cans & Sumos are recognised as attackers in BA, and the name has been adjusted!
0 x

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

Re: Shard 0.31.1 Not So Ballsey

Post by AF » 15 Sep 2011, 16:40

Someone asked for help on how to configure shard from a beginners point of view:

Shard runs off of behaviours, and by default construction units are assigned a TaskQueueBehaviour.

This piece of code looks at a file called taskqueues.lua containing a table that says Unit A will build B,C,D,E,F,then G, repeat.

The reason Shard only builds peewees is because I told it to in taskqueues.lua. To change this you will want to go to the BA subfolder and modify the BA specific taskqueues.lua by adding/removing/re-ordering the unit names listed.

e.g. ai/BA/taskqueues.lua :

Code: Select all

taskqueues = {
	unitname = {
		"unitname",
		"unitname",
		"etc",
	},
	-- e.g.:
	corck = { -- core construction kbot
		"corsolar", -- build a solar
		"cormex", -- then a mex
		"cormex", -- then another mex
		"corllt", -- now a light laser tower
		"corrad", -- now a radar tower
		"corllt", -- another light laser tower
		"corsolar", -- another solar!
		"corllt", -- etc
		"corsolar",
		"cormex",
		"corhlt",
		"cornanotc",
		"corllt",
	},
	armlab = { -- arm kbot lab
		"armck", -- build a con bot
		"armck", -- then build a second one
		"armck", -- then a 3rd
		"armpw", -- now a peewee
		"armpw", -- and then another one
		"armpw", -- and another
		"armpw", -- and another
		"armpw", -- and another
		"armpw", -- and another
		"armpw", -- and another
		"armpw", -- and another
		"armpw", -- and another
		"armpw", -- and another
		"armpw", -- and another
		"armpw", -- and another
		"armpw", -- and another
		"armpw", -- and another
		"armpw", -- and another
		"armpw", -- and another
		"armpw", -- and another
		"armpw", -- and another
		-- all done, now repeat again
	},
}
You might see examples where instead of a table containing a list of things to build, you see the name of a function returning a list of things to build, or a function, or a predefined table ( helps reduce copy pasta if you define it once and then just sue the table name ).
0 x

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

Re: Shard 0.31.1 Not So Ballsey

Post by AF » 26 Sep 2011, 17:22

An update on the current situation regarding Gadget AIs:

http://darkstars.co.uk/2011/shard-gadge ... anagement/
0 x

User avatar
Erik
Posts: 283
Joined: 20 Aug 2009, 20:49

Re: Shard 0.31.1 Not So Ballsey

Post by Erik » 27 Sep 2011, 15:27

How would i make a builder search for map features and reclaim them?
0 x

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

Re: Shard 0.31.1 Not So Ballsey

Post by AF » 27 Sep 2011, 18:15

You can use map:GetMapFeatures() to retrieve all the map features, it can also take 2 parameters, a position, and a radius.

This will return a table of feature objects, which has 3 methods:

Code: Select all

feature = ...
integer feature:ID()
string feature:Name()
Position feature:GetPosition()
You have 2 ways of reclaiming a feature.

Code: Select all

engineunit:Reclaim(feature)
engineunit:AreaReclaim(feature:GetPosition(),10)
If you have requests for extra functions/methods for getting various pieces of data on features, let me by putting in a request here:

https://github.com/Tarendai/Shard/issues

( ps: this isn't a clickety clackety tracker I setup myself that might go boom soon, it's github, it's here to stay! )

May i ask what game you're working on for this?
0 x

User avatar
Erik
Posts: 283
Joined: 20 Aug 2009, 20:49

Re: Shard 0.31.1 Not So Ballsey

Post by Erik » 27 Sep 2011, 18:46

Its called "Void" and it uses economy based on reclaiming, which kinda explains why this part is important.
0 x

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

Re: Shard 0.31.1 Not So Ballsey

Post by AF » 27 Sep 2011, 19:05

Interesting, care to PM me more details? I can think of a few things that might help you out
0 x

User avatar
Erik
Posts: 283
Joined: 20 Aug 2009, 20:49

Re: Shard 0.31.1 Not So Ballsey

Post by Erik » 27 Sep 2011, 19:28

Edit: Got it working

Edit2: The "wait" function for the buildlists does not work, it either cancels everything or has no effect at all.
0 x

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

Re: Shard 0.31.1 Not So Ballsey

Post by AF » 28 Sep 2011, 18:04

Not so ballsey doesn't have that functionality in, unless you're using the git master version? Not so ballsey was intended to fix the syntax error rather than to push out the latest and greatest version.

I take it from your post though that you're making a builder build things then pause so that the autoreclaim behaviour can take control, then yield control when the unit is next idle so it can resume construction?

I've one or two changes I want to make to the behaviour control routines, when a unit becomes idle, rather than handing off to the current active behaviour ( and waiting for said behaviour to do the elect behaviour call ), instead I want the unit object to call the elect behaviour call every single time the unit is idle, and then at regular intervals of every 1-2 seconds if no behaviour desires control.

This should make more sense than what is currently in use with minimal changes.

An active behaviour can then retain its control by raising its priority return value so it retains control. This way if another behaviour urgently needs to intervene, it can do so at the next unit idle call by giving itself a very high priority, e.g. you can make your behaviour check if there's a resource shortage, and if so return some uber high number as it's priority so it will go off to find resources, rather than continue building.


If you could let me take a look at what you've done so I can see and maybe make suggestions? It'd help me see how people are using my APIs and plan accordingly.
0 x

User avatar
Erik
Posts: 283
Joined: 20 Aug 2009, 20:49

Re: Shard 0.31.1 Not So Ballsey

Post by Erik » 30 Sep 2011, 23:04

Bug:
UnitDead is called for every behaviour for each unit in possession of the AI player, i don't think this is intended( i thought it would be called only when a unit with that behaviour dies not for every unit).

In addition it is called for each frame while the unit dies, for example a building with a "topple-over" animation that lasts 30 gameframes would trigger it 30 times, could this possibly be fixed?



Also:
Is there a function to initialize stuff(playstyle for example) for an AI player that is called before everything else?
0 x

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

Re: Shard 0.31.1 Not So Ballsey

Post by AF » 01 Oct 2011, 23:51

Erik wrote:Bug:
UnitDead is called for every behaviour for each unit in possession of the AI player, i don't think this is intended( i thought it would be called only when a unit with that behaviour dies not for every unit).
This is desirable behaviour, for example say unit A, a super uber bomber, needs to attack a fusion reactor, but unit B needs to die first ( specialised super uber bomber killer turret ), a behaviour that made A wait until the defences were down would be impossible if the behaviour was only notified of its own death and not that of others.

In addition it is called for each frame while the unit dies, for example a building with a "topple-over" animation that lasts 30 gameframes would trigger it 30 times, could this possibly be fixed?
This is most certainly a bug, and one in the AI interface at that. You can work around it but an API fix would be a lot better. Talk to Hoijui about this and if he can't sort it, he'll point you to someone who can. If not, let me know what he says ( he'll probably post in this thread now )
Also:
Is there a function to initialize stuff(playstyle for example) for an AI player that is called before everything else?
Yes! They're called Modules, they're like behaviours but they're not attached to anything in particular. Look at the attack system. It has a behaviour for each unit, and a global Module that coordinates.
0 x

User avatar
Erik
Posts: 283
Joined: 20 Aug 2009, 20:49

Re: Shard 0.31.1 Not So Ballsey

Post by Erik » 02 Oct 2011, 19:07

Another bug/strange behaviour thingy:

In the buildques if i call a function that returns nil the build process is stopped altogether instead of just skipping that entry.

Also would help to be able to return "wait" commands.
0 x

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

Re: Shard 0.31.1 Not So Ballsey

Post by AF » 02 Oct 2011, 20:50

You can return wait commands by returning exactly the same thing as what you would put to declare a wait command.

Are you using git master or not so ballsey now?
0 x

User avatar
Erik
Posts: 283
Joined: 20 Aug 2009, 20:49

Re: Shard 0.31.1 Not So Ballsey

Post by Erik » 02 Oct 2011, 21:15

still using the "not so ballsy" one
0 x

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

Re: Shard 0.31.1 Not So Ballsey

Post by AF » 02 Oct 2011, 21:52

There's no wait command in not so ballsey

I advise moving to git master
0 x

User avatar
Erik
Posts: 283
Joined: 20 Aug 2009, 20:49

Re: Shard 0.31.1 Not So Ballsey

Post by Erik » 04 Oct 2011, 16:27

Three more questions:

How would i best keep track of an AIs unit count for example it always wants to have at least 2 builders?

How do i get an AIs ressource pool (with example if possible)?


Is there a function i could call that returns all enemies that the AI can see currently?
0 x

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

Re: Shard 0.31.1 Not So Ballsey

Post by AF » 04 Oct 2011, 20:03

If you refer to a file called preload/api.lua you can see all the calls possible to the game and map objects.

To determine the overrall unit count you can simply count the number of objects returned int he table when calling game:GetFriendlies(), and vice versa for game:GetEnemies()

To count the builders you would either iterate through the returned items and check each if they were a builder, or you can store the value via a module, and increment and decrement on unit created and unit death events. ( latter would be preferable as it's far less intensive )

Here is the current Shard resources API:

Code: Select all

	function game:GetResource(idx) --  returns a Resource object
		return game_engine:GetResource(idx)
	end

	function game:GetResourceCount() -- return the number of resources
		return game_engine:GetResourceCount()
	end

	function game:GetResource(name) -- returns a Resource object, takes the name of the resource
		return game_engine:GetResource(name)
	end

	function game:GetResources() -- returns a table of Resource objects, takes the name of the resource

		local rcount = game_engine:GetResourceCount()
		if(rcount > 0) then

			local resources = {}

			for i = 0,rcount do
				local res = game:GetResource(i)
				if res.name ~= "" then
					resources[res.name] = res
				end
			end
			return resources
		else
			return nil
		end
	end
IMO this portion of the API is lacking, especially with regards to features.
0 x

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

Re: Shard 0.31.1 Not So Ballsey

Post by AF » 05 Oct 2011, 00:10

To clarify things I've made additions that should make you and foreboding/IK happy
  • Added boolean Reclaimable() to feature objects
  • Added float ResourceValue(integer resource_id) to features objects, takes the ID of a resource and returns the amount of resources in said feature left for reclaiming. Returns -1 on error
  • Added float ResourceCost(integer resource_id) to unit definition objects, takes the ID of a resource and returns the amount of resources in said feature left for reclaiming. Returns -1 on error
  • Added float ReclaimSpeed() to unit objects, returns 0 if the unit cannot reclaim. Thus doubles as a CanReclaim method
  • Resource objects returned by calls to the game object now have a subvalue called id for use in aforementioned API calls
  • A minor example for anyone lurking wanting a gadget API port
  • Added game:GetTeamID, returns the ID of Shards current team
  • Added game:GetUnits(), retrieves Shards units, but not allied units
  • Unit objects now have a Team method returning their teamID
  • Experimental MaxWeaponDamage method added to unit objects ( untested, unsure of results as there is no straightforward way of determining the damage a weapon will do via AI API without knowing more details of context)
0 x

Post Reply

Return to “AI”