Author Topic: DNA command line interpreter  (Read 17324 times)

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
DNA command line interpreter
« 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:
  • add, sub - basic arithmetic, nothing fancy
  • mult - multiplies two numbers and then uses only the 9 least significant digits.
  • div - A divide by zero returns 0.  Division always truncates the result, which is unusual to most other commands.
  • mod - A divide by zero returns the original number.  Mod always obeys the law a * n + b = r where a is the division result, b is the mod result, n is the divisor, and r is the original number.
  • sqrt - returns the signed sqrt of a number.  That is, -25 sqrt returns -5
  • max, min - returns the maximum or minimum of a pair of numbers
  • swap - swaps the top two values in the stack
  • rand - returns a random number between (val, 0] or [0, val) depending on if val is positive or negative.
  • abs - returns the absolute value of a number
  • sgn - returns the sign of a number as either -1, 0, or 1
  • neg - returns the negative of the top value on the stack.
  • inc, dec - increments or deincrements the memory location pointed to by the top value in the stack.
  • ref - returns the value of the memory location pointed to by the top value of the stack
  • sin - returns the normalized sine of a number.  This is actually a little weird, but basically a full circle is 1080 degrees (1080 is close to 1000, and has many integer denominators), and sin returns values in the range [-1080,1080]  No cosine, since its so easy to convert a sine call to a cosine call using trig identities.
  • atan - A binary operator that basically computes tan(angle) = y/x, or mirrors atan2 in most programming languages.
  • store - operates like one would expect from experience with DarwinbotsII, however values are modded down to the 4 digits that memory stores.
  • dup - Duplicates the top value on the stack.
  • Comparisons - All 6 standard comparisons (> < >= <= = !=) are present.
  • Logic - and, or, xor, not are all present
  • true, false - the constants true and false are recognized
  • stop - turns off DNA execution.  DNA after it is basically ignored.
  • start - starts the DNA executing again, and clears both the bool and integer stack
  • dub, swab - mirrors the functionality of dup and swap, but for the boolean stack (note the p's are replaced with b's for "bool")
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.

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.
« Last Edit: January 09, 2008, 03:09:13 AM by Numsgil »

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
DNA command line interpreter
« Reply #1 on: September 08, 2007, 04:26:51 AM »
The version I had uploaded before was broken.  I've reattached a fixed version.

Offline Jez

  • Bot Overlord
  • ****
  • Posts: 788
    • View Profile
DNA command line interpreter
« Reply #2 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?
If you try and take a cat apart to see how it works, the first thing you have in your hands is a non-working cat.
Douglas Adams

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
DNA command line interpreter
« Reply #3 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.

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4483
    • View Profile
DNA command line interpreter
« Reply #4 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...
« Last Edit: November 30, 2007, 10:43:08 AM by Botsareus »

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
DNA command line interpreter
« Reply #5 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.  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.

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4483
    • View Profile
DNA command line interpreter
« Reply #6 on: October 18, 2007, 02:06:46 PM »
What about MSDN?

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
DNA command line interpreter
« Reply #7 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.

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4483
    • View Profile
DNA command line interpreter
« Reply #8 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?"

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
DNA command line interpreter
« Reply #9 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.

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4483
    • View Profile
DNA command line interpreter
« Reply #10 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?

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
DNA command line interpreter
« Reply #11 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

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4483
    • View Profile
DNA command line interpreter
« Reply #12 on: December 20, 2007, 01:25:02 PM »
Thank you Numsgil.

Offline Prsn828

  • Bot Destroyer
  • ***
  • Posts: 139
    • View Profile
DNA command line interpreter
« Reply #13 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.
So, what will it be? Will you submit to my will, or must I bend reality to suit my needs?
Better answer before I do BOTH!

Offline Moonfisher

  • Bot Overlord
  • ****
  • Posts: 592
    • View Profile
DNA command line interpreter
« Reply #14 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   )