Jump to content

[javascript] Web Worker supported in RMS and AI?


rjs23
 Share

Recommended Posts

Hello, I'm a long time lurker here. I've been watching 0AD progressing and it is a beautiful game. I haven't mod with it very much, but now I got some free times to play around with it.

Anyway, I am curious to know if Web Worker is supported in AI and RMS? Is AI muilti threaded already supported? Having muilti-threaded AI could help with performance in late game.

I'm researching around to begin the AI creation for fun but before I begin, there are several things I would like to know:

1. is there any references document for AI

2. list of deprecated functions that shouldn't be used but exists in game? I would like to try to avoid outdated functions.

3. What are the 0AD AI system's most weakness?

I'm excited to learn how to make AI and possibly contribute something useful!

Link to comment
Share on other sites

Documentation:

And I think the AI's weakness is that it lacks the ingenuity of a human :P That and currently all the AIs are scared of water.

Thanks for the documenation. Thats one challege I'll try to tackle then! *Thumbs up*

I don't know too much about the AI system, but I do know one major factor is serialization. If you start adding multithreaded without much thought, you'll end up causing players to desync.

I'm glad you brought that up. Thats another challenge to tackle: making it multiplayer supported with muiltithreaded without causing out of sync. Before I do that, I want to get familar with concepts that 0AD can offer before I can begin my creation with muiltithreading support. I can't guarantee anything at this point but I want to try. My personal goal is to try to make an AI without it sucking up the main threads as much as possible.

So far, I'm still researching around what 0ad has to offer for muiltithreading. Does it offer JavaScript's Web Work or is there alternative to it?

Edited by rjs23
Link to comment
Share on other sites

For scenarios the defaults are set per-map, for random maps, the non-first-player data is drawn from simulation/data/player_defaults.json

I used player_defaults.json. That works. I changed AI setting to the name of my bot name.

Is there an option to disable outputting warning such as:

WARNING: JavaScript does not always return a value.

Link to comment
Share on other sites

I don't believe so. That particular warning comes straight from SpiderMonkey.

Ok, thats no problem. I'll just get used to it, and fix it later I suppose.

in gameState.getOwnEntities function, what does ent.foundationProgress() do?

Does it return boolean if a unit iss within town radius?

Edit: Nvm I seew what it does. Thats good.

Edited by rjs23
Link to comment
Share on other sites

Those docs are fairly incomplete, I recently did a little bit of updating so they are not incorrect, just missing a lot of useful info.

On the threading issue, the AI system was designed to handle threading very nicely. It will be very easy to thread it without sync issues because of the AIProxy layer which creates a copy of the games state before sending to the AI so the AI will work with a slightly out of date snapshot. What would be less easy would be to not break the profiler which is one of the reasons which this hasn't been done yet. So when writing an AI you can forget about threading completely and sometime later each AI will get a thread.

Link to comment
Share on other sites

I managed to gain understanding to AI system, so it wasn't too hard. Those doc gave me basic understandings about how gameState works and stuff, but yea it needs more stuff to it.

It wouldn't be too bad to have an indepedent thread for each AI to use. Would make the game with qBot (yours) and juBot and demoBot more playable during late game.

I'm still exploring around. I'm using common-api-v2, playing around with juBot which my bot is based off. (juBot lags bit too much for me. Modified how it works a bit and works smoother for now.) Right now, I'm trying to determine how to find out if a unit/object is dead/deleted from the game. entity.position() doesn't seem to do the trick since they aren't updated when they die. registerUpdates() might be something that I am looking for.

Baby-step at a time!

Edited by rjs23
Link to comment
Share on other sites

Note: other/special_trasure_shipwreck_debris, and other shipwreck treasures does not have class to tell its water object.

What is the most correct way for AI to determine that this is a water object and not land? I don't see a class object from it that says its a water object.

I could do it by template name, but I'm afraid that could lead to instability in long run...

Fish has a class called Sea Creature and thats what I'm using in my bot to tell its a water related food.

Link to comment
Share on other sites

EntityCollection.prototype.addEnt

EntityCollection.prototype.removeEnt

They add/remove entity to/from the entityCollection right? When I try to use removeEnt function from the entityCollection, i will get an error that says ent.id() is undefined. I'm trying ot oragnize an entityCollection and filtering out the useless one and save it later for future reference but base.js() keeps messing up for some reason.

addEnt works fine for me so far but it seems removeEnt may be broke? I don't know, it may be my error.

Edit: I'm using common-api-v2

I'm trying to use removeEnt to keep the alive units only. When they die, removeEnt will be called to remove them.

Edit2: It's not really big of a problem but I'm just curious if those thing usable and stable enough for AI people.

Edited by rjs23
Link to comment
Share on other sites

  • 2 weeks later...

If you have updating entity collections then dead units will be auto removed. When using removeEnt you must pass it an Entity object. Common-api-v2 is used by all of the current developed bots so should be stable.

I found out why it wasn't working. It turns out that events (when an unit gets created, destroyed or attacked) are little bit confusing. In Created events, it uses different attribute than what Destroyed events use.

In created events, I was using this script to gets its entity

event.msg.entity

but in destroyed events, its

event.msg.entityObj._entity

but I was using

event.msg.entity instead of event.msg.entityObj._entity for destroyed events. event.msg.entity is not defined in destroyed events type but is defined in created events type. That's what threw me off.

It confused me because I figured

event.msg.entity would work fine with any events but in Destroyed event, it would returns undefined. That is why I was having problem with using removeEnt function because it was actually receiving undefined object. It's working fine now.

Like you said, it must be an Entity object but it was passing as undefined.

Edited by rjs23
Link to comment
Share on other sites

Documentation:

And I think the AI's weakness is that it lacks the ingenuity of a human :P That and currently all the AIs are scared of water.

Look like not all AI will be scared of water anymore. Right now, my AI finally is able to build a dock reliably near fishes ;). Doesn't train any boat yet, but it finally builds a dock. Phew. 0AD's ai system is pretty awesome.

Link to comment
Share on other sites

Not at all, but atm it doesn't have the ability to train any worker/boat yet. I'll add that later on as the AI stabilize first. It's work in progress and also, I haven't fully planned how it should train effectively yet (I need to play 0AD more to learn its gameplay better before I do add it to AI)

However, if you train the worker/boats for the AI, then AI will do the rest.

Other than that, lots of debugs warning and sometime other strange warnings.

How do you want me to upload AI's files?

Edited by rjs23
Link to comment
Share on other sites

Not familiar with AI format. I probably would guess planner? Other seems less clear to me.

Random google grab for behavior tree or BT, I checked to make sure its decent:

http://www.altdevblo...behavior-trees/

Rule based AI is the probably the most intuitive. The original Glest uses a rule based system. Basically it has general directives like gather resources and produce units and then it has other things like when you have this, this is the finite state machine part, then do this. That might mean, when the game is 5 minutes in, and you have 10 units, send them to scout the enemy base. This system tends to rely on the game knowing where your base is as well as likely expansions. So the scout part is basically hard coded to go to your starter base while checking any expansions in between. The AI is given specific rules, hence the name. Rule based is sort of like planner iirc.

I believe that 0 A.D. is set up for a rule based or hierarchical system. It may also be a planner, this is my impression from posts here and playing the game, I don't look at the actual code cause its time consuming.

Here is a more complete list of AI frameworks:

  • Ad-hoc rules
  • Finite State Machine (FSM)
  • Hierarchical FSM
  • Behavior Tree (BT)
  • Planner
  • Utility-based system
  • Artificial Neural Network

Edited by MoLAoS
Link to comment
Share on other sites

here is my bot attachment. Hopefully it should be enough to be able to work on your 0 AD.

Only works in SVN, not alpha 10.

Don't expect it to be fully working bot like qBot yet.

Molas: I'm reading your post, give me a moment to understand the BT concept.

arBot.zip

Edited by rjs23
Link to comment
Share on other sites

Random google grab for behavior tree or BT, I checked to make sure its decent:

http://www.altdevblo...behavior-trees/

Rule based AI is the probably the most intuitive. The original Glest uses a rule based system. Basically it has general directives like gather resources and produce units and then it has other things like when you have this, this is the finite state machine part, then do this. That might mean, when the game is 5 minutes in, and you have 10 units, send them to scout the enemy base. This system tends to rely on the game knowing where your base is as well as likely expansions. So the scout part is basically hard coded to go to your starter base while checking any expansions in between. The AI is given specific rules, hence the name. Rule based is sort of like planner iirc.

I believe that 0 A.D. is set up for a rule based or hierarchical system. It may also be a planner, this is my impression from posts here and playing the game, I don't look at the actual code cause its time consuming.

Here is a more complete list of AI frameworks:

  • Ad-hoc rules
  • Finite State Machine (FSM)
  • Hierarchical FSM
  • Behavior Tree (BT)
  • Planner
  • Utility-based system
  • Artificial Neural Network

If i understand correctly, I would say that its mixtures of:

1. Hierarchical FSM or Behavior tree, (example: if there is a building foundation and this worker is capable of building it, then assign this worker. If not, then make this worker to gather something. This also can be events-driven type of action )

2 .Planner (example: picking which buildings to be used that are best for this civilization then customize the AI behavior later on ) This would usually happens initially.

3. Rule based (example: worker can't build too far, worker can't gather resource far away, can't build dock if there is no fish)

So far it would be Planner at the start of the game, then it would become combination of FSM/Behavior Tree/Rule Based ai format. That's how I would see in my AI once it evolves.

I hope that answered to your question. :boredom:

One file of your code is formatted badly but the rest looks pretty typical I guess. I don't know specifically what various functions do but based on the name you can sort of guess.

I expect it to be vague lol. its formatting reveal what kind of habit I have: laziness :lol2:

I don't expect people to use my code at this point because, well, its very immature at this point.

Edited by rjs23
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...