Darwinbots Forum

Bots and Simulations => DNA - General => The Gene depository => Topic started by: bacillus on April 29, 2008, 08:00:29 PM

Title: OCULUS II
Post by: bacillus on April 29, 2008, 08:00:29 PM
This must be my most elaborate and unreadable code I ever produced. I checked over it twice (a very tedious job!!!) and found no errors, so should work. OCULUS I turned towards the thing it needed to turn least towards to face it; OCULUS II faces towards the closest thing in sight, using the priority system of OCULUS I in case of conflicts.

-4 *.eye1 *.eye9 sub sgn 0 floor mult *.eye1 *.eye8 sub sgn 0 floor mult *.eye1 *.eye7 sub sgn 0    floor mult *.eye1 *.eye6 sub sgn 0 floor mult *.eye1 *.eye5 sub sgn 0 floor mult *.eye1 *.eye4 sub   sgn 0 floor mult *.eye1 *.eye3 sub sgn 0 floor mult *.eye1 *.eye2 sub sgn 0 floor mult 4 *.eye9     *.eye8 sub sgn 0 floor mult *.eye9 *.eye7 sub sgn 0 floor mult *.eye9 *.eye6 sub sgn 0 floor mult
 *.eye9 *.eye5 sub sgn 0 floor mult *.eye9 *.eye4 sub sgn 0 floor mult *.eye9 *.eye3 sub sgn 0 floor  mult *.eye9 *.eye2 sub sgn 0 floor mult *.eye9 *.eye1 sub sgn ++ sgn mult add -3 *.eye2 *.eye9 sub   sgn ++ sgn mult *.eye2 *.eye8 sub sgn 0 floor mult *.eye2 *.eye7 sub sgn 0 floor mult *.eye2 *.eye6  sub sgn 0 floor mult *.eye2 *.eye5 sub sgn 0 floor mult *.eye2 *.eye4 sub sgn 0 floor mult *.eye2    *.eye3 sub sgn 0 floor mult *.eye2 *.eye1 sub sgn ++ sgn mult add 3 *.eye8 *.eye9 sub sgn ++ sgn     mult *.eye8 *.eye7 sub sgn 0 floor mult *.eye8 *.eye6 sub sgn 0 floor mult *.eye8 *.eye5 sub sgn 0   floor mult *.eye8 *.eye4 sub sgn 0 floor mult *.eye8 *.eye3 sub sgn 0 floor mult *.eye8 *.eye2 sub   sgn ++ sgn mult *.eye8 *.eye1 sub sgn ++ sgn mult add -2 *.eye3 *.eye9 sub sgn ++ sgn mult *.eye3    *.eye8 sub sgn ++ sgn mult *.eye3 *.eye7 sub sgn 0 floor mult *.eye3 *.eye6 sub sgn 0 floor mult
 *.eye3 *.eye5 sub sgn 0 floor mult *.eye3 *.eye4 sub sgn 0 floor mult *.eye3 *.eye2 sub sgn ++ sgn   mult *.eye3 *.eye1 sub sgn ++ sgn mult add 2 *.eye7 *.eye9 sub sgn ++ sgn mult *.eye7 *.eye8 sub     sgn ++ sgn mult *.eye7 *.eye7 sub sgn 0 floor mult *.eye7 *.eye6 sub sgn 0 floor mult *.eye7 *.eye5  sub sgn 0 floor mult *.eye7 *.eye4 sub sgn ++ sgn mult *.eye7 *.eye2 sub sgn ++ sgn mult *.eye7     *.eye1 sub sgn ++ sgn mult add -1 *.eye4 *.eye9 sub sgn ++ sgn mult *.eye4 *.eye8 sub sgn ++ sgn     mult *.eye4 *.eye7 sub sgn ++ sgn mult *.eye4 *.eye6 sub sgn 0 floor mult *.eye4 *.eye5 sub sgn 0    floor mult *.eye4 *.eye3 sub sgn ++ sgn mult *.eye4 *.eye2 sub sgn ++ sgn mult *.eye4 *.eye1 sub     sgn ++ sgn mult add 1 *.eye4 *.eye9 sub sgn ++ sgn mult *.eye4 *.eye8 sub sgn ++ sgn mult *.eye4    *.eye7 sub sgn ++ sgn mult *.eye4 *.eye6 sub sgn ++ sgn mult *.eye4 *.eye5 sub sgn 0 floor mult
 *.eye4 *.eye3 sub sgn ++ sgn mult *.eye4 *.eye2 sub sgn ++ sgn mult *.eye4 *.eye1 sub sgn ++ sgn     mult add 0 *.eye5 *.eye9 sub sgn ++ sgn mult *.eye5 *.eye8 sub sgn ++ sgn mult *.eye5 *.eye7 sub     sgn ++ sgn mult *.eye5 *.eye6 sub sgn ++ sgn mult *.eye5 *.eye4 sub sgn ++ sgn mult *.eye5 *.eye3   sub sgn ++ sgn mult *.eye5 *.eye2 sub sgn ++ sgn mult *.eye5 *.eye1 sub sgn ++ sgn mult add .focuseye store
Title: OCULUS II
Post by: Reiyuki on April 30, 2008, 12:36:19 PM
Quote from: bacillus
This must be my most elaborate and unreadable code I ever produced. I checked over it twice (a very tedious job!!!) and found no errors, so should work. OCULUS I turned towards the thing it needed to turn least towards to face it; OCULUS II faces towards the closest thing in sight, using the priority system of OCULUS I in case of conflicts.

-4 *.eye1 *.eye9 sub sgn 0 floor mult *.eye1 *.eye8 sub sgn 0 floor mult *.eye1 *.eye7 sub sgn 0    floor mult *.eye1 *.eye6 sub sgn 0 floor mult *.eye1 *.eye5 sub sgn 0 floor mult *.eye1 *.eye4 sub   sgn 0 floor mult *.eye1 *.eye3 sub sgn 0 floor mult *.eye1 *.eye2 sub sgn 0 floor mult 4 *.eye9     *.eye8 sub sgn 0 floor mult *.eye9 *.eye7 sub sgn 0 floor mult *.eye9 *.eye6 sub sgn 0 floor mult
 *.eye9 *.eye5 sub sgn 0 floor mult *.eye9 *.eye4 sub sgn 0 floor mult *.eye9 *.eye3 sub sgn 0 floor  mult *.eye9 *.eye2 sub sgn 0 floor mult *.eye9 *.eye1 sub sgn ++ sgn mult add -3 *.eye2 *.eye9 sub   sgn ++ sgn mult *.eye2 *.eye8 sub sgn 0 floor mult *.eye2 *.eye7 sub sgn 0 floor mult *.eye2 *.eye6  sub sgn 0 floor mult *.eye2 *.eye5 sub sgn 0 floor mult *.eye2 *.eye4 sub sgn 0 floor mult *.eye2    *.eye3 sub sgn 0 floor mult *.eye2 *.eye1 sub sgn ++ sgn mult add 3 *.eye8 *.eye9 sub sgn ++ sgn     mult *.eye8 *.eye7 sub sgn 0 floor mult *.eye8 *.eye6 sub sgn 0 floor mult *.eye8 *.eye5 sub sgn 0   floor mult *.eye8 *.eye4 sub sgn 0 floor mult *.eye8 *.eye3 sub sgn 0 floor mult *.eye8 *.eye2 sub   sgn ++ sgn mult *.eye8 *.eye1 sub sgn ++ sgn mult add -2 *.eye3 *.eye9 sub sgn ++ sgn mult *.eye3    *.eye8 sub sgn ++ sgn mult *.eye3 *.eye7 sub sgn 0 floor mult *.eye3 *.eye6 sub sgn 0 floor mult
 *.eye3 *.eye5 sub sgn 0 floor mult *.eye3 *.eye4 sub sgn 0 floor mult *.eye3 *.eye2 sub sgn ++ sgn   mult *.eye3 *.eye1 sub sgn ++ sgn mult add 2 *.eye7 *.eye9 sub sgn ++ sgn mult *.eye7 *.eye8 sub     sgn ++ sgn mult *.eye7 *.eye7 sub sgn 0 floor mult *.eye7 *.eye6 sub sgn 0 floor mult *.eye7 *.eye5  sub sgn 0 floor mult *.eye7 *.eye4 sub sgn ++ sgn mult *.eye7 *.eye2 sub sgn ++ sgn mult *.eye7     *.eye1 sub sgn ++ sgn mult add -1 *.eye4 *.eye9 sub sgn ++ sgn mult *.eye4 *.eye8 sub sgn ++ sgn     mult *.eye4 *.eye7 sub sgn ++ sgn mult *.eye4 *.eye6 sub sgn 0 floor mult *.eye4 *.eye5 sub sgn 0    floor mult *.eye4 *.eye3 sub sgn ++ sgn mult *.eye4 *.eye2 sub sgn ++ sgn mult *.eye4 *.eye1 sub     sgn ++ sgn mult add 1 *.eye4 *.eye9 sub sgn ++ sgn mult *.eye4 *.eye8 sub sgn ++ sgn mult *.eye4    *.eye7 sub sgn ++ sgn mult *.eye4 *.eye6 sub sgn ++ sgn mult *.eye4 *.eye5 sub sgn 0 floor mult
 *.eye4 *.eye3 sub sgn ++ sgn mult *.eye4 *.eye2 sub sgn ++ sgn mult *.eye4 *.eye1 sub sgn ++ sgn     mult add 0 *.eye5 *.eye9 sub sgn ++ sgn mult *.eye5 *.eye8 sub sgn ++ sgn mult *.eye5 *.eye7 sub     sgn ++ sgn mult *.eye5 *.eye6 sub sgn ++ sgn mult *.eye5 *.eye4 sub sgn ++ sgn mult *.eye5 *.eye3   sub sgn ++ sgn mult *.eye5 *.eye2 sub sgn ++ sgn mult *.eye5 *.eye1 sub sgn ++ sgn mult add .focuseye store


That is a sweet bit of code there.
I mean look at it, the thing's longer than most bots themselves, and only needs one store command to function.  


How do you think it would handle mutations?
Title: OCULUS II
Post by: EricL on April 30, 2008, 12:52:09 PM
Quote from: Reiyuki
How do you think it would handle mutations?
Poorly, as with most hand authorred code.
Title: OCULUS II
Post by: Moonfisher on April 30, 2008, 01:52:26 PM
Long store comands break easy from mutations... if one value or operator mutates into an or/and for example, or if the store becomes an inc or dec...
Was a big problem for me when trying to make aneural network, had to make each weight consist of many values to get it to evolve without too much trouble.

Also if you like one liner bots, you should take a look at the SS league... for bots with only one store command.
Title: OCULUS II
Post by: bacillus on April 30, 2008, 05:57:06 PM
A one liner bot? I think the only one I've seen is Nano. Then again, it depends on how you define a line...
Title: OCULUS II
Post by: Numsgil on April 30, 2008, 07:03:58 PM
one line meaning a single, self contained store.
Title: OCULUS II
Post by: bacillus on April 30, 2008, 08:08:36 PM
That would be a challenge; could you build a single increment bot?
Title: OCULUS II
Post by: Numsgil on April 30, 2008, 08:35:51 PM
That... may not be strictly possible.  There wouldn't really be a way to feed using shots, at least, since all feeding shots are negative.
Title: OCULUS II
Post by: bacillus on April 30, 2008, 08:45:48 PM
Sure it is.
Just use ties. You can increment... umm....
damn, I think you're right..
Title: OCULUS II
Post by: Moonfisher on April 30, 2008, 09:02:40 PM
There's a lot of new SS bots, which is why the SS league was started...
Still only like 6 bots in there... but it's a funny challenge...
It's not just about converting genes, you can only do one thing at the time.
But you can do a lot with one store per cycle.
Most of the new SS bots are in the starting gate, theres also a lot of good pointers in those topics.

And you CAN make a single inc bot... but you can never push values above 1 into a location though... so I guess you would have to tie and use 1 .sharenrg... but I think you would loose energy that way...
With a single dec you could atleast shoot... but not reproduce...
Title: OCULUS II
Post by: bacillus on April 30, 2008, 09:07:31 PM
I would really like to run the SS league sometime. Me and Commander Keen seem to be taking over all the Leagues. In the meantime, though, I've got 59 rounds of Guardian to work through.
Title: OCULUS II
Post by: gymsum on May 01, 2008, 12:10:42 AM
I thought sgn wasn't supported in DB yet.
Title: OCULUS II
Post by: EricL on May 01, 2008, 12:40:08 AM
Quote from: gymsum
I thought sgn wasn't supported in DB yet.
It's there.  Replaces the top value on the integer stack with either -1 or 1 depending on it's sign.
Title: OCULUS II
Post by: gymsum on May 02, 2008, 12:00:17 AM
Quote from: EricL
Quote from: gymsum
I thought sgn wasn't supported in DB yet.
It's there.  Replaces the top value on the integer stack with either -1 or 1 depending on it's sign.

thought it was sin.. lol
Title: OCULUS II
Post by: bacillus on May 02, 2008, 07:53:19 PM
I guess a sin function would be useful when making a snake-like multibot. Maybe the values could be scaled to between -1000 and 1000?
Title: OCULUS II
Post by: Numsgil on May 02, 2008, 08:27:58 PM
I think that was the plan, Eric's just never gotten around to it.
Title: OCULUS II
Post by: bacillus on May 10, 2008, 02:59:41 AM
Wait...
about the increment thing, could you increment .tieloc until you hit .tieval, then increment that?
No, that's even more stupid. You'll likely lose 100 nrg for each 1 you gain. How about a one inc/one dec bot?
Title: OCULUS II
Post by: gymsum on May 10, 2008, 11:30:52 PM
cant you use (*a -1 mult sgn)? then add that number to it.
Title: OCULUS II
Post by: Numsgil on May 11, 2008, 01:24:00 AM
But if you're limited to just inc or dec, that doesn't really help.  I think it's impossible to create a bot that manages to feed itself (ie: not a veg) and reproduce with just a single inc or dec.  Using two (inc and dec) is probably too easy (not to mention severely limits the sorts of bots you could make).

So I still think a single store bot is the leanest bot possible that still allows a nearly full range of actions.
Title: OCULUS II
Post by: Trafalgar on May 11, 2008, 11:44:23 AM
I was thinking that the many many many SGized comparisons are a bit inefficient in CPU-usage, and thought about alternatives. What I came up with first:
Code: [Select]
highest = -4
highestVal = 0
    
for (num=1; num<9; num++):
    if (eye[num]>highestVal):
        highest = num - 5
        highestVal = eye[num]
focuseye = highest

The first step to implementing that would be unrolling the loop, of course. Next I thought, well, to avoid doing a bunch of stores, we could make highest and highestVal be stack values that we change instead of actual variables. Unfortunately, that is, as far as I can tell, impossible. Actually, I can make them stack variables and do work on them just fine. The problem is that they aren't affected by the boolean stack's top value. They run whether it's true or false.

If highestVal were the topmost stack value and highest was below it, what I had for popping/dropping highestVal and changing highest was:
Code: [Select]
+ dup ^ -4 + *.eye1, with -4 and *.eye1 replaced by other values for other eyes.

I did write a version which uses stores, but it can have up to 19 stores in a cycle if the eyes are all perfectly in order so that eye2 is higher than eye1, eye3 higher than eye2, etc (DNA length 93). Here's a snippet of it with the beginning, two eyes, and the end (Actually, there is no end).
Code: [Select]
*.eyef .highestVal store

*.highestVal *.eye1 <=
-4 .focuseye store
*.eye1 .highestVal store
dropbool *.highestVal *.eye2 <=
-3 .focuseye store
*.eye2 .highestVal store
dropbool

There's one optimization in that - it starts highestVal off with the value in eyef (maybe I could actually modify eyef instead), so that no stores will be made for eyes which see nothing closer than eyef. Effectively, if the focuseye is the best one there will only be one store. If we use eyef instead of highestVal, it would be 0 stores.

OCULUS II's DNA length is 524, but of course it has the huge advantage of *always* only having one store.

Alternately, I've made something else that you might consider an improvement on OCULUS II (Although I wrote this with pybot, and the code came out very similar to OCULUS II, and then I rearranged the eye order so that it came out in the same order too, for ease of comparison). Most of the DNA came out the same, but this has most of the multiplication replaced by &, which should be faster, and it checks to make sure it isn't setting focuseye to what it is already set to. Comparisons with a lower eye to a higher eye use >= instead of >, which makes the DNA a tiny bit larger, but that means eye1 is considered more important than eye2-9, eye2 is more important than 3-9, etc. Oh, and apparently we omitted a condition set for a different eye. You omitted #6, whereas I omitted #5. This has a DNA length of 537.
Code: [Select]
-4 *.eye1 *.eye9 sub 1 add sgn 0 floor *.eye1 *.eye8 sub 1 add sgn 0 floor & *.eye1 *.eye7 sub 1 add sgn 0 floor & *.eye1 *.eye6 sub 1 add sgn 0 floor & *.eye1 *.eye5 sub 1 add sgn 0 floor & *.eye1 *.eye4 sub 1 add sgn 0 floor & *.eye1 *.eye3 sub 1 add sgn 0 floor & *.eye1 *.eye2 sub 1 add sgn 0 floor & mult 4 *.eye9 *.eye8 sub sgn 0 floor *.eye9 *.eye7 sub sgn 0 floor & *.eye9 *.eye6 sub sgn 0 floor & *.eye9 *.eye5 sub sgn 0 floor & *.eye9 *.eye4 sub sgn 0 floor & *.eye9 *.eye3 sub sgn 0 floor & *.eye9 *.eye2 sub sgn 0 floor & *.eye9 *.eye1 sub sgn 0 floor & mult add -3 *.eye2 *.eye9 sub 1 add sgn 0 floor *.eye2 *.eye8 sub 1 add sgn 0 floor & *.eye2 *.eye7 sub 1 add sgn 0 floor & *.eye2 *.eye6 sub 1 add sgn 0 floor & *.eye2 *.eye5 sub 1 add sgn 0 floor & *.eye2 *.eye4 sub 1 add sgn 0 floor & *.eye2 *.eye3 sub 1 add sgn 0 floor & *.eye2 *.eye1 sub sgn 0 floor & mult add 3 *.eye8 *.eye9 sub 1 add sgn 0 floor *.eye8 *.eye7 sub sgn 0 floor & *.eye8 *.eye6 sub sgn 0 floor & *.eye8 *.eye5 sub sgn 0 floor & *.eye8 *.eye4 sub sgn 0 floor & *.eye8 *.eye3 sub sgn 0 floor & *.eye8 *.eye2 sub sgn 0 floor & *.eye8 *.eye1 sub sgn 0 floor & mult add -2 *.eye3 *.eye9 sub 1 add sgn 0 floor *.eye3 *.eye8 sub 1 add sgn 0 floor & *.eye3 *.eye7 sub 1 add sgn 0 floor & *.eye3 *.eye6 sub 1 add sgn 0 floor & *.eye3 *.eye5 sub 1 add sgn 0 floor & *.eye3 *.eye4 sub 1 add sgn 0 floor & *.eye3 *.eye2 sub sgn 0 floor & *.eye3 *.eye1 sub sgn 0 floor & mult add 2 *.eye7 *.eye9 sub 1 add sgn 0 floor *.eye7 *.eye8 sub 1 add sgn 0 floor & *.eye7 *.eye6 sub sgn 0 floor & *.eye7 *.eye5 sub sgn 0 floor & *.eye7 *.eye4 sub sgn 0 floor & *.eye7 *.eye3 sub sgn 0 floor & *.eye7 *.eye2 sub sgn 0 floor & *.eye7 *.eye1 sub sgn 0 floor & mult add -1 *.eye4 *.eye9 sub 1 add sgn 0 floor *.eye4 *.eye8 sub 1 add sgn 0 floor & *.eye4 *.eye7 sub 1 add sgn 0 floor & *.eye4 *.eye6 sub 1 add sgn 0 floor & *.eye4 *.eye5 sub 1 add sgn 0 floor & *.eye4 *.eye3 sub sgn 0 floor & *.eye4 *.eye2 sub sgn 0 floor & *.eye4 *.eye1 sub sgn 0 floor & mult add 1 *.eye6 *.eye9 sub 1 add sgn 0 floor *.eye6 *.eye8 sub 1 add sgn 0 floor & *.eye6 *.eye7 sub 1 add sgn 0 floor & *.eye6 *.eye5 sub sgn 0 floor & *.eye6 *.eye4 sub sgn 0 floor & *.eye6 *.eye3 sub sgn 0 floor & *.eye6 *.eye2 sub sgn 0 floor & *.eye6 *.eye1 sub sgn 0 floor & mult add dup *.focuseye != .focuseye store dropbool
So what happens with yours if there are targets in two eyes with exactly the same distance? (The >=s in this one should prevent that from resulting in more than one eye's addition occurring)
Title: OCULUS II
Post by: Peter on May 11, 2008, 12:10:49 PM
The loop could be a serious problem, I could imagine DB being held in a loop pretty easily.
Title: OCULUS II
Post by: Trafalgar on May 11, 2008, 12:55:31 PM
Quote from: Peter
The loop could be a serious problem, I could imagine DB being held in a loop pretty easily.

I'm not suggesting adding a loop operator. I included it and the [] in the first pseudocode to show the basis for the idea. As I said, you would unroll the loop (and convert the eye[num] into eye1, eye2, etc), and you can see what that looks like (with 2 eyes instead of all 9) in the third code block in that post.
Title: OCULUS II
Post by: bacillus on May 14, 2008, 02:27:40 AM
Quote from: Trafalgar
So what happens with yours if there are targets in two eyes with exactly the same distance? (The >=s in this one should prevent that from resulting in more than one eye's addition occurring)
Ah, that's why I use the >= comparator (which I already was using, by the way). So if two eyes have conflicting data, they are chosen according to the priority list, Eye5 being the first choice:
Eye5
Eye6
Eye4
Eye7
Eye3
Eye8
Eye2
Eye9
Eye1