Darwinbots Forum
Code center => Darwinbots3 => Topic started 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:- 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 (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.
-
The version I had uploaded before was broken. I've reattached a fixed version.
-
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?
-
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.
-
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...
-
.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).
-
What about MSDN?
-
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.
-
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?"
-
*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".)
nrg by itself is a number representing the location of energy in the sysvars?
Right.
**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.
-
You can create your own sysvars by using the def metatag.
Can you give me an example?
What about constants like:
7 label ab
ab will always return 7?
-
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
-
Thank you Numsgil.
-
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.
-
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 )
-
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.
-
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.
-
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.
-
I get it. Robots can evolve there own Codules.
-
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!