Shard 0.4/dev - Page 7

Shard 0.4/dev

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

Moderators: hoijui, Moderators

Post Reply
User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

Re: Shard

Post by yuritch »

Looks like the changes in ai.lua have broken my overrides as well (namely moving the includes from AI:Init() to require block, so now ai object is not initialized when my scripts run). That's easy to fix however (and maybe with the new resource object and unit-list-as-lua-table thing my hacks won't be needed anymore).
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Shard

Post by AF »

note that ai.lua can be overridden as well now thanks to that change, you can take the lua files form the previous Shard and put them in your folder and huzzah you have the previous Shard but with extra API additions while you port your code forward. Just remember to modify the function in ai.lua that loads custom game overrides accordingly.
User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

Re: Shard

Post by yuritch »

If I just place ai.lua from Shard 0.21 into my mod_name folder, overrides still crash AI (so looks like 0.25 ai.lua is still used). So I modified the 0.25 ai.lua to be more like the 0.21 (by moving the includes into AI:Init(), in theory that should not break it) and now the game starts.

However now I'm getting spring crashes at about game frame 4600 - 4800 with infolog pointing to Shard\0.25\SkirmishAI.dll at the top of stack (so the crash is probably in there). I'm trying to find out if those are caused by my overrides and modifications.

Edit: looks like attempt to get the resource object causes the crash. Trying to figure if I'm just doing it wrong...

Edit2: found it. This code causes error (I modified it a bit so it doesn't crash the dll now, error stays in lua):
"attempt to index global 'tmpRes' (a userdata value)"

Code: Select all

	i = game:GetResourceCount()
	game:SendToConsole("GetResourceCount: "..i)
	for j = 1, i do
		tmpRes = game:GetResource(j)
		game:SendToConsole(tmpRes.name)
	end
So whatever GetResource() returns doesn't quite seem to be a table.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Shard

Post by AF »

GetResource returns a userdata type object of type SResource.

Also keep in mind you are using lua array assumptions of indices starting at 1. Whereas these API calls reference a C++ structure, starting at index 0.

I should have a GetResources in the next version containing each resource in a table
User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

Re: Shard

Post by yuritch »

So it's 0-based. Might be worth it to mention that in the api.lua or some other doc somewhere.

So, if the resource object is not a table, how do I use it then? Most of your other objects are documented as containing only functions in api.lua, so I can call those functions, but resource object (and also Position object) only contain properties? And an attempt to get those properties with the dot notation (as well as with the array notation, like tmpRes["name"]) fails.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Shard

Post by AF »

It should be enough to do something along the lines of:

Code: Select all

local rcount = game:GetResourceCount()

for i = 0,rcount do
    res = game:GetResource(i)
    if name ~= "" then
        game:SendToConsole(res.name)
    end
end
But I'd ideally want to be able to do:

Code: Select all

local resources = games:GetResources()

for name,resource in pairs(resources) do
    game:SendToConsole(name)
end
Note that I haven't tested that code, and I can make no guarantees. You can use the first bit of code to modify api.lua to add a GetResources that behaves the way the second piece of code does, since the game variable, is a table wrapping around game_engine, and game_engine is the object that all the C++ functions/methods are attached to.

As a side note, since when Shard is released in source, it'll be LGPL, BUT, since the lua code is already released, which constitutes a considerable proportion of Shards source code, that lua code will be licensed under LGPL also.

Also note that I consider the two separate projects, the Shard AI, and the Shard C++ binary. It is only the binary that is currently a problem in the developers forum.
User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

Re: Shard

Post by yuritch »

I tried your first example, and (just like with my own code) this is what I get:

attempt to index global 'res' (a userdata value)

Line number in the error string points to this line:

Code: Select all

game:SendToConsole(res.name)
(also, I think this:

Code: Select all

if name ~= "" then
should instead be this:

Code: Select all

if res.name ~= "" then
, but it doesn't work either way)

So, in short. Any attempt of accessing any properties of a resource object (like res.name, res.income, etc.) causes error. Looks like something is missing on the C++ side.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Shard

Post by AF »

blah it mustn't like member data variables that arent wrapped up in public accessor methods. For now all I can think of trying is accessing the other variables that are numeric, or adding :c_str() to the end, since name is of type std::string internally.
User avatar
romulous
Posts: 39
Joined: 31 Jan 2010, 12:36

Re: Shard

Post by romulous »

Just tried this AI. It sent a lot of L1 units in, then both AIs I was playing sent their commanders over and my defences took them out and it was game over. See the replay if you're interested.
Attachments
20100608_135252_Tangerine_0.81.2.rar
(133.36 KiB) Downloaded 21 times
User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

Re: Shard

Post by yuritch »

Shard (as well as most other AIs) has no special consideration for commander, it doesn't know this unit is more important than the rest. Generally playing com. end mode with AIs is a bad idea because of that.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Shard

Post by AF »

I primarily focus on Shard as an AI framework, and although I provide and develop a basic AI that can be modified via behaviour and task queues, there are a lot of possibilities which I either don't have the time to go into, or are not appropriate for me since it would require personal knowledge.

Thus there is nothing stopping someone using Shards framework to create an AI under a new name with extra modules behaviours and code to decide what happens instead of what I have written, so long as they make it clear that Shard was used as it's basis and they follow the license. Any such AI should be released after bI have open sourced shard, for which Im still waiting on the results to know it is safe to release. This should be no later than the 12th of July

The case hoof commanders is one that uniquely affects TA based games, and I simply have not implemented code to protect commanders, as far as Shard is concerned it treats them just like any other unit.

I would suggest adding a new behaviour that tells a commander to retreat to the nearest structure in the event that it is fired upon and a certain number of units are found within a certain radius with weapons. Refer to the evolutionRTS overrides which has a behaviour that makes engineers build turrets when under fire
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Shard

Post by Forboding Angel »

Hey AF, could you add a little didly that would allow us to limit how many buildings of a certain type shard is willing to make?

Like for example, me being able to limit shieldgens to 2, etc
User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

Re: Shard

Post by yuritch »

That's already possible with the current setup, I do it in my config a lot.
You can count existing units of a given type in taskques and return an empty string if you don't want to make any more (AI will complain about not being able to find unitdef for "", but will continue to work). Returning any non-existing unit name also works (but not nil, this will cause lua error).
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Shard

Post by AF »

Actually a task queue should be able to signal a premature ending using a nil value, I'll have to look into that

The best way of doing it would be so that instead of putting the name of the shieldgen in the task queue, you instead put in the name of a function, in the same way that has beenndone to figure out wether to build solars or wind generators in the TA task queues. Then refer to your own overrides for how to store data, this should show you how to store a counter.

Then you have to do a check, check to see how many units of that type are in existence on your team and if there are less than 2, return the shieldgen name, else return something else or an empty string. I intended for it to be a nil but since that's not working I can look into that and summon up a private build for you both
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Shard

Post by AF »

I will know my results by or on the 18th of June

How should I put Shard up on github? Should it be the Shard folder as is, or should it be a full spring directory structure but with only the Shard folders?
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Shard

Post by hoijui »

only the content of the Shard folder, like here:
http://github.com/Error323/E323AI

i guess this means.. we will not get any of the development history from before the day of release? (eg, you do not have it as a git repo now)
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Shard

Post by AF »

I had an svn repository but it is also out of date, but I dont think there is too much to be gained from Shards C++ source code that hasnt already been gained through demonstration
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Shard

Post by zwzsg »

So I tried Shard 0.25, watching 2 Shard in KP 4.0 on Data Cache:
  • I still have the issue of Shard forgetting to give order to builders: idle builders while there are free datavent.
  • One AI let a Pointer unfold and fire while still inside the Kernel, thus blocking it, preventing new unit from being built. How to prevent that?
  • I still don't know how to issue custom order (dispatch). See this PM for details.
  • You are still shipping Shard with an outdated KP config:
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Shard

Post by AF »

I am aware of the out of date files, but I can't do anything about it since I haven't released source code yet and I don't want to deal with flamewars and this thread being locked by GPL jihadists
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Shard

Post by zwzsg »

Oh ok. 18 is soon anyway.
Post Reply

Return to “AI”