Shard 0.4/dev - Page 29

Shard 0.4/dev

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

Moderators: hoijui, Moderators

User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey

Post by Forboding Angel »

Go ahead, be a douche.
abma
Spring Developer
Posts: 3798
Joined: 01 Jun 2009, 00:08

Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey

Post by abma »

sorry, i couldn't resist.

but as conclusion: imo at best: if you find a bug/problem with shard, make a report at https://github.com/Tarendai/Shard/issues and then AF or me will try to fix / apply... at best, make a pull request, but that isn't really needed to change a few lines.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey

Post by Forboding Angel »

Abma, I was talking to AF, not you. Sorry for the confusion.
User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey

Post by yuritch »

Should api.new_vectorFloat() work in Shard included with 94.1? It causes an error.

What I'm trying to do is this:

Code: Select all

function BomberBehaviour:BombPosition(position)
	local CMD_ATTACK = 20
	local floats = api.new_vectorFloat()
	-- populate with x, y, z of the position
	table.insert(floats, position.x)
	table.insert(floats, position.y)
	table.insert(floats, position.z)
	self.unit:Internal():ExecuteCustomCommand(CMD_ATTACK, floats)
end
Result:

Code: Select all

attempt to call field 'new_vectorFloat' (a nil value)
Why I'm trying this: Shard lacks an Attack(position) command for units. I tried using Attack(unit) to order bombers, but order is immediately canceled - looks like the engine resets it for units the team doesn't see (or maybe for some other reason). Attack gound would work in that case.
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 »

Referring here:

https://github.com/Tarendai/Shard/blob/ ... /API/api.i

The vector float isnt a part of the api module. Wether this means you should call new_vectorFloat instead of api.new_vectorFloat I don't know, you'd have to refer to the SWIG documentation. It was never quite clear to me what it should be....

Another thing to note is that the resulting object is not a lua table, but a C++ std::vector<float> object, and so table.insert probably won't work on it. You'll want to use push_back on that object instead

something along these lines:

Code: Select all

floats:push_back( position.x )
User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey

Post by yuritch »

Doesn't initialize without api as well:

Code: Select all

attempt to call global 'new_vectorFloat' (a nil value)
Would it be possible to add an Attack(Position) to IUnit object instead? It only has Attack(IUnit).
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 is indeed possible, though ironing out how to use custom commands would be handy too

try:

Code: Select all

local floats = api.vectorFloat()
User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey

Post by yuritch »

Thanks, AF! That did it. Now my bombers work.

Working code is as follows:

Code: Select all

function BomberBehaviour:BombPosition(position)
	local CMD_ATTACK = 20
	local floats = api.vectorFloat()
	-- populate with x, y, z of the position
	floats:push_back(position.x)
	floats:push_back(position.y)
	floats:push_back(position.z)
	self.unit:Internal():ExecuteCustomCommand(CMD_ATTACK, floats)
end
This causes units to attack ground at the specified position. Of course I have some other code to stop them doing so when the target is dead :)
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 wondering what people think of a more Backbone-esque style of object, so that this:

Code: Select all

LowEnergyBehaviour = class(Behaviour)

function LowEnergyBehaviour:Init()
	self.active = false
	self.underfire = false
end

function LowEnergyBehaviour:UnitIdle(unit)
	if unit:Internal():ID() == self.unit:Internal():ID() then
		if not self:IsActive() then
			res = game:GetResourceByName("energy")
			if res == nil then
				game:SendToConsole("res == nil in LowEnergyBehaviour")
		else
			if res.reserves == 0 then
				self.underfire = true
				self.unit:ElectBehaviour()
			end
		end
	else
		self.underfire = false
		self.unit:ElectBehaviour()
	end

	end
	if unit:Internal():ID() == self.unit:Internal():ID() then
		if self:IsActive() then
			self.unit:ElectBehaviour()
		end
	end

end

function LowEnergyBehaviour:Activate()
	self.underfire = false

	local s = self.unit:Internal():Build("esolar2")
	if s then
		self.active = true
	else
		self.unit:ElectBehaviour()
	end
end

function LowEnergyBehaviour:Deactivate()
	self.active = false
	self.underfire = false
end

function LowEnergyBehaviour:Priority()
	if self.underfire == true  then
		return 110
	end
	return 0
end
Would look more like this:

Code: Select all

LowEnergyBehaviour = Shard.behavior.extend( {
	init = function()
		self.active = false
		self.underfire = false
	end,

	unitidle = function( unit )
		if unit:Internal():ID() == self.unit:Internal():ID() then
			if not self:IsActive() then
				res = game:GetResourceByName("energy")
				if res == nil then
					game:SendToConsole("res == nil in LowEnergyBehaviour")
			else
				if res.reserves == 0 then
					self.underfire = true
					self.unit:ElectBehaviour()
				end
			end
		else
			self.underfire = false
			self.unit:ElectBehaviour()
		end

		end
		if unit:Internal():ID() == self.unit:Internal():ID() then
			if self:IsActive() then
				self.unit:ElectBehaviour()
			end
		end
	end,

	activate = function()
		self.underfire = false

		local s = self.unit:Internal():Build("esolar2")
		if s then
			self.active = true
		else
			self.unit:ElectBehaviour()
		end
	end,

	deactivate = function()
		self.active = false
		self.underfire = false
	end,

	priority = function()
		if self.underfire == true  then
			return 110
		end
		return 0
	end
})

Thoughts? Is this a good direction to go in?
User avatar
Zealot
Posts: 94
Joined: 03 Dec 2012, 13:53

Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey

Post by Zealot »

Hi AF, and others. Shard looks amazing.

I am trying to set it up so that I can play test a mod I am working on. It looks like it should be quite easy to set up with behavior for my mod which is awesome however I am a bit confused as to how to go about it.

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

"Writing AIs With Shard

If you have a prebuilt copy of Shard ( as comes with every install of the Spring Engine ), you don't need to build Shard to use it, you need only a text editor and knowledge of lua."

I am working on Mac Os.

I have a text editor and a basic understanding of Lua.

From what I have read, to get shard to work for my mod I basically need to set up the taskqueues and attackers files, in spring/ai/shard/mymodname/


In my spring/ai and all subfolders there is no shard directory and nothing to do with shard.

I assumed there would be shard subfolder inside spring/ai/skirmish however there is not.

When I play spring I can select shard as an AI.

I just played a single player game of EVO vs shard, so shard is installed on my computer?

Am i missing something?

I have spent about 6 hours last night and today trawling through the 29 pages of forums posts here, and the wiki and the nota shard forums topic but so now i ask for help...
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 wasn't aware Spring ran on Mac OS 9, perhaps you mean OS X?

There is no reason I'm aware of that Shard cannot work on OS X but, I have little knowledge of the state of Spring for OS X, I dont know how recent the build is, what it comes with, and from the few experiences I've had, lobby support is pitiful, or relies on mechanisms that are broken for security reasons ( e.g. weblobby + java applets being messed up by Apple induced Java security changes ).

So I do not know if Shard was built and distributed with Springs OS X builds, I've never tried to build it with xcode either.

So currently, you actually know more about this than I do, and there really isn't much I can help you with. Perhaps the person doing the OS X builds would be able to help you, I don't know who that is.


Since you can select Shard, perhaps it's present inside the app bundle? In which case you'll want to copy it out and make a new copy of Shard, and rename it to something else, so that you can select the new copy of Shard and modify its files. Simply creating the folders for the lua files in the springrc folders and placing them in there will not work as Shard doesn't look at the Spring Virtual file system ( I don't know how to do this, I dont think anyone else does either )
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey

Post by knorke »

I have little knowledge of the state of Spring for OS X
pnöpel uses Spring on OS X via weblobby. It downloads 91.0 and 94.1 and both work. Except for random bugs and some crashes I would say it is playable.
http://springrts.com/phpbb/viewtopic.php?f=11&t=30226
http://springrts.com/phpbb/viewtopic.php?f=11&t=30305
http://springrts.com/phpbb/viewtopic.php?f=11&t=30647
User avatar
Zealot
Posts: 94
Joined: 03 Dec 2012, 13:53

Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey

Post by Zealot »

Hi. Thanks for both of your responses.

I uses OSX 10.6.8

I should have been more clear.

I use web lobby, and it works well, sometimes does not load on chrome, but does not have a problem on firefox.

The does have a security warning dialoge box, but it works fine.

Yeah there a quite a few random bugs, but mostly spring plays fine on mac



Thanks AF I think your instructions have helped me solve the problem, I found shard inside the app bundle, and have copied it. I think this will work but I have not tested it yet I will update in a few days when I have time to test it properly.

Thanks.

Z
raaar
Metal Factions Developer
Posts: 1094
Joined: 20 Feb 2010, 12:17

Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey

Post by raaar »

I'm gonna try and use shard in my *A mod too.

Any pro tips?
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 »

Spectate good players and steal their start builds for task queues, but add a little redundancy and lee way, so instead of 3 solars, tell it to make an extra one a little later.

Also SublimeText with the lua linting/checker is a big timesaver
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey

Post by Forboding Angel »

Posting in this thread so AF gets an email: http://springrts.com/phpbb/viewtopic.php?f=15&t=30692
User avatar
Zealot
Posts: 94
Joined: 03 Dec 2012, 13:53

Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey

Post by Zealot »

Hi AF.

I've got shard working and it is great.

I will have some more questions in a little while when I start to try and get some more complex behavior out of it.

It has helped me a huge amount in play testing and balancing my game.

Thanks for all the hard work.
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 »

Zealot wrote:Hi AF.

I've got shard working and it is great.

I will have some more questions in a little while when I start to try and get some more complex behavior out of it.

It has helped me a huge amount in play testing and balancing my game.

Thanks for all the hard work.
You have earnt a cookie!


Feel free to email or PM me, I dont get emails from posts in this thread, notify on reply hasnt been turned on for some reason
User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey

Post by yuritch »

Is it possible to have Shard re-calculate metal spot positions in runtime? Metal map can be changed on the fly, but Shard always sees the spots as they were on load time. This post describes the problem a bit more.
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 »

In current Shard no, the spots are grabbed when the Map object is created and cached, and its the cached spots as you correctly surmised that get returned.

The two avenues for fixing this are:
  • Remove caching on the C++ side and always calculate spots everytime its called, and rely on the lua side for any performance caching
  • Add a method to recalculate spots and flush cache
I'm in favour more of the first one. Even though it's more work for other people, it's the most flexible, and option 2 will probably lead to a lot of this:

Code: Select all

recalc spots()
get spots()
Which is wasteful.

What do you think?
Post Reply

Return to “AI”