Author Topic: Bot testbed  (Read 836 times)

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7703
    • View Profile
Bot testbed
« on: April 01, 2017, 11:32:48 AM »
Okay, at long last, I have completed the first iteration of my bot testbed.

What is it?
A simulation with a single bot in it.  This is a very simple base I'm going to use to build more features on top of.

The single bot is a star shaped polygon.  It has "spindles" arranged around its nucleus.  The bot can control the length of these spindles using its DNA.

So far the only features implemented are the spindles.  It can't reproduce or move or do anything else but change its shape.

Overview
It's multithreaded (to a point) with 3 core threads:

  • UI - The UI thread handles button clicks and the like.
  • Simulation - The simulation thread handles running the simulation, running the bot's DNA, etc.
  • Render - The render thread is in charge of drawing the graphics.
Importantly these three threads are independent.  The simulation can run at 10000 cycles/sec and the graphics can run at 5 FPS.  Or the simulation could run at 10 cycles/sec and the graphics could run at 60 FPS.

If one thread crashes, it should largely not cause problems for the other threads.  The simulation thread can continue running in the background if the render thread crashes (as long as it's not frame locked), and vice versa.

Read the DNA help
The DNA langauge that Darwinbots3 uses ("Sunweaver") is similar but distinct from the language in Darwinbots2.  Make sure you read through the Sunweaver manual under the help menu to understand it.  If you want to suggest changes, the raw text for it is here.  Just send me any changes you make to that file.

Help me out
My mission for you guys, if you're willing, is to mess around with this testbed to create bots that do cool things.  Specifically I'd like some bots that move in a way that looks like they're swimming, because I want to try adding fluid to this testbed next, and I want to see if a swimming motion can produce forward motion.

Also, I want to make sure that there aren't any bugs.  If you find crashing bugs, you will get an exception dialog box.  You can see what it looks like by forcing crashes (look under the 'debug' menu).  Copy+paste the exception dialog text and post it here and I can try and reproduce the issue on my side.  Unless you know why it crashed, of course, and it's not a bug. 

Or if you find the interface weird, or have just general comments, please let me know.

What's next
I'm going to start experimenting with adding fluid to this simple testbed.  I'd like to verify that it's possible for bots to swim by manipulating their shapes.

(Edit: I've uploaded a new version that fixes the render thread crashes.  Also changed:
  • Fixed issue that prevented incrementing spindle lengths in the DNA from working.
  • Fixed issue preventing memory from being saved to disk.
  • Added a "numspindles" sysvar.
  • Broke apart pause and play buttons to work the same way they do in DB2.
)
« Last Edit: April 09, 2017, 10:14:19 AM by Numsgil »

Offline spike43884

  • Bot Overlord
  • ****
  • Posts: 656
    • View Profile
    • OurIllogicalWorld Blog
Re: Bot testbed
« Reply #1 on: April 03, 2017, 02:08:07 PM »
Just partway through reading up that sunweaver manual file... I came up with a few ideas for changes, it'd be pretty sweet if you were able to implement them (if they haven't been yet)

One nice thing would be to include tan in mathematical operators (we currently only have sine and cosine), a 'proportional to' operator, and perhaps some sort of support for percentiles? I'd quite like to also see factorials, perhaps shortcuts for some constants (like pi, the golden ratio, eulers constant and so forth) - Some distinguishing between vector and scalar products would be quite useful too I do think. A couple of probability functions in DNA so we don't have to rely on total randomness...

Finally, and deviating from the maths side of things, a "return to line __" function would be quite nice to force part of the DNA to rerun...
Autism can allow so much joy, and at the same time sadness to be seen. Our world is weird, and full of contradiction everywhere, yet somehow at moments seems to come together, and make near perfect sense.

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7703
    • View Profile
Re: Bot testbed
« Reply #2 on: April 03, 2017, 05:50:45 PM »
One nice thing would be to include tan in mathematical operators (we currently only have sine and cosine), a 'proportional to' operator, and perhaps some sort of support for percentiles? I'd quite like to also see factorials... A couple of probability functions in DNA so we don't have to rely on total randomness.

On purpose I've tried to leave the underlying language with relatively few commands, so it's easier to learn and understand.  It's not meant to be fully featured.  Note you can write codules and set up macros with them, so you have a lot of power to make your own commands and use them the same as if they were natively supported.

So for instance, naively you could define a tangent function as:

(edit: Oops, language is still new to me too.  I've modified this to be right, hopefully).
Code: [Select]
{tan dup cos swap sin div }
macro tan @tan

I say naively because you're just doing integer division, and not using the full range of the integer stack, so the error in the calculation here would be quite large.  Which brings me to point two:

Quote
perhaps shortcuts for some constants (like pi, the golden ratio, eulers constant and so forth) - Some distinguishing between vector and scalar products would be quite useful too I do think.

Sunweaver, like the DNA in Darwinbots2, is entirely integer driven.  Pi doesn't make sense in the language, unless you want it to just be 3 :)  You could arbitrarily decide to store as many digits as you could, but that still might not be appropriate depending on what you're trying to do.  For instance, some sort of numerical calculation involving pi might need 100s of digits.  Or it might be fine approximating it as 3.  There isn't really a one size fits all here.  Note that sin and cos, for instance, don't use radians they use degrees (well, degrees / 3). 

Likewise there's nothing inherently vector or not about anything in the language.  Integers get pushed to the stack, and integers get popped from the stack, and integers get written to memory.  How anything is interpreted in between is a question for the programmer.

Quote
Finally, and deviating from the maths side of things, a "return to line __" function would be quite nice to force part of the DNA to rerun...

This is another case where the restrictions are on purpose.  Like in DB2, the entire DNA gets executed, start to end, every cycle.  In order to prevent infinite loops from causing the program to hang, infinite loops are simply impossible.  If I supported gotos, I can't guarantee that a given DNA program would terminate.  As a compromise note that DNA supports a finite looping mechanism.  So you can basically run a loop over some code 100 times, for instance.  But even here, I'm not sure if this is too generous.  It's possible to make some really gross nested loops that can eat all the CPU cycles and slow the simulation to a crawl.  But I think the loops, along with the branching mechanisms, might be an important tool for evolution so I wanted to include them.
« Last Edit: April 04, 2017, 08:09:24 AM by Numsgil »

Offline Shadowgod2

  • Bot Destroyer
  • ***
  • Posts: 379
    • View Profile
Re: Bot testbed
« Reply #3 on: April 04, 2017, 02:09:41 PM »
Primitive it is... i with i could see the memory similarly to db2 but i do have an idea on a swimmer, just after i figure out how the dna works more hopefully i will get a working swimmer in a few days. Looks good.
« Last Edit: April 04, 2017, 03:31:41 PM by Shadowgod2 »

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7703
    • View Profile
Re: Bot testbed
« Reply #4 on: April 04, 2017, 04:57:40 PM »
i with i could see the memory similarly to db2

Yes, on my todo list. :/  If you're really desperate you could save the simulation and inspect the memory in the save file.  The saves are just Lua scripts, and fairly readable.

Offline Shadowgod2

  • Bot Destroyer
  • ***
  • Posts: 379
    • View Profile
Re: Bot testbed
« Reply #5 on: April 05, 2017, 12:43:07 AM »
well this will be a while.. basically learning a proper programing language.. my brain does not compute well  :wacko:.. trying to figure out how to make an ellipse without long handing it... maybe im reaching too high right now and should basically mess with the shape in other ways... if i can make the spindles dependent of each other that would be a good start.

cant wait for evolution to do this for me.. :D jk

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7703
    • View Profile
Re: Bot testbed
« Reply #6 on: April 05, 2017, 05:07:27 AM »
Ellipses are hard, haha, but I managed it.  Set this to 120 segments:

Code: [Select]
{rdiv swap div }
{square dup mul }
{gulp 0 store } ' clear out the integer stack by one element
macro rdiv @rdiv
macro square @square
macro gulp @gulp
const a 500
const b 501
const theta 502

' Ellipse equation is
'                         a * b
' ------------------------------------------------
'  sqrt( (b * cos(theta))^2 + (a * sin(theta))^2 )
{ellipse
.b
.a
.theta
*theta cos *b mul square
*theta sin *a mul square
add
sqrt
*a *b mul
9999 mul
30 mul
rdiv
} gulp

120 { dup
9 mul ' Get in range [0, 1080]
' cos 0 max 1000 add ' Not an ellipse but interesting!
5 3 @ellipse
swap store } loop

There's probably a much simpler way to get an ellipse, but I don't know it!

Note that this will crash the renderer at around 60 bot segments.  I've already made a note of it.
« Last Edit: April 05, 2017, 05:09:41 AM by Numsgil »

Offline Shadowgod2

  • Bot Destroyer
  • ***
  • Posts: 379
    • View Profile
Re: Bot testbed
« Reply #7 on: April 05, 2017, 09:09:24 AM »
seems to make mine crash from the start :/

Offline spike43884

  • Bot Overlord
  • ****
  • Posts: 656
    • View Profile
    • OurIllogicalWorld Blog
Re: Bot testbed
« Reply #8 on: April 05, 2017, 11:59:54 AM »
Ahh I understand the intentions for simplifying things.
For finite loops, I'm not sure you need code for that, you can just make repetitions of DNA to loop with any checks needed. Then it prevents easy setting up of huge loops, and shows truly how long a bots DNA is.

A few quick questions - Will bots be able to stick to things, like ties do in DB2, and will they be able to stick to "shapes" or such? Also, are shapes going to be reworked at all, perhaps being able to have some extra properties of their own like buoyancy or mass (allowing pushing of shapes by bots)?
Autism can allow so much joy, and at the same time sadness to be seen. Our world is weird, and full of contradiction everywhere, yet somehow at moments seems to come together, and make near perfect sense.

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7703
    • View Profile
Re: Bot testbed
« Reply #9 on: April 05, 2017, 02:22:02 PM »
seems to make mine crash from the start :/

Bleh, mine too.  This seems to have exposed quite a number of different bugs.  Give me a few days or weeks to fix it.  In the mean time, if you go to your Documents folder, and find Darwinbots3, and rename or delete .lastexit.lua, you can sort of "factory reset" things.  Then, if you start the Bot Testbed again, set the number of spindles to 120, and copy+paste the DNA I showed, it should work.

Quote
For finite loops, I'm not sure you need code for that, you can just make repetitions of DNA to loop with any checks needed. Then it prevents easy setting up of huge loops, and shows truly how long a bots DNA is.

I'm not sure exactly what you mean.  Do you mean just copy+paste the code over and over and get rid of loops entirely?  Although they come with a lot of baggage, I think allowing some simple looping will make for some interesting evolution.

Quote
Will bots be able to stick to things, like ties do in DB2, and will they be able to stick to "shapes" or such?

Yes, eventually, but I don't know how it will work yet.  Probably the vertices of the bot's polygon, the ends of the "spindles", can form anchors against other bots and shapes in the environment.  But I probably won't have springy ties like in DB2.  The bots themselves, since they can change shape, can act as the springs for most multibot type things you'd want to build.

Quote
are shapes going to be reworked at all, perhaps being able to have some extra properties of their own like buoyancy or mass (allowing pushing of shapes by bots)?

Yes they'll be reworked.  One of the archetypes I'm working towards is an "ant" bot that can make colonies by digging out shapes.  Probably also, in addition to nrg, bots need some physical substance (ie: nutrients) to grow that they can only get from shapes.  From some light research, it seems a large part of why rain forests are so biodiverse is that they're energy rich but nutrient poor, so I want to be able to simulate that.

I'm not sure of the specifics yet, but my thought is basically that when a dead bot decays, it leaves behind inorganic blobs that can float around in the sim.  Blobs that touch each other stick together, so over time blobs will combine together to form larger and larger shapes.  Something like that.

Offline Shadowgod2

  • Bot Destroyer
  • ***
  • Posts: 379
    • View Profile
Re: Bot testbed
« Reply #10 on: April 05, 2017, 09:36:01 PM »
well probably same bug as above but it might be easier to find the bugs... idk i'm not a programmer but if you set the seg number to 5 the rendering crashes at 13. seems to only be 13 but you'll have to play with it

macro seg 5
seg 2 div { dup seg 2 div add swap seg add swap store } loop


seg is the number of segments btw... now to figure out how to mirror to the other side

also how do you read the memory of a location like this:

120 { dup (get memory of said location, modify it) swap store } loop
« Last Edit: April 05, 2017, 11:42:19 PM by Shadowgod2 »

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7703
    • View Profile
Re: Bot testbed
« Reply #11 on: April 06, 2017, 04:30:41 AM »
also how do you read the memory of a location like this:

120 { dup (get memory of said location, modify it) swap store } loop

You can use the ref command like so:

Code: [Select]
120 { dup ref 5 add swap store } loop

(I'm pretty sure that bot memory is saved between frames, but I saw an issue recently that made me question that assumption.  It was something I tested once a long time ago but haven't tested recently.  If it seems like memory is cleared every frame, let me know).
« Last Edit: April 06, 2017, 06:29:48 AM by Numsgil »

Offline Shadowgod2

  • Bot Destroyer
  • ***
  • Posts: 379
    • View Profile
Re: Bot testbed
« Reply #12 on: April 06, 2017, 08:56:01 AM »
Yea seems to be a bug when you start everything to 0 and try to just add 1 to it, it adds the 1 but seems to stop after that which is why i was confused. Thanks

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7703
    • View Profile
Re: Bot testbed
« Reply #13 on: April 06, 2017, 11:35:41 AM »
Bleh, sorry, I guess I need some better testing around the high level stuff.  I'm going on vacation soon, which means I'll either get a lot of programming done or none at all, so I'm not sure what sort of timeline for a fix would look like,

Offline Shadowgod2

  • Bot Destroyer
  • ***
  • Posts: 379
    • View Profile
Re: Bot testbed
« Reply #14 on: April 06, 2017, 12:06:39 PM »
Alright no problem. I'll still play with the bot dna see what i get. I feel like im getting pretty close to getting what i need to know for a basic swimmer or something allong those lines.. crude but workable.