IPB Style© Fisana

Jump to content


[javascript] Web Worker supported in RMS and AI?


  • Please log in to reply
34 replies to this topic

#1 rjs23

rjs23

  • Community Members
    Pip

  • Discens
    (95 posts)

Posted 30 July 2012 - 07:04 PM

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!

#2 Geek377

Geek377

  • Web Development Team

  • Primus Pilus
    (1,720 posts)

Posted 30 July 2012 - 10:04 PM

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.
The Geek [ aka Geek377]
Wildfire Games Webmaster
Contact me: Posted Image Posted Image

#3 k776

k776

  • Open Source Development Manager

  • Centurio
    (663 posts)

Posted 30 July 2012 - 10:07 PM

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.

Kieran P [ aka k776 ]
Wildfire Games Open Source Development Manager
Contact me: kieran@wildfiregames.com


#4 rjs23

rjs23

  • Community Members
    Pip

  • Discens
    (95 posts)

Posted 30 July 2012 - 10:35 PM

View PostGeek377, on 30 July 2012 - 10:04 PM, said:

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*

View Postk776, on 30 July 2012 - 10:07 PM, said:

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, 30 July 2012 - 10:39 PM.


#5 rjs23

rjs23

  • Community Members
    Pip

  • Discens
    (95 posts)

Posted 31 July 2012 - 12:32 AM

Got my first AI build going. So far so interesting. I'm curious to know how to change default AI selection in game creation menu?

#6 Deiz

Deiz

  • WFG Programming Team

  • Princeps Civitatis
    (76 posts)

Posted 31 July 2012 - 12:55 AM

For scenarios the defaults are set per-map, for random maps, the non-first-player data is drawn from simulation/data/player_defaults.json
Deiz
Wildfire Games Programmer
Contact me: deiz@wildfiregames.com

#7 rjs23

rjs23

  • Community Members
    Pip

  • Discens
    (95 posts)

Posted 31 July 2012 - 02:53 AM

View PostDeiz, on 31 July 2012 - 12:55 AM, said:

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.

#8 Deiz

Deiz

  • WFG Programming Team

  • Princeps Civitatis
    (76 posts)

Posted 31 July 2012 - 03:56 AM

I don't believe so. That particular warning comes straight from SpiderMonkey.
Deiz
Wildfire Games Programmer
Contact me: deiz@wildfiregames.com

#9 rjs23

rjs23

  • Community Members
    Pip

  • Discens
    (95 posts)

Posted 31 July 2012 - 05:51 PM

View PostDeiz, on 31 July 2012 - 03:56 AM, said:

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, 31 July 2012 - 07:42 PM.


#10 quantumstate

quantumstate

  • WFG Programming Team

  • Primus Pilus
    (1,086 posts)

Posted 31 July 2012 - 10:07 PM

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.

Jonathan Waller [ aka quantumstate ]

Wildfire Games AI Scripter
Contact me: jonathanmarkwaller at gmail dot com


Support Wildfire Games!


#11 rjs23

rjs23

  • Community Members
    Pip

  • Discens
    (95 posts)

Posted 31 July 2012 - 10:37 PM

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, 31 July 2012 - 10:41 PM.


#12 rjs23

rjs23

  • Community Members
    Pip

  • Discens
    (95 posts)

Posted 01 August 2012 - 02:07 AM

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.

#13 gudo

gudo

  • Community Members
    PipPipPip

  • Duplicarius
    (228 posts)

Posted 01 August 2012 - 05:21 AM

Submit a patch that adds "IsWaterObject" class or something to the relevant objects (it is a useful distinction IMO) and then code around that.
Did you contribute to 0 AD?
Make sure you're in the credits!


AI Players
JuBot | RootBot | SplitBot | qBot | Marilyn | arBot

#14 rjs23

rjs23

  • Community Members
    Pip

  • Discens
    (95 posts)

Posted 01 August 2012 - 10:36 PM

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, 02 August 2012 - 01:34 AM.


#15 quantumstate

quantumstate

  • WFG Programming Team

  • Primus Pilus
    (1,086 posts)

Posted 16 August 2012 - 09:40 PM

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.

Jonathan Waller [ aka quantumstate ]

Wildfire Games AI Scripter
Contact me: jonathanmarkwaller at gmail dot com


Support Wildfire Games!


#16 rjs23

rjs23

  • Community Members
    Pip

  • Discens
    (95 posts)

Posted 16 August 2012 - 11:37 PM

View Postquantumstate, on 16 August 2012 - 09:40 PM, said:

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, 17 August 2012 - 06:15 AM.


#17 rjs23

rjs23

  • Community Members
    Pip

  • Discens
    (95 posts)

Posted 17 August 2012 - 06:06 AM

View PostGeek377, on 30 July 2012 - 10:04 PM, said:

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.

#18 Gen.Kenobi

Gen.Kenobi

  • 0 A.D. Art Team

  • Centurio
    (703 posts)

Posted 18 August 2012 - 02:15 AM

View Postrjs23, on 17 August 2012 - 06:06 AM, said:

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.
Awesome! Do you mind uploading it for us to try it? :D
Daniel Schubert [ aka Gen.Kenobi]

Wildfire Games 3d Artist
Contact me: daniel[at]wildfiregames.com


Vote for 0 A.D. in the 2012 Indie of the Year awards!
Posted Image

Posted Image
Visit Revora Creative Network! : )

#19 rjs23

rjs23

  • Community Members
    Pip

  • Discens
    (95 posts)

Posted 18 August 2012 - 02:39 AM

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, 18 August 2012 - 02:40 AM.


#20 MoLAoS

MoLAoS

  • Community Members
    Pip

  • Discens
    (54 posts)

Posted 18 August 2012 - 02:54 AM

Can I ask what AI format you use? Planner, hierarchy, utility, behavior tree?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users