Jump to content

Ai Bot


Recommended Posts

Hi

I try to make my 1st contribution in AI scripting.

  1. Would you have some tips and tricks? Especially for testing, reproducing scenarios?
  2. I am looking for more examples of use of all the methods of the Entity class
  3. And like to know more about the difference of the methods Entity:setMetaData and the methods like Entity::move

Thank you in advance,

Bye

Link to comment
Share on other sites

I feel a bit lonely here... dry.gif

But here is the google code project for my AI Bot, which I have called the Split Bot, read the description to understand why.

I choose to develop in haXe which is a very structured language which can be "compiled" in javascript code.

Here are the javascript common-api classes in haXe :

http://code.google.com/p/split-bot/source/browse/#svn%2Ftrunk%2Fsrc%2Forg%2Fzeroad%2Fcommon_api

These are haXe "extern"s which will link to the actual javascript classes of 0 A.D. at runtime.

Link to comment
Share on other sites

Hi

Thank you for your answer :)

I am very happy with haxe. It is really something you know...

And I already have an AI Bot running. So now is the part where I am trying to look into Entity objects, I make them move or build and when I'll be comfortable, this will be the time to implement my logic!

Bye!

Link to comment
Share on other sites

If you want my two cents, I'd suggest avoiding modifying the common API files (common-api/base.js class.js, etc) You see, there's no way to be sure that your changes will make it into the source. There's a ton of problems with this. Mainly the risk that your changes will break other bots and incompatibility with other common-api changing bots (RootBot for example.)

Note though, those common-api's could still use a bit of development. If you want to make changes to the source, go ahead and register on trac and submit a ticket/patch.

Are there any pre-compiled files that I could just throw into my install so I can try your bot out?

Link to comment
Share on other sites

Hi gudo, thank you for your interest

If you want my two cents, I'd suggest avoiding modifying the common API files (common-api/base.js class.js, etc) You see, there's no way to be sure that your changes will make it into the source. There's a ton of problems with this. Mainly the risk that your changes will break other bots and incompatibility with other common-api changing bots (RootBot for example.)

I did not modify it, I did haXe extern classes, which is like an import at runtime, but it gives you auto completion and type checking.

Note though, those common-api's could still use a bit of development. If you want to make changes to the source, go ahead and register on trac and submit a ticket/patch.

I just did! :)

There is a mistake in the common api I think: http://trac.wildfire....com/ticket/897

Are there any pre-compiled files that I could just throw into my install so I can try your bot out?

It is just a bit too early, for now it only traces some data...

Thank you for your advice, bye!

And my question remains:

Do you know a place where these javascript classes are documented?

  • Template
  • State
  • Player
  • Map

Edited by lexa
Link to comment
Share on other sites

common-api and testbot were just my first unfinished prototype attempt at a design, so please don't take them too seriously as being perfect or complete or unchangeable :). It's quite possible that they'll be redesigned entirely, if someone comes up with a better way of doing them. Also there's no guarantee of maintaining compatibility with AI scripts, given future changes to the script design or to the engine - we need more experience and a better design before being able to offer stability. The only documentation is this which is very minimal, and even that might change incompatibly.

So the AI design isn't good or stable or documented yet - what we need is for people to experiment with it and identify problems and propose improvements, so that we can hopefully converge on something that works well, eventually :)

Would you have some tips and tricks? Especially for testing, reproducing scenarios?

The autostart command-line options are often useful for testing.

And like to know more about the difference of the methods Entity:setMetaData and the methods like Entity::move

The metadata thing is a way for AI scripts to associate arbitrary AI-specific data with entities (e.g. remembering whether they're meant to be a worker or a soldier etc), with a bit of engine support so you can assign metadata when training units and it will be remembered when the unit actually gets created. All other methods are either examining the entity's state at the beginning of the turn, or issuing commands that will be executed on the next turn.

how to access these methods and structures from javascript

You can't - AI scripts only have access to a snapshot of the simulation state that's passed into some common-api function every turn. (Files like binaries/data/mods/public/simulation/components/AIProxy.js are used when constructing that snapshot, and they're a normal simulation component.)

Link to comment
Share on other sites

Hi

Thank you very much for these tips! It seems ok to me the common-api for now... So far there is only one bug whoch is bothering me ;)http://trac.wildfiregames.com/ticket/897

I would be glad to help improving it. I believe, the haxe "extern" classes are at least a fully typed version of the api. It is easyier to understand I guess.

http://code.google.com/p/split-bot/source/browse/#svn%2Ftrunk%2Fsrc%2Forg%2Fzeroad%2Fcommon_api

I will keep you informed, bye!

Link to comment
Share on other sites

  • 3 weeks later...

Hello

Thank you very much for your encouragement. Back from vacation and back to 0ad.

I am not sure about the decision tree yet, I have several ideas which I am testing... Anyway, I have a clean fully typed classes which map all the classes and objects of the common api (externs in haxe)

I let you know when I have something serious to play with :)

Bye!

Link to comment
Share on other sites

  • 2 weeks later...

Hello

I am about to release the 1st alpha version of the SplitBot AI bot, in haxe here

It beats the other bots with 100% success (I tried about 5 times with each bot), but in fact the defense and attack are not implemented for now. It builds a decent village very quickly and grows a population of 200 workers before sending all "men" to the nearest enemy...

And now I have a question: is it possible to accelerate time for testing the bot? I do not need the rendering during the "acceleration"..

Thank you all,

lexa.

Link to comment
Share on other sites

Hello

I am about to release the 1st alpha version of the SplitBot AI bot, in haxe here

It beats the other bots with 100% success (I tried about 5 times with each bot), but in fact the defense and attack are not implemented for now. It builds a decent village very quickly and grows a population of 200 workers before sending all "men" to the nearest enemy...

And now I have a question: is it possible to accelerate time for testing the bot? I do not need the rendering during the "acceleration"..

Thank you all,

lexa.

maybe this can be useful?

Link to comment
Share on other sites

And now I have a question: is it possible to accelerate time for testing the bot? I do not need the rendering during the "acceleration"..

You can also 'time warp'. When in-game hit Shift-D to open the developer overlay window, select 'Enable time warp', then just hold down space to fast-forward the game.

Link to comment
Share on other sites

That too, though be careful in long games - it effectively stores a saved game every 2 seconds (or every 0.1 seconds if you're holding down space and running 20x faster), so it's a bit slow and can eat up huge amounts of memory :)

Huh, i had no idea. I time-warp a lot.

Link to comment
Share on other sites

Hi lexa,

I'm receiving the following error when attempting to run a match against Splitbot:

<p class="warning">WARNING: JavaScript warning: simulation/ai/splitbot/SplitBot.js line 2102
anonymous function does not always return a value</p>
<p class="warning">WARNING: JavaScript warning: simulation/ai/splitbot/SplitBot.js line 2138
anonymous function does not always return a value</p>
<p class="warning">WARNING: JavaScript warning: simulation/ai/splitbot/SplitBot.js line 2149
anonymous function does not always return a value</p>
<p class="warning">WARNING: JavaScript warning: simulation/ai/splitbot/SplitBot.js line 2189
anonymous function does not always return a value</p>
<p class="warning">WARNING: JavaScript warning: simulation/ai/splitbot/SplitBot.js line 2205
anonymous function does not always return a value</p>
<p class="warning">WARNING: JavaScript warning: simulation/ai/splitbot/SplitBot.js line 2236
anonymous function does not always return a value</p>
<p class="warning">WARNING: JavaScript warning: simulation/ai/splitbot/SplitBot.js line 2246
anonymous function does not always return a value</p>
<p class="error">ERROR: JavaScript error: simulation/ai/splitbot/SplitBot.js line 1
ReferenceError: assignment to undeclared variable $estr
@simulation/ai/splitbot/SplitBot.js:1</p>
<p class="error">ERROR: Failed to load script simulation/ai/splitbot/SplitBot.js</p>

I've tried it with Alpha5, and the latest svn build. Hope you know what it could be - I want the bot to defeat me too :D

Link to comment
Share on other sites

Hi

Thank you for the test

The warnings are ok, I'll check it later, it is due to javascript strict mode and I should fix each error by hand

The error is a problem and I do not have this at home :(

Can you try wirth the latest release of 0ad ?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...