Darwinbots Forum

Code center => Darwinbots3 => Topic started by: Numsgil on September 07, 2007, 02:39:12 AM

Title: DNA command line interpreter
Post by: Numsgil on September 07, 2007, 02:39:12 AM
I've been working on the DNA module for the last few weeks, and this is the result.  It's a command line interpreter for DNA.  You can type in any DNA commands, and it will calculate them and show you the resulting stack.

Everything in the DNA should appear to work on a base 10 system.  The stack has capacity for 9 digits (though this may increase in  the future if I can find a clever way to multiply two longs without overflowing).  A bots memory has a capacity for 4 digits.  Memory exists between [0, 999].  Values outside this range are absolute valued and then modded into range.

Some commands may behave a little differently than you're used to.  Sqrt for instance.  I'll try to build a detailed in-console help system sometime in the future, but in the mean time, don't be afraid to ask questions.

Codules, chromosomes, and other features aren't coded yet.

I've implemented the in-place condition programming I talked about in another thread.  stores and codule calls (not implemented yet, but it will be) will still pull values from the stack, but nothing will happen if the top value on the bool stack is false.  An empty bool stack is treated as true.

Values will fizzle (not pull values from the stack, and do nothing) if there aren't enough values on the stack.

Things should be pretty robust, but I got a bit sloppy near the end of my work and I still need to go back and do some stronger testing.  Be aggressive in your testing, and question anything that doesn't look right to you.

This is the full command list:In addition, number constants are recognized, as are custom labels (and sysvars in the future, though it's not implemented yet).  Instead of "10 .up store", you can now do "10 up store".  In addition, a new feature called Explicits allows you to combine the location and action for memory (and eventually codule) manipulations.

For instance, "10 up store" can be done as "10 .up".  The period prefix is now associated with storing instead of label lookup.

And something like *.nrg is now done as *nrg (Trying to do *.nrg will result in a syntax error).

For all explicits, labels and number constants are treated the same.

Lastly, I've set up functionality for something I'm calling Metatags.  Metatags are information about the DNA that needs to be processed before the DNA is parsed.  Like preprocessor commands.  So far the only one is def.  You can use it like you're used to to register a custom label.  def labelname 10 would cause labelname to push 10 onto the stack whenever it's encountered, for instance.  I might later add in some inline macroing as well to allow people to construct their own custom commands that work the same as the default ones.

Requirements: You'll need .Net 2.0.  Nothing else is needed.  Download it here (http://www.microsoft.com/downloads/details.aspx?FamilyID=0856EACB-4362-4B0D-8EDD-AAB15C5E04F5&displaylang=en).

Use:
Here's a quick example of using the command line interpreter. Type enter at the end of each line, in the order given, and watch what happens:

10
20
add
def mylabel 100
mylabel
100 .mylabel
*mylabel
mylabel ref
start
50 .mylabel
50 *mylabel add mylabel sub

The program is included as an attachment at the end of the post.
Title: DNA command line interpreter
Post by: Numsgil on September 08, 2007, 04:26:51 AM
The version I had uploaded before was broken.  I've reattached a fixed version.
Title: DNA command line interpreter
Post by: Jez on September 09, 2007, 03:04:29 PM
Haven't got time to play with this atm but it sounds interesting, would I use it for deciphering 'evolved' code or did you have another use in mind?
Title: DNA command line interpreter
Post by: Numsgil on September 09, 2007, 08:24:17 PM
Deciphering evolved code is probably the main use.  Also testing out how the math works when you're writing a bot.  Later on as a way of automatically testing to see that your bot behaves as you expect it should, though it's not really ready for that just yet.

You won't be able to use this on any evolved code from Darwinbots 2.X.  The two languages are just too different.
Title: DNA command line interpreter
Post by: Botsareus on October 04, 2007, 01:42:53 PM
Quote
Requirements: You'll need .Net 2.0. Nothing else is needed. Download it here.
I want to buy .net from the store (since I probably won't have fast Internet) Should I ask for "VisualStudio.net 2.0" and they should have it? Also: do I have to buy MSDN.net separately or it comes with the package?
----
Thank you for your time...
Title: DNA command line interpreter
Post by: Numsgil on October 04, 2007, 06:17:32 PM
.Net is free, it's just a set of run time libraries.

Buying Visual Studio to program in .Net isn't necessary.  They have a free version that is 100% adequate for anything you could possibly need.  Find it here (http://msdn2.microsoft.com/en-us/express/aa975050.aspx).  Each language has its own download.

You can also use XNA with these programs, which lets you program games in .NET for XBOX 360 and PC.  I won't be using XNA for Darwinbots  (although an XBOX version of Darwinbots would be pretty wicked  ).  I'll probably use Tao's bindings for OpenGL, but if you're interested you can follow these instructions to install XNA too:

Install Microsoft Visual C# 2005 Express Edition (including Service Pack 1) using the link below.
Obtain the latest updates for Visual Studio from Microsoft Update.
Download and run the Microsoft XNA Game Studio Express 1.0 Refresh installer.
Follow the instructions displayed during setup.
Launch Microsoft XNA Game Studio Express from the Start Menu.

From this page (http://www.microsoft.com/downloads/details.aspx?FamilyId=12ADCD12-7A7B-4413-A0AF-FF87242A78DE&displaylang=en).
Title: DNA command line interpreter
Post by: Botsareus on October 18, 2007, 02:06:46 PM
What about MSDN?
Title: DNA command line interpreter
Post by: Numsgil on October 18, 2007, 05:42:06 PM
There should be a way to download MSDN during the installation process.  If not then there must be a separate download for it.  It's hard to remember, I haven't played around with it in a long time.
Title: DNA command line interpreter
Post by: Botsareus on November 30, 2007, 10:46:20 AM
How does this work?

*nrg, does it return the val. of energy?

nrg by itself is a number representing the location of energy in the sysvars?

what about:

**50 , does it mean "the data of the memory location of the data of memory location 50?"
Title: DNA command line interpreter
Post by: Numsgil on November 30, 2007, 04:39:51 PM
Quote from: Botsareus
*nrg, does it return the val. of energy?

Yes.  Labels are automatically turned in to numbers, you don't need to add the period '.' in front of them (the period now means "store to this location".)

Quote
nrg by itself is a number representing the location of energy in the sysvars?

Right.

Quote
**50 , does it mean "the data of the memory location of the data of memory location 50?"

Would cause a syntax error.  Explicits (labels with characters in front of them) are simply shortcuts for implicit commands (will be used also as a method of directing evolution-- the location and the store command are grouped together for higher cohesion).

10 .50 is a shortcut for 10 50 store
*50 is a shortcut for 50 ref
and once codules are implemented, @50 will be a shortcut for 50 call

If you wanted to do **50, you'd have to do either *50 ref or 50 ref ref.

You can download the DNA command line interpreter and actually play with this stuff.  And I'd be grateful if you did, as it would help me bug test / "play test" it.  You can create your own sysvars by using the def metatag.
Title: DNA command line interpreter
Post by: Botsareus on December 06, 2007, 02:04:01 PM
Quote
You can create your own sysvars by using the def metatag.

Can you give me an example?

What about constants like:
Quote
7 label ab

ab will always return 7?
Title: DNA command line interpreter
Post by: Numsgil on December 06, 2007, 02:56:19 PM
Here's a quick example of using the command line interpreter.  Type enter at the end of each line, in the order given, and watch what happens:

10
20
add
def mylabel 100
mylabel
100 .mylabel
*mylabel
mylabel ref
start
50 .mylabel
50 *mylabel add mylabel sub
Title: DNA command line interpreter
Post by: Botsareus on December 20, 2007, 01:25:02 PM
Thank you Numsgil.
Title: DNA command line interpreter
Post by: Prsn828 on April 24, 2009, 01:13:07 PM
I just finished a major update on the DNA system.
Sysvars have not been chosen yet, but it can read them once it knows what they are now.
Also, it is more robust, allowing for bad whitespace and mixed cases (StORe = store) now.
Title: DNA command line interpreter
Post by: Moonfisher on April 25, 2009, 07:25:23 AM
Allowing whitespaces sounds like a good idea, not sure I like allowing mixed cases.
I kinda like compilers to be very strict, they shouldn't swallow anything (Unlike a good gf   )
Title: DNA command line interpreter
Post by: Prsn828 on April 25, 2009, 11:34:56 PM
Quote from: Moonfisher
Allowing whitespaces sounds like a good idea, not sure I like allowing mixed cases.
I kinda like compilers to be very strict, they shouldn't swallow anything (Unlike a good gf   )

Hmm, you're more than a little suggestive there

Anyway, if you spell it wrong, or use a symbol that doesn't exist in the system, it won't work, but other than that, it is the same as any other case-insensitive programming language.
Title: Re: DNA command line interpreter
Post by: Botsareus on December 11, 2013, 05:38:36 PM
I know this is a really, really old thread. But:

Numsgil, why do you want as few commands as possible natively?
I think bots can benefit from naturally evolving compound commands... I actually added them to DB2 from an evolution stand point. I didn't really care that it makes life easier for the programmer.
Title: Re: DNA command line interpreter
Post by: Numsgil on December 11, 2013, 06:18:29 PM
Codules would basically let you build your own commands, and the smaller the list of DNA commands the easier it is to test and debug.

For evolved code, the smaller the building blocks for evolution to play with the more impressive the final results are.  Codules, again, let bots build up code reuse so it's entirely possible for things like storeadd to evolve on their own just by happenstance.  Or other, weirder DNA shortcuts.

Or that's the thinking anyway.  I haven't played with it in a long while; I'll revisit it at some point and finish flushing out the language once I have a chance to play with it in practice.
Title: Re: DNA command line interpreter
Post by: Botsareus on December 12, 2013, 05:35:14 AM
I get it. Robots can evolve there own Codules.
Title: Re: DNA command line interpreter
Post by: spike43884 on January 25, 2015, 07:42:48 AM
Oooh. A nice little command to add for DB3:
.mygenefired

This will check if X (X being the value you put before .mygenefired store) was active in the previous cycle, it will return 1 if true, 0 if false!